Idea: highlight part of a file
Would it be possible to fade parts of a buffer? When studying other people's code or for other reasons, I'd like to fade parts of a buffer (more precisely, highlight only between two given lines).
FYI there are a few plugins that support similar functionality to what you are looking for:
- limelight.vim - Iconic vim plugin from FZF author. Works well and this plugin takes a lot of inspiration from limelight already. Caveat: doesn't support dimmed syntax highlighting.
- twilight.nvim - Seems like a good alternative to limelight.vim; the main difference is that it bases highlights off of treesitter. Same issue and doesn't support dimmed syntax highlighting.
- focushere.nvim - Highlight visual selection, dim everything else. Same issue and doesn't support dimmed syntax highlighting.
I think focushere.nvim in particular is the closest match to the feature that you are requesting
I'm open to adding this into vimade as well, but will need to consider the approach for a bit. I also want to see if I can just add the feature into one of these existing plugins.
Just wanted to update this thread since I intentionally left the previous comment ambiguous as I wasn't sure if I could implement this with real syntax highlighting in Neovim (tldr - it works)
I also wanted to first take a look and see if this could have been added into the existing plugins as I would have preferred to keep the logic separate. Unfortunately, it would have meant rewriting the plugins and basically re-implementing Vimade.
I've been able to create a POC that proves out that this can be supported on Neovim, which was going to be the major hurdle (most of the logic I need for Vim is already built out). I'm going to release this for Neovim as version 2.5 for this plugin and Vim will be 3.0.0 when complete.
There are a few features I need to wrap up with the approach, I think it will likely be ready this week
This now exists, but undocumented for Neovim. Combined the features of the above-mentioned plugins but with actual highlighting and also added VimadeMark so that you can select ranges in windows to keep un-faded. Only works on Neovim 0.10+ currently (I can maybe support 0.9.0 for this feature with some additional work)
Changes include the following:
-
New mode:
ncmode = 'focus'. It can be used as part of the normal setup opts:vimade.setup({ncmode='focus'}). If you enable this mode, Vimade won't do anything until you use the command:VimadeFocus, indicating that you want to highlight around the cursor -
New command:
:VimadeMark. VimadeMark also has sub-commands for easier removing of marksremove-win,remove-buf,remove-tab,remove-all. VimadeMark by itself is treated as a toggle command, meaning it will remove a mark under the cursor if it finds one. If not, it will add a mark.VimadeMarkprevents the selected range from fading across windows. You can further customize the highlighting via:hi VimadeMark -
New command:
:VimadeFocus. This command can be configured to highlight using a number of providers. I've created providers fortreesitter(similar to twilight),blanks(similar to limelight),static(always highlight N lines),hlchunks(reads the scope from hlchunks plugin),mini-indentscope(scope from mini), andsnacks(scope from snacks).You can configure VimadeFocus like the following:
vimade.setup({
focus = {
providers = {
filetypes = {
default = {
-- If you use mini.indentscope, snacks.indent, or hlchunk, you can also highlight the indent scope!
-- {'snacks', {}},
-- {'mini', {}},
-- {'hlchunk', {}},
{'treesitter', {
min_node_size = 2,
min_size = 1,
max_size = 0,
-- exclude types either too large and/or mundane
exclude = {
'script_file',
'stream',
'document',
'source_file',
'translation_unit',
'chunk',
'module',
'stylesheet',
'statement_block',
'block',
'pair',
'program',
'switch_case',
'catch_clause',
'finally_clause',
'property_signature',
'dictionary',
'assignment',
'expression_statement',
'compound_statement',
}
}},
-- if treesitter fails or there isn't a good match, fallback to blanks (similar to limelight)
{'blanks', {
min_size = 1,
max_size = '35%'
}},
-- if blanks fails to find a good match, fallback to static 35%
{'static', {
size = '35%'
}},
},
-- You can make custom configurations for any filetype. Here are some examples.
-- markdown = {{'blanks', {min_size=0, max_size='50%'}}, {'static', {max_size='50%'}}},
-- javascript = {
-- -- only use treesitter (no fallbacks)
-- {'treesitter', { min_node_size = 2, include = {'if_statement', ...}}},
-- },
-- typescript = {
-- {'treesitter', { min_node_size = 2, exclude = {'if_statement'}}},
-- {'static', {size = '35%'}}
-- },
-- java = {
-- -- mini with a fallback to blanks
-- {'mini', {min_size = 1, max_size = 20}},
-- {'blanks', {min_size = 1, max_size = '100%' }},
-- },
},
}
}
})
Attaching a preview using the new Paradox recipe combined with Ayu theme
https://github.com/user-attachments/assets/1a3645e2-c348-40ae-9a0c-1312b13b063f
(Not sure why but github breaks the first 10 seconds of the video, but this one is good enough)