Posted by Dariusz Dwornikowski on Wed 30 January 2013

Toggle cursorline and cursorcolumn function in VIM

It is often very comfortable to see where your cursor in VIM is. To achieve that you can use cursorcolumn and cursorline to highlight the row and the column in which you are currently present with your cursor. Below is a function that can be placed in your .vimrc to toggle such a behaviour. It is then mapped to <leader>cl, which effectively means that you need to punch \cl to make it work.

set cursorline
set cursorcolumn

fu! ToggleCurline ()
  if &cursorline && &cursorcolumn
    set nocursorline
    set nocursorcolumn
  else
    set cursorline
    set cursorcolumn
  endif
endfunction

map <silent><leader>cl :call ToggleCurline()<CR>

© 2012-2014 Dariusz Dwornikowski. Built using Pelican. Based on theme by Carey Metcalfe, available on GitHub, which is based on svbhack by Giulio Fidente, modified by Vincent Cheng.