Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: highlight part of a file #75

Open
galou opened this issue Jun 11, 2024 · 4 comments
Open

Idea: highlight part of a file #75

galou opened this issue Jun 11, 2024 · 4 comments
Assignees
Milestone

Comments

@galou
Copy link

galou commented Jun 11, 2024

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).

@TaDaa
Copy link
Owner

TaDaa commented Dec 7, 2024

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.

@TaDaa TaDaa added this to the 3.0.0 milestone Jan 4, 2025
@TaDaa TaDaa self-assigned this Jan 4, 2025
@TaDaa
Copy link
Owner

TaDaa commented Jan 4, 2025

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

TaDaa added a commit that referenced this issue Jan 20, 2025
…nds, VimadeMark commands. VimadeFocus is basically limelight with syntax highlighting. Created scope providers for VimadeFocus including treesitter (similar to twilight), blanks (similar to limelight), static (rolling static size), snacks.nvim, mini-indent, hlchunk.nvim. Scope providers can be configured based on filetype and can be used in any combination. Add VimadeMark, which allows you to select an area and prevent it from being faded.
@TaDaa
Copy link
Owner

TaDaa commented Jan 20, 2025

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 marks remove-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. VimadeMark prevents 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 for treesitter (similar to twilight), blanks (similar to limelight), static (always highlight N lines), hlchunks (reads the scope from hlchunks plugin), mini-indentscope (scope from mini), and snacks (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%' }}, 
      -- },
    },
  }
  }
})

@TaDaa
Copy link
Owner

TaDaa commented Jan 20, 2025

Attaching a preview using the new Paradox recipe combined with Ayu theme

reuploadc.mp4

(Not sure why but github breaks the first 10 seconds of the video, but this one is good enough)

TaDaa added a commit that referenced this issue Jan 20, 2025
TaDaa added a commit that referenced this issue Jan 24, 2025
…een focus and global states, improves terminal highlighting when in focus mode, add cmdline completion highlights to blocklist so that they are readable in focus mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants