Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Vim cursorline colors?

Tags:

vim

I have tried to look at other answers here on SO and Google but none of them seem to be changing my cursor settings. I am wanting to have a background of yellow with foreground of white bold but can't get it with the settings that I have seen around the web. I am using MacVim mvim in iTerm2.

Thank you for any help.

enter image description here

like image 427
pertrai1 Avatar asked Mar 20 '15 13:03

pertrai1


People also ask

How to set cursorline in Vim?

Simply putting :set cursorline in your vimrc will highlight the current line in every window and update the highlight as the cursor moves. With the default backslash leader key, typing \c will toggle highlighting on and off. That makes it easy to locate the cursor after scrolling in a large file.

How do I change the background color in vim?

The ctermfg=white is used to set the foreground color to white in a terminal text editor. Finally, the ctermbg=black is used to set the background color to black in a terminal text editor.

How to highlight lines in Vim?

If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor. Finally, you can select text in columns by pressing ctrl+v and moving up or down the block.


2 Answers

Most likely you are interested in these three highlighting groups: Cursor, CursorColumn and CursorLine. The names are self explanatory.

For example to change just the cursor color:

:highlight Cursor ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold

To do the same for column cursor:

:highlight CursorColumn ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold

If you also need to highlight the current line, use CursorLine.

like image 157
svlasov Avatar answered Nov 09 '22 03:11

svlasov


If you wants to keep it enable always put the below things in your .vimrc or .gvimrc file

for cursorline

set cursorline
autocmd InsertEnter * highlight CursorLine guibg=#000050 guifg=fg
autocmd InsertLeave * highlight CursorLine guibg=#004000 guifg=fg

for cursor column

set cursorcolumn
autocmd InsertEnter * highlight CursorColumn ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold
autocmd InsertLeave * highlight CursorColumn ctermfg=Black ctermbg=Yellow cterm=bold guifg=Black guibg=yellow gui=NONE

You can change the colors in your wish

like image 38
imbichie Avatar answered Nov 09 '22 02:11

imbichie