问题描述
我想更改VIM的(不是gVIM的)光标,取决于我目前的模式。我想:
I would like to change VIM's (not gVIM's) cursor depending on what mode I am currently in. I would like:
- 正常&视觉模式=块光标
- 插入&命令模式= I beam光标
我尝试将以下代码添加到 .vimrc
但它没有工作。
I tried adding the following code to .vimrc
but it did not work.
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
我得到了,但它说它是Gnome-Terminal(版本2.26)和我有Gnome-Terminal(版本3.60)。不知道这是否为什么它不工作的原因。
I got that bit of code from http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes but it says that it is for Gnome-Terminal (version 2.26) and I have Gnome-Terminal (version 3.60). Not sure if that is the reason why it's not working.
有关如何执行此操作的任何想法?
Any ideas on how to do this?
推荐答案
我有gnome-terminal 3.10.2,我使用以下步骤:
I have gnome-terminal 3.10.2 and I got it working with the following steps:
创建一个名为gnome-terminal-cursor-shape的脚本。 sh:
Create a script called gnome-terminal-cursor-shape.sh:
#!/bin/sh
DEFAULTPROF=`dconf read /org/gnome/terminal/legacy/profiles:/default`
DEFAULTPROF=`echo "$DEFAULTPROF" | sed -e "s/^'/:/" -e "s/'$//"`
dconf write /org/gnome/terminal/legacy/profiles:/$DEFAULTPROF/cursor-shape "'$1'"
并使用ibeam,块或下划线调用以更改光标形状。
And call it with ibeam, block or underline to change cursor shape.
将脚本放在/ usr / bin或/ usr / local / bin中,并将以下行添加到.vimrc中:
Put the script in /usr/bin or /usr/local/bin, and add the following lines to your .vimrc:
if has("autocmd")
au InsertEnter *
\ if v:insertmode == 'i' |
\ silent execute "!gnome-terminal-cursor-shape.sh ibeam" |
\ elseif v:insertmode == 'r' |
\ silent execute "!gnome-terminal-cursor-shape.sh underline" |
\ endif
au InsertLeave * silent execute "!gnome-terminal-cursor-shape.sh block"
au VimLeave * silent execute "!gnome-terminal-cursor-shape.sh block"
endif
这篇关于如何在Gnome终端中的不同模式下更改VIM游标形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!