Vim logo vim online Vim Book Ad

basic Tip #235: Toggle highlight word under cursor, to find cursor.

 tip karma   Rating 15/11, Viewed by 1038 

created:   April 11, 2002 7:27      complexity:   basic
author:   HughSasse      as of Vim:   6.0

When the screen has scrolled such as during a search, it may be difficult to find the cursor.  :help %# explains the pattern one can use to highlight the word around the cursor, which gives a bigger target to look for on the screen.  I have this in my .vimrc:

function VIMRCWhere()
    if !exists("s:highlightcursor")
        match Todo /\k*\%#\k*/
        let s:highlightcursor=1
    else
        match None
        unlet s:highlightcursor
    endif
endfunction
map <C-K> :call VIMRCWhere()<CR>

This means that in "normal" mode ctrl-k will toggle the highlight.  Todo is a hightlight group whch is particularly easy to see.
For further information see ":help s:", ":help match",  ":help exists()"  and ":help funtion".

 rate this tip  Life Changing Helpful Unfulfilling 

<<Vi(M) Command Line tips & tricks | Menu for inserting special characters >>

Additional Notes

[email protected], April 12, 2002 20:44
Good trick.  Another way to find the cursor is to hit zz, which moves the current line to the center of the screen.
[email protected], April 12, 2002 23:43
I found that often the highlighting didn't help, because the cursor was either not on a word or on a single-letter word.  Therefore, I chaged the function to make it highlight the entire line.  To do this, change the appropriate line in the function to "match Todo /^.*\%#.*$/".
[email protected], April 12, 2002 23:43
I found that often the highlighting didn't help, because the cursor was either not on a word or on a single-letter word.  Therefore, I changed the function to make it highlight the entire line.  To do this, change the appropriate line in the function to "match Todo /^.*\%#.*$/".
Anonymous, April 13, 2002 2:15
jk

Do this quickly, you'll see the cursor because it's moving.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo