RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.16k stars 47 forks source link

Toggle buffer only #44

Closed juanMarinero closed 4 years ago

juanMarinero commented 4 years ago

How can I apply IlluminationToggle just in current buffer? Please. From the doc - COMMANDS section, I tried in vain to map either globally OR buffer-range:

nnoremap <buffer> <leader>aht  <Esc>:IlluminationToggle<CR>
nnoremap          <leader>ahtg <Esc>:IlluminationToggle<CR>

Since the toggle function is (source)

fun! illuminate#toggle_illumination() abort
  if !s:enabled
    call illuminate#enable_illumination()
  else
    call illuminate#disable_illumination()
  endif
endf

...I tried to build my own mini function, but these also affect all buffers:

nnoremap <buffer> <leader>asd1 <Esc>:call illuminate#disable_illumination()<CR>
nnoremap <buffer> <leader>asd2 <Esc>:call illuminate#enable_illumination()<CR>

Thanks in advance!

RRethy commented 4 years ago

You can enable and disable at a buffer level using a bang, for example

IlluminateDisable!
IlluminateEnable!
IlluminateToggle!

Without the bang will apply globally (however, any previously used bang calls will override all future global invocations).

I'm going to leave this undocumented for a bit so it can be tested.

juanMarinero commented 4 years ago

Thanks @RRethy !! It works.

Might someone just copy-paste:

nnoremap <buffer> <leader>aht <Esc>:IlluminationToggle!<CR>:echo "---- Auto highlight wordUnderCursor toogled BUFFER (add g to map global)----"<CR>
nnoremap          <leader>ahtg <Esc>:IlluminationToggle<CR>:echo "---- Auto highlight wordUnderCursor toogled GLOBALLY (all buffers) ----"<CR>
RRethy commented 4 years ago

In the mapping you don't need <buffer> since that just means "make this mapping only for this buffer", it doesn't modify the functionality of the executed command.