vim 中高亮显示当前行号

发布于 2024-12-17 17:01:01 字数 100 浏览 5 评论 0原文

有没有办法在 vim 中突出显示当前行号(在左栏),而不突出显示当前行的背景?理想情况下,我希望将当前行号设为粗体

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

ㄖ落Θ余辉 2024-12-24 17:01:01

有两组确定 &cursorline 选项处于活动状态时显示的行的突出显示:CursorLineCursorLineNR。第一个用于突出显示整行,第二个用于突出显示行号。因此,要实现您想要的效果,您必须

  1. 清除CursorLine的突出显示:只需hiclear CursorLine 在任何:colorscheme之后并且设置背景=调用

    嗨清除 CursorLine
    augroup CLClear
        自动命令! ColorScheme * 高清晰 CursorLine
    澳大利亚集团END
    
  2. 如果您的颜色方案中未设置 CursorLineNR,请设置它的突出显示:

    hi CursorLineNR cterm=bold
    augroup CLNRSet
        自动命令! ColorScheme * hi CursorLineNR cterm=粗体
    澳大利亚集团END
    

    (最好检查它是否已经在颜色方案中设置,也许在这种情况下看起来会更好)。

当然,您可以将这两个自动命令加入其中。

CursorLineNR 是最近在 7.3.488 版本中添加的。

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.

酷遇一生 2024-12-24 17:01:01

你想看看

:se cursorline

,也许甚至/也

:se cursorcolumn

You want to look at

:se cursorline

and perhaps even/also

:se cursorcolumn
三人与歌 2024-12-24 17:01:01

这对我有用:

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

设置配色方案后,我只是在 .vimrc 中使用它。当然,您也可以设置特定的背景颜色,但将它们全部设置为“无”只会突出显示行号(即使其更亮)。

我想你可以只使用 :hi CursorLine cterm=NONE 但我只是想确保一切都透明(包括 gvim)。

通过 CursorLineNR,我可以设置突出显示数字的前景色和背景色。

我写这篇文章只是因为对我来说它无需任何自动命令即可工作,并且可能是大多数人所需要的。

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.

醉生梦死 2024-12-24 17:01:01

您可以设置光标线以仅突出显示数字

'cursorlineopt' 'culopt' 字符串(默认值:“number,line”)                        
                        本地到窗口                                         
                        {在没有 + 语法的情况下编译时不可用        
                        特征}                                                
        关于如何显示“光标线”的设置的逗号分隔列表。     
        有效值:                                                           
        “line” 突出显示光标的文本行              
                        CursorLine hl-CursorLine。                               
        “screenline” 仅突出显示光标的屏幕线       
                        CursorLine hl-CursorLine。                               
        “number” 突出显示光标的行号            
                        CursorLineNr hl-CursorLineNr。             

并覆盖你的颜色方案 使用 autocmd

所以,以下工作:

set cursorline
set cursorlineopt=number
autocmd ColorScheme * highlight CursorLineNr cterm=bold term=bold gui=bold

You can set cursorline to highlight only the numbers

'cursorlineopt' 'culopt' string (default: "number,line")                        
                        local to window                                         
                        {not available when compiled without the +syntax        
                        feature}                                                
        Comma separated list of settings for how 'cursorline' is displayed.     
        Valid values:                                                           
        "line"          Highlight the text line of the cursor with              
                        CursorLine hl-CursorLine.                               
        "screenline"    Highlight only the screen line of the cursor with       
                        CursorLine hl-CursorLine.                               
        "number"        Highlight the line number of the cursor with            
                        CursorLineNr hl-CursorLineNr.             

And to override your colorscheme use autocmd

So, the following works:

set cursorline
set cursorlineopt=number
autocmd ColorScheme * highlight CursorLineNr cterm=bold term=bold gui=bold
朦胧时间 2024-12-24 17:01:01

这对我来说可以突出显示行号而不是行的其余部分:

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

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

沧桑㈠ 2024-12-24 17:01:01

highlight-groups 的帮助没有提到专有的“当前的数量” line”语法组,因此官方答案可能是

您可能需要查看 cursorline 选项,该选项突出显示整行,如果有帮助的话。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文