How to highlight the current line and the cursor in .vimrc

vimvimrc

I am trying to highlight the current line as well as the cursor position in Vim. Here's my .vimrc:

set cursorline
hi CursorLine ctermbg=8 ctermfg=15 "8 = dark gray, 15 = white
hi Cursor ctermbg=15 ctermfg=8

The problem I'm experiencing is that the current line background color covers up the cursor background color, so it looks like this:

The current line is highlighted but the cursor is not.

I can obviously tell where the cursor is because the foreground color is almost black, but when the cursor is on a space or at the beginning/end of a line I have no clue where it is unless I move it.

The cursor is at the end of the line, though you'd never know it.

What am I doing wrong here?

Best Answer

You have to change the color of your cursor line to a color other than the color of your cursor. If you're in a terminal emulator like st or rxvt, Vim cannot change the color of your cursor; it will always be the color your terminal application decides to make it. Only the graphical version of Vim is able to change the color of your cursor.

You can change your cursor color through your terminal configuration though.

Some ~/.Xdefaults / ~/.Xresources examples:

XTerm*cursorColor: #FFFFFF
URxvt.cursorColor: white

You could also use the Vim command :set cursorcolumn to put your cursor in crosshairs.

Related Question