Tech and travel

Highlight the current line in Vim

2007-08-15

To highlight the current line in Vim, you have to set the cursorline setting.

:set cursorline
:set cul

These two are the same. This can also be set in your _vimrc file, you don’t need the colon then.

Here’s an extract from my vimrc file:

set cursorline
set nowrap
set ic                       " Ignore case
set ai                       " autoindent
set tabstop=4
set shiftwidth=4
set expandtab
set cul                      " Cursor highlight

map <f1> ^hhxxj0
map <f2> ^i  <esc>j0

The last 2 entries add mappings for F1 and F2, to dedent and indent the current line. Map is one of the most useful Vim commands, well worth learning.

Copyright (c) 2024 Michel Hollands