Vim 插入模式下光标线颜色变化
有一个用于更改光标颜色的好片段:
if &term =~ "xterm\\|rxvt"
" use an orange cursor in insert mode
let &t_SI = "\<Esc>]12;orange\x7"
" use a red cursor otherwise
let &t_EI = "\<Esc>]12;red\x7"
silent !echo -ne "\033]12;red\007"
" reset cursor when vim exits
autocmd VimLeave * silent !echo -ne "\033]112\007"
" use \003]12;gray\007 for gnome-terminal
endif
我应该如何更改它,而不是光标,CursorLine 会更改颜色,例如从深蓝色更改为蓝色?
我的完整配置是 https://bitbucket.org/JackLeo/home-configs/src/5b8faf340f87/。 vimrc
There is good snippet for changing cursor color:
if &term =~ "xterm\\|rxvt"
" use an orange cursor in insert mode
let &t_SI = "\<Esc>]12;orange\x7"
" use a red cursor otherwise
let &t_EI = "\<Esc>]12;red\x7"
silent !echo -ne "\033]12;red\007"
" reset cursor when vim exits
autocmd VimLeave * silent !echo -ne "\033]112\007"
" use \003]12;gray\007 for gnome-terminal
endif
How should I alter this that instead of cursor, CursorLine would change color for example from dark blue to blue?
My complete config is https://bitbucket.org/JackLeo/home-configs/src/5b8faf340f87/.vimrc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您是否研究过“突出显示”命令,这是控制此操作的更简单方法。
例如,要更改 CursorLine,
请参考: :helphighlight
使其在模式之间切换。
我也许可以将 termcap 颜色与 autocmd 混合使用,但在我看来,突出显示更容易长期维护(如果偶尔使用 gVim)
Have you look in into the 'highlight' command which is a easier way to control this.
For example, to change the CursorLine,
Reference: :help highlight
To make it switch between mode.
I may be possible to mix termcap color with autocmd, but IMO, highlight is more easy to maintain in long term (and in case if use gVim occassionally)
这非常简单,将以下内容放入
.vimrc
< /a> 或自定义 colorscheme 文件。有关更多信息,请参阅:
:help 'cursorline'
< /a>:help :autocmd
:help InsertEnter
< /a>:help :highlight
注意:你可以使用相同的方法来更改光标的颜色,而无需所有这些
if
语句和转义序列(这也适用于 GVim)。This is pretty straightforward, put the following in your
.vimrc
or custom colorscheme file.For more information see:
:help 'cursorline'
:help :autocmd
:help InsertEnter
:help :highlight
N.B: You can use the same method to change the colour of the cursor without all of those
if
-statements and escape-sequences (and this will also work in GVim).当将 MacVim 与 'Lokaltog/vim-powerline' 一起使用时,您可以设置正常/视觉/插入颜色与电力线模式颜色相匹配。我发现这对于在不阅读电源线的情况下了解我所处的模式非常有帮助,尤其是在大屏幕上。
这是我正在使用的代码,基于 @Zarick-Lau 的答案。
在我的
colors/molokai.vim
文件中:这是一个使用 molokai 原始配色方案的示例。
正常
视觉
插入
我还发现将操作系统设置为使用相同颜色进行视觉选择也很有帮助。例如,我已将 OSX 中的突出显示颜色更改为
Orange
, 蓝色,与 VIM 中相同。当我选择文本时,它现在是橙色而不是 src="https://i.sstatic.net/HSZjR.png" alt="选择橙色突出显示">
示例
这里,文本框中使用的橙色突出显示为我现在我在操作系统中选择的所有文本都与 VIM 设置匹配。
When using MacVim with 'Lokaltog/vim-powerline' you can setup your normal/visual/insert colors to match the powerline mode color. I find this extremely helpful to know what mode I'm in without reading the powerline, especially on a large screen.
Here is the code I am using, based on @Zarick-Lau's answer.
In my
colors/molokai.vim
file:Here is an example using the molokai original color scheme.
Normal
Visual
Insert
I also find it's helpful to set the OS up to visually select using the same color too. For example, I've changed my highlight color to
Orange
in OSX, and when I select text, it is now orange instead of blue, same as in VIM.Example
Here the orange highlight being used in the text-box as I'm writing this Stack Overflow entry. Now all text I select in my OS matches the VIM setup.
我选择在插入模式下切换
CursorLine
和Normal
。首先使用:hi Normal
和:hi CursorLine
获取值。然后调整以下行:对于日光,看起来像这样。我喜欢“聚焦”效果。
I chose to switch
CursorLine
andNormal
in insert mode. First get the values with:hi Normal
and:hi CursorLine
. Then adjust the following lines:For solarized light, this looks like this. I like the "focus" effect.
即使您进入或离开插入模式,当前行中也没有颜色
NO COLOR in current line even if you enter or leave INSERT MODE