Reputation: 41
I'm using iTerm2 and Vim 7.4 on top of OS X 10.9.
In my bash shell, my cursor is a blinking line. I've installed Vitality (https://github.com/sjl/vitality.vim/) in order to get the Vim cursor to be a block in normal mode and a line in insert mode. Then, in order to get my cursor to revert to a line on exiting vim, I've added the following autocmd to my .vimrc (sourced from this stack overflow question):
autocmd VimLeave * let &t_me="\<Esc>]50;CursorShape=1\x7"
This is all working great; the one problem is that when I suspend Vim via Ctrl-Z (which I do frequently), my cursor remains a block. Is there some way to detect that Vim is being suspended (maybe via an autocmd) and set the cursor to a line? Also, presumably I would then have to reset the cursor to a block on resuming Vim.
Upvotes: 4
Views: 459
Reputation: 11
I use Ingo's suggestion along with what I found here:
Update Vim after it suspended?
... To toggle a different terminal setting (called "Bracketed Paste Mode") when I suspend Vim. You can tweak this for any other escape sequence pairs you need, as the general concept is not BPM specific. This trick solves the 'fg' problem. Here it is:
" (Re)Set Bracketed Paste Mode
function SetBPM(mode)
execute "silent !echo -ne '\033[?2004" . a:mode . "'"
endfunction
" toggle BPM when suspending (hook ctrl-z)...
nnoremap <silent> <C-z> :call SetBPM("l")<CR>:suspend<bar>:call SetBPM("h")<CR>
Upvotes: 1
Reputation: 172608
There's no :autocmd
event for suspending, but you can solve this part by hooking into the <C-z>
command:
:nnoremap <silent> <C-z> :let &t_me=...<CR><C-z>
Restoring the cursor on restore is more difficult. It looks like the Vitality plugin already uses autocmd events to change the shape, so one mode change (into / out of insert mode) would be required to correct things.
If that's not enough, you'd have to install a separate fire-once autocmd (e.g. on CursorMoved,CursorHold
) in the above mapping. Or you could try sending the :let
command via feedkeys()
, in the hope that it would only be executed after Vim awakes (not tested that).
Upvotes: 2