Highlight current line
From Vim Tips Wiki
Tip 769 Previous Next created August 14, 2004 · complexity intermediate · version 7.0
Contents |
[edit] Highlighting that stays after cursor moves
To highlight the current line, and have the highlighting stay where it is while you move the cursor, use this mapping:
:nnoremap <silent> <Leader>k mk:exe 'match Search /<Bslash>%'.line(".").'l/'<CR>
This mapping also sets mark k, so that you can simply press 'k to return to the highlighted line. Use :match to clear the highlighting once you're done.
[edit] Highlighting that moves with the cursor
Simply putting :set cursorline in your vimrc will highlight the current line in every window and update the highlight as the cursor moves. You can customize the color using the CursorLine highlight group.
If you only want the highlight applied in the current window, use an autocmd instead:
autocmd WinEnter * setlocal cursorline autocmd WinLeave * setlocal nocursorline
To achieve this result on older Vim versions, you could combine the idea in the first method with a CursorHold or a CursorMoved autocmd.
If you only want highlighting in insert mode (but don't mind that it appears in all windows) use InsertEnter and InsertLeave instead of WinEnter and WinLeave above.
Note that the 'cursorline' option can cause Vim to respond slowly, especially for large files or files with long lines.
