Vim Tips Wiki
Advertisement
Tip 235 Printable Monobook Previous Next

created April 11, 2002 · complexity basic · author HughSasse · version 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 highlight group which is particularly easy to see.

References

Comments

Good trick. Another way to find the cursor is to hit zz, which moves the current line to the center of the screen.


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 /^.*\%#.*$/".


Do this quickly, you'll see the cursor because it's moving.


As well as hitting zz, you can ":set scrolloff=999" (or so=999) to leave it permanently in the centre.

Takes a bit of getting used to, but you never lose the cursor and you don't have to spend as much time scrolling because you're always editing in the middlle of the action.


<Space> followed by <Backspace> moves the cursor in both Command and Insert modes, without altering the buffer.


Advertisement