在“VimLeave”上重置或设置光标形状 [英] Reset or set cursor shape on "VimLeave"

查看:711
本文介绍了在“VimLeave”上重置或设置光标形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用iTerm2(Build 1.0.0.20130319)和Vim(MacVim Snapshot 66的bin)作为我的CLI编辑团队OS X 10.7.5。



在iTerm2中,我定义了使用不闪烁的垂直条作为光标形状。
在Vim中我定义

 输入插入模式(光标形状:垂直条)
let& t_SI =\< Esc>] 50; CursorShape = 1 \x7

离开插入模式(光标形状:块)
let& t_EI =\ ; Esc>] 50; CursorShape = 0 \ x7

正常模式。基本上这工作正常。当我离开Vim并返回到CLI时出现问题。发生的情况是,光标不返回其初始形状(垂直条)。



我可以将光标重置为初始形状,还是强制它返回一个垂直条形?我可以设想触发一个活动。 VimLeave。但我不知道我可以作为一个转义序列传递。

解决方案

$ c>:help 我发现

  autocmd VimLeave * let& t_me =\\ \\< Esc>] 50; CursorShape = 1 \x7

它的初始,或者说一个定义的形状。
到目前为止很好。



有没有人知道这种方法的缺点?除了 VimLeave ,也可以触发 VimLeavePre QuitPre 。 / p>

编辑:
更好的是有一个新的插件可以做一些人正在寻找的。

https://github.com/jszakmeister/vim-togglecursor



它也有点可配置:

  let g:togglecursor_default =block
let g:togglecursor_insert =line
let g:togglecursor_leave =line
let g:togglecursor_disable_tmux = 0


I use iTerm2 (Build 1.0.0.20130319) and Vim (bin of MacVim Snapshot 66) on top of OS X 10.7.5 as my CLI editing team.

In iTerm2 I defined to use a non-blinking vertical bar as a cursor shape. In Vim I defined

" Enter insert mode (Cursor shape: vertical bar)
let &t_SI = "\<Esc>]50;CursorShape=1\x7"

" Leave insert mode (Cursor shape: block)
let &t_EI = "\<Esc>]50;CursorShape=0\x7"

to be able to distinct between insert and normal mode. Basically this works fine. The problem arises when I leave Vim and return to the CLI. What happens is that the cursor does not return in its initial shape (vertical bar). Instead it decides to stay in a block shape.

Could I reset the cursor to it's initial shape or force it to return to be a vertical bar? I Could imagine to trigger an event on e.g. "VimLeave". But I don't know what I could pass as an escape sequence.

解决方案

After a little bit more digging into :help I found out that

autocmd VimLeave * let &t_me="\<Esc>]50;CursorShape=1\x7"

would revert the cursor shape to its initial, or let's say a defined, shape. That works great so far.

Does anyone know downsides of that approach? Besides VimLeave one could also trigger VimLeavePre or QuitPre.

EDIT: Even better there's a new plugin available which does exactly what some people are looking for.

https://github.com/jszakmeister/vim-togglecursor

It's a little bit configurable, too:

let g:togglecursor_default = "block"
let g:togglecursor_insert = "line"
let g:togglecursor_leave = "line"
let g:togglecursor_disable_tmux = 0

这篇关于在“VimLeave”上重置或设置光标形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆