Vertical vim cursor in command mode

守給你的承諾、 提交于 2019-12-02 04:08:41

I think you're looking for set virtualedit=onemore.

From :help 'virtualedit':

A comma separated list of these words:
    block   Allow virtual editing in Visual block mode.
    insert  Allow virtual editing in Insert mode.
    all     Allow virtual editing in all modes.
    onemore Allow the cursor to move just past the end of the line

[...]

"onemore" is not the same, it will only allow moving the cursor just
after the last character of the line.  This makes some commands more
consistent.  Previously the cursor was always past the end of the line
if the line was empty.  But it is far from Vi compatible.  It may also
break some plugins or Vim scripts.  For example because l can move
the cursor after the last character.  Use with care!

I've never noticed any problems myself, so it seems reasonably safe in spite of the warning.

In case you're using iTerm2, there's a little trick: You can automatically switch your cursor depending on your mode. This works better if your default cursor is the block cursor, and you only want a vertical bar in insert mode, but I'll show it nevertheless:

let &t_EI = "\<Esc>]50;CursorShape=0\x7"
let &t_SI = "\<Esc>]50;CursorShape=1\x7"

This instructs vim to print those strings when entering (&t_SI) and exiting (&t_EI) insert mode. iTerm2 has a bunch of proprietary escape codes that interpret the strings as instructions to change the cursor shape.

All you then would need to do is somehow print "\<Esc>]50;CursorShape=0\x7" when starting vim and "\<Esc>]50;CursorShape=1\x7" when exiting it. For that, you can use autocmds:

autocmd BufEnter * execute 'silent !echo -ne "' . &t_EI . '"'
autocmd VimLeave * execute '!echo -ne "' . &t_SI . '"'

This automatically changes your cursor shape to a box when entering vim, and then restores it to a vertical bar when exiting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!