2015-12-13 33 views
3

我習慣使用gvim,但我想使用vim + tmux的好處。爲此我想換成vim。但是在vim中,光標樣式並不會改變,這取決於我是哪種模式,這是gvim的一個有用特性。我使用zsh(oh-my-zsh)並在gnome-terminal下面。如何在vim中更改光標樣式,具體取決於插入模式還是普通模式?

我想這個答案:http://vim.wikia.com/wiki/Change_cursor_shape_in_different_modes

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 

但globaly改變光標。絕對是我不想要的東西

接下來我試過這個插件:http://www.vim.org/scripts/script.php?script_id=4403,但它都沒有奏效。

+0

它看起來可以滿足我的需求,但它也不起作用。你能想象爲什麼? – Jonas

+0

看來我完全誤讀了你的文章。我刪除了我的答案。 –

+0

[如何在插入/正常模式下更改vim光標?](http:// stackoverflow。com/questions/6488683/how-do-i-change-the-vim-cursor-in-insert-normal-mode) –

回答

0

對於顏色,這是我用:

let &t_SI = "\<Esc>]12;yellow\x7" 
let &t_SR = "\<Esc>]12;red\x7" 
let &t_EI = "\<Esc>]12;blue\x7" 

其他選項:

" solid underscore 
" let &t_SI .= "\<Esc>[4 q" 

" solid block 
" let &t_EI .= "\<Esc>[1 q" 
    " 1 or 0 -> blinking block 
    " 3 -> blinking underscore 
    " Recent versions of xterm (282 or above) also support 
    " 5 -> blinking vertical bar 
    " 6 -> solid vertical bar 

這是termcap的代碼,請參閱幫助的termcap光標顏色。代碼本身是console_codes(4)。因此,這些是與終端本身的交互,而不是vim會話。

我不幸沒有解決關於離開Vim並返回原始光標顏色的問題。我已經嘗試了以下及其許多變體:

au VimLeave * let &t_EI = "\<Esc>]12;white\x7" 
au VimLeavePre * :!echo -ne "\033]12;white\000" 
au VimLeavePre * let &t_SI = "\<Esc>]12;white\x7" 

但沒有成功。無論如何,這是如何改變與編輯模式相關的光標形狀和顏色。

用於在模式變化更一般的變化(例如,色彩方案的變化),我用

au InsertEnter * call ColoursBasedOnMode(v:insertmode) 
au InsertLeave * call ColoursBasedOnMode('n') 
autocmd BufWinEnter,BufNew * call ColoursBasedOnMode('n') 

中,我有:

: 
    : 
elseif a:mode == 'i' 
    "echo " ColoursBasedOnMode insert mode" 
    "set nonumber 
    "set norelativenumber 

    colorscheme railscasts 
     : 
     : 
+0

謝謝,但你究竟在哪裏放置代碼?在.vimrc中? – Jonas

+0

是的,是的,在我的.vimrc中 –

0

設置終端選項只是這個終端仿真器。 正如在此指出的那樣:https://stackoverflow.com/a/25327689/2544873

let &t_SI = "\<Esc>]12;orange\x7" 
let &t_EI = "\<Esc>]12;red\x7" 
autocmd VimLeave * silent !echo -ne "\033]112\007" 
  1. 設置在進入插入模式
  2. 休假插入模式
  3. 設置端子光標
  4. 復位默認休假VIM
0

可能要(灰)色,wincent/terminus VIM插件是終端光標你需要什麼:

在插入模式下,光標形狀更改爲細豎條。在替換模式下,它會更改爲下劃線。在返回到正常模式時,它將恢復到標準「塊」形狀。提供配置選項以在不同的形狀中進行選擇。

相關問題