问题
I would like to change VIM's (not gVIM's) cursor depending on what mode I am currently in. I would like:
- Normal & Visual modes = block cursor
- Insert & Command modes = I beam cursor
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
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?
回答1:
I have gnome-terminal 3.10.2 and I got it working with the following steps:
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'"
And call it with ibeam, block or underline to change cursor shape.
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
回答2:
For me, gnidmoos solution worked after changing the script script called gnome-terminal-cursor-shape.sh to:
#!/bin/sh
gconftool-2 --set "/apps/gnome-terminal/profiles/Default/cursor_shape" --type string "$1"
(using the same lines in .vimrc)
Ps. I'm running ubuntu 14.04, GNOME Terminal 3.6.2
Cheers!
来源:https://stackoverflow.com/questions/14266346/how-to-change-vim-cursor-shape-while-in-different-modes-in-gnome-terminal