Highlight word under cursor in gvim

How to highlight word under cursor in vim. I currently do this by calling the word under the cursor and then clicking *

. Of course, this underlines the text, but the cursor moves to the next found word in the file (if the word exists more than once). But I want the cursor to stay on the same word while highlighting it.

+3


source to share


3 answers


I have added this feature, it allows you to allocate a maximum of 6 words in different colors, pressing <leader> 1-6

, <leader> -0

clear all the selection.

https://github.com/sk1418/myConf/blob/master/common/.vimrc#L729



the original idea was from sjl.

+1


source


You can try flagging the plugin as it allows you to highlight multiple words with different colors at the same time. It is very stable, well documented and easy to use.



You can select a word to highlight directly or through regular expressions, and the plugin offers some mechanism to navigate between occurrences of the tagged word / expression.

+2


source


Assuming you have hlsearch

on - which gave you the command description *, I'm sure you will - you can create a mapping that sets the search case:

nnoremap <leader>* :<C-u>let @/ = expand('<cword>')<cr> 

      

After using your match, you can navigate to the next / previous result with n/ njust like any other search.

Edit:

Since you asked me to describe what the mapping does, I'll break it down.

  • nnoremap

    talks about creating a non-recursive display.
  • <leader>*

    - key sequence to display. The default <leader>

    is there \, so the actual display is \followed *. You can change this however you want, I just used it as an example.
  • :<C-u>

    probably not useful in this case, but I found it to be a good habit. What it does is to ensure that no range has been added to the command you are about to run.
  • let @/ =

    sets the register /

    (search). This is where the last search string is stored in a normal search. We manipulate this with our mapping to take advantage of the built-in functions hlsearch

    and n/ n.
  • expand('<cword>')

    captures the word under the cursor.
  • <cr>

    just simulates a click Enterto end the command.
+2


source







All Articles