如何将 Vim 高亮线更改为不是下划线?

在一些配色方案中,当前线突出显示改变背景,而在其他配色方案中,如沙漠,当前线突出显示下划线。

我想改变当前线高亮在沙漠使用不同的背景颜色,而不是下划线。我该怎么做?

我的 .vimrc:

set cursorline
highlight Cursorline cterm=bold

更新: 解决这个问题的 .vimrc

colorscheme desert
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40
93124 次浏览
color desert
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40

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

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

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

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.

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

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