28

Vim 配置光标形状和颜色(Windows Terminal、xterm)

 3 years ago
source link: https://www.starky.ltd/2021/06/08/change-vim-cursor-shape-and-color-in-xterm-or-windows-terminal/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Vim 配置光标形状和颜色(Windows Terminal、xterm)

发表于 2021-06-08

| 分类于 Linux

| 0

| 阅读次数: 2

字数统计: 1.5k

|

阅读时长 ≈ 0:01

Windows Terminal 里的 Vim 设置了浅的配色,刚好光标默认是白色的竖线,不容易看出来。很有点费眼睛。

想把光标改成其他颜色的方块样式。因为不是 gvim,guicursor 之类的配置不起作用。
上网查了些资料,测试如下配置可以正常生效(貌似这个 Terminal 是属于 xterm 那一类):

" Set cursor shape and color
if &term =~ "xterm"
" INSERT mode
let &t_SI = "\<Esc>[6 q" . "\<Esc>]12;blue\x7"
" REPLACE mode
let &t_SR = "\<Esc>[3 q" . "\<Esc>]12;black\x7"
" NORMAL mode
let &t_EI = "\<Esc>[2 q" . "\<Esc>]12;green\x7"
endif
" 1 -> blinking block 闪烁的方块
" 2 -> solid block 不闪烁的方块
" 3 -> blinking underscore 闪烁的下划线
" 4 -> solid underscore 不闪烁的下划线
" 5 -> blinking vertical bar 闪烁的竖线
" 6 -> solid vertical bar 不闪烁的竖线

其中各配置项的含义如下:

  • &t_SI 表示插入模式
  • &t_SR 表示替换模式
  • &t_EI 表示 Normal 模式
  • . 号左边的 "\<Esc>[6 q" 用来配置光标的形状。其中 6 的取值可以是 1 - 6,分别指代不同的光标样式(参考前面的注释)
  • . 号右边的 "\<Esc>]12;blue\x7" 用来配置光标颜色,其中的 blue 可以替换为其他颜色名词

设置光标颜色时也可以使用 RGB 颜色,格式为 rgb:RR/GG/BB。比如纯白色的光标即为 "\<Esc>]12;rgb:FF/FF/FF\x7"

若只想设置光标形状,直接去掉 . 号以及右边的颜色配置部分即可。如 let &t_SR = "\<Esc>[3 q"
同理,只想修改颜色时也可以将 . 号左边的形状配置部分删掉。
. 号在这里的作用其实是字符串拼接,方便区分形状配置部分和颜色配置部分而已。去掉 . 号直接将两部分配置写在一个字符串里也是可以的。
let &t_SR = "\<Esc>[3 q" . "\<Esc>]12;black\x7" 等同于 let &t_SR = "\<Esc>[3 q\<Esc>]12;black\x7"

Normal 模式(绿色方块):Normal

插入模式(蓝色竖线):Insert

替换模式(黑色下划线):Replace

Cursor color in xterm; change accordingly to the syntax in vim


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK