How do I change my Vim highlight line to not be an underline?

Vim

Vim Problem Overview


In some colorschemes the current line highlighting changes background, in others, like Desert, the current line is underlined.

I want to change the current line highlighting in Desert to use a different background color instead of underlining. How can I do that?

My .vimrc:

set cursorline
highlight Cursorline cterm=bold

Update: .vimrc that solves the issue

colorscheme desert
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40

Vim Solutions


Solution 1 - Vim

color desert
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40

desert is your colorscheme.(should come first)
put it in your ~/.vimrc

Solution 2 - Vim

This works better (in every terminal) for me.

:hi CursorLine   cterm=NONE ctermbg=darkred ctermfg=white

It is setting of color for terminal: background color - ctermbg, and text color - ctermfg. For using in graphical window, add parameters guibg=darkred guifg=white

You can highlight the corresponding column as well, using the command:

:set cursorcolumn

It is useful to toggle highlighting on and off by pressing one key in the editor. Add these line to your vimrc:

:nnoremap H :set cursorline! cursorcolumn!<CR>

typing 'H' will toggle highlighting on and off (Map it to another key if you want)

You can find more info in the article: http://vim.wikia.com/wiki/Highlight_current_line

Solution 3 - Vim

for a style similar to the one you get in gvim in the terminal, preserving the syntax highlight:

" first thing is entering vim mode, not plain vi
set nocompatible
" force 256 colors on the terminal
set t_Co=256
" load the color scheme before anything
colorscheme darkblue " or desert... or anything
" the syntax cmd is when the colorscheme gets parsed, i think..
syntax on
" might not be on by default, this enable the cursor line feature
set cursorline

" set the prefered colours, pick one line here only.
" dark grey, better you can get if you don't support 256 colours
hi CursorLine   cterm=NONE ctermbg=8 ctermfg=NONE
" light grey, no 256 colors
hi CursorLine   cterm=NONE ctermbg=7 ctermfg=NONE
" dark redish
hi CursorLine   cterm=NONE ctermbg=52 ctermfg=NONE
" dark bluish
hi CursorLine   cterm=NONE ctermbg=17 ctermfg=NONE
" very light grey
hi CursorLine   cterm=NONE ctermbg=254 ctermfg=NONE
" yelowish
hi CursorLine   cterm=NONE ctermbg=229 ctermfg=NONE
" almost black
hi CursorLine   cterm=NONE ctermbg=234 ctermfg=NONE

Solution 4 - Vim

If you want to turn the underline on use either one of:

:hi CursorLine cterm=underline
:hi CursorLine gui=underline

Otherwise use one of those:

:hi CursorLine cterm=none
:hi CursorLine gui=none

Solution 5 - Vim

I had a similar problem setting cursorline highlight, but mine was due to the mksession command that I was using to save the session information during vim exit. This session is then automatically restored during program startup, if it's run without any file arguments.

If anyone has .vimrc setup like this, you can add the following to .vimrc to set cursorline highlight correctly:-

function s:SetCursorLine()
    set cursorline
    hi cursorline cterm=none ctermbg=darkblue ctermfg=white
endfunction
autocmd VimEnter * call s:SetCursorLine()

A bit of explanation as to why this works. Along with various buffer and window information, mksession saves the current colorscheme name. This is restored during program startup through session restoration. However, since the session restoration is typically done after .vimrc has been run (typically using a function invoked through 'autocmd VimEnter *'), the cursorline highlight setting in .vimrc is reset by the default for the restored colorscheme.

The above function, invoked through the autocmd, will be run after all the initialization is complete and therefore successfully sets the cursorline highlight.

HTH.

Solution 6 - Vim

You must add .vimrc end line:
highlight lineNr term=bold cterm=NONE ctermbg=none  ctermfg=none gui=bold

set cursorline

highlight CursorLine term=bold cterm=NONE ctermbg=none  ctermfg=none gui=bold

highlight CursorLineNr term=bold cterm=none ctermbg=none ctermfg=yellow gui=bold

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionashimView Question on Stackoverflow
Solution 1 - VimkevView Answer on Stackoverflow
Solution 2 - VimsrnkaView Answer on Stackoverflow
Solution 3 - VimgcbView Answer on Stackoverflow
Solution 4 - Vimuser5920118View Answer on Stackoverflow
Solution 5 - VimHari MahadevanView Answer on Stackoverflow
Solution 6 - VimcsxView Answer on Stackoverflow