如何在Gnome终端上的Console Vim中根据普通模式或插入模式将光标从细线更改为块

我正在使用Gnome终端2.32.1从Gvim切换到使用Console Vim。

我非常喜欢在Gvim中,当处于正常模式时光标将是一个实心方块,而在插入模式下光线是如何。

  • 在Gnome终端中运行控制台Vim时有没有办法产生这种function?

  • 如果不可能,有什么技巧可以知道你在哪种模式? 我知道屏幕底部显示的模式,但似乎没有光标(这是我的眼睛看的地方)有用。 或者你只是习惯于练习?

对于gnome-terminal,将其添加到~/.vimrc (如果缺少则创建):

 if has("autocmd") au InsertEnter * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam" au InsertLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape block" au VimLeave * silent execute "!gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/cursor_shape ibeam" endif 

在此处找到: 在不同模式下更改光标形状 。

编辑

将最后一个ibeam更改为block ,使用块光标离开。

对于gnome终端版本> 3.15
将其添加到〜/ .vimrc中。

 if has("autocmd") au VimEnter,InsertLeave * silent execute '!echo -ne "\e[2 q"' | redraw! au InsertEnter,InsertChange * \ if v:insertmode == 'i' | \ silent execute '!echo -ne "\e[6 q"' | redraw! | \ elseif v:insertmode == 'r' | \ silent execute '!echo -ne "\e[4 q"' | redraw! | \ endif au VimLeave * silent execute '!echo -ne "\e[ q"' | redraw! endif 

您将在正常模式下获得一个块光标,在插入模式下获得一个薄光标。

没有必要为此使用自动命令或gconftool – Vim现在支持它。

将以下行插入vimrc:

 let &t_SI = "\[5 q" " blinking I-beam in insert mode let &t_SR = "\[3 q" " blinking underline in replace mode let &t_EI = "\[ q" " default cursor (usually blinking block) otherwise 

自从2014年底发布的VTE版本0.39以及xterm以来,这些序列应该适用于所有基于VTE的终端仿真器。 如果您想要停止光标闪烁,请为每个数字添加一个,并在t_EI的序列中插入2 ( 此答案中列出了可能的序列;另请参阅VT510手册 )。