我想根据我目前的模式改变VIM (不是gVIM)的光标.我想:
我尝试添加以下代码,.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
Run Code Online (Sandbox Code Playgroud)
我从http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes获得了一些代码,但它说它是Gnome-Terminal(版本2.26),我有Gnome-Terminal(版本3.60).不确定这是否是它无法正常工作的原因.
关于如何做到这一点的任何想法?
我有 gnome-terminal 3.10.2,我按照以下步骤让它工作:
创建一个名为 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'"
Run Code Online (Sandbox Code Playgroud)
并用 ibeam、块或下划线调用它来改变光标形状。
将脚本放入 /usr/bin 或 /usr/local/bin 中,并将以下行添加到 .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
Run Code Online (Sandbox Code Playgroud)