Highlighting the current line number in vim

送分小仙女□ 提交于 2019-12-03 04:13:54

问题


Is there a way to highlight only the current line number (in the left hand coloumn) in vim, without highlighting the background of the current line? Ideally, I would Like to make the current line number bold.


回答1:


There are two groups that determine highlighting of line displayed when &cursorline option is active: CursorLine and CursorLineNR. First is used to highlight the whole line, second for the line number. So to achieve what you want you must

  1. Clear the highlighting of CursorLine: just hi clear CursorLine after any :colorscheme and set background= call.

    hi clear CursorLine
    augroup CLClear
        autocmd! ColorScheme * hi clear CursorLine
    augroup END
    
  2. Set the highlighting of CursorLineNR if it is not set in your colorscheme:

    hi CursorLineNR cterm=bold
    augroup CLNRSet
        autocmd! ColorScheme * hi CursorLineNR cterm=bold
    augroup END
    

    (better to check whether it is already set in the colorscheme, maybe it will look better in that case).

You can join both autocommands in one of course.

CursorLineNR has been added relatively recently around version 7.3.488.




回答2:


You want to look at

:se cursorline

and perhaps even/also

:se cursorcolumn



回答3:


This is what worked for me:

highlight CursorLine cterm=NONE ctermbg=NONE ctermfg=NONE guibg=NONE guifg=NONE
set cursorline

I'm just using this in my .vimrc after having set the color scheme. Of course you could also set a specific background color but setting all of them to NONE just highlights the line number (i.e. makes it brighter).

I guess you could just use :hi CursorLine cterm=NONE but I just wanted to make sure I'm making everything transparent (gvim included).

With CursorLineNR I was then able to set the foreground and background colors of the highlighted number.

I'm only writing this because for me it worked without any autocommands and it may be what most people require.




回答4:


This worked for me to highlight the line number and not the rest of the line:

highlight CursorLineNr cterm=NONE ctermbg=15 ctermfg=8 gui=NONE guibg=#ffffff guifg=#d70000




回答5:


The help for highlight-groups does not mention an exclusive "number of current line" syntax group, so the official answer might be no.

You may want to take a look in the cursorline option which highlights the entire line, if it helps.



来源:https://stackoverflow.com/questions/8247243/highlighting-the-current-line-number-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!