Wednesday, 17 July 2019

vim - Is it possible to not trigger my normal search highlighting when using search as a movement?


When I do a search in vim, I like to have my results highlighted and super-visible, so I give them a bright yellow background and a black foreground in my .vimrc.


" When highlighting search terms, make sure text is contrasting colors
:highlight Search guibg=yellow guifg=black

(This is for GUI versions of vim, like MacVim or Gvim; for command-line, you'd use ctermbg and ctermfg.)


But I sometimes use search with a command, as in c/foo - "change from the cursor to the next occurrence of foo."


In that case, I don't want all the occurrences of foo to be highlighted.


Can I turn off highlighting only in cases where search is used as a movement for a command?



Answer



These naive mappings seem to help.




  • normal search


    Turn highlighting on before doing the search:


    nnoremap / :set hls/


  • motion search


    Turn highlighting off before doing the search:


    nnoremap v/ :set nohlsv/
    nnoremap d/ :set nohlsd/
    nnoremap y/ :set nohlsy/
    nnoremap c/ :set nohlsc/


Note that you'd need to setup similar mapping for ?.


No comments:

Post a Comment

How can I VLOOKUP in multiple Excel documents?

I am trying to VLOOKUP reference data with around 400 seperate Excel files. Is it possible to do this in a quick way rather than doing it m...