命令模式下的垂直vim光标

时间:2016-10-06 20:18:39

标签: css macos vim terminal cursor

我在mac上,我的终端光标设置为垂直条选项。但是在vim命令模式下,光标是垂直条,但它不会让我使用hjkl到达行尾,它总是在结束前停止。这尤其令人讨厌,因为您必须在插入模式下使用箭头键才能使光标移到行尾。任何修复都将不胜感激

例如:hello worl | d,我想要的是你好世界|

2 个答案:

答案 0 :(得分:2)

我认为您正在寻找set virtualedit=onemore

来自: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!

我自己从来没有发现任何问题,所以尽管有警告,它似乎还是相当安全的。

答案 1 :(得分:0)

如果您使用iTerm2,还有一个小技巧:您可以根据您的模式自动切换光标。如果您的默认光标是块光标,并且您只想在插入模式下使用垂直条,这样可以更好地工作,但我仍会显示它:

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

这指示vim在输入(&t_SI)和退出(&t_EI)插入模式时打印这些字符串。 iTerm2有一堆proprietary escape codes,它们将字符串解释为更改光标形状的指令。

然后你需要做的就是以某种方式在启动vim时打印"\<Esc>]50;CursorShape=0\x7",在退出时打印"\<Esc>]50;CursorShape=1\x7"。为此,您可以使用autocmds:

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

输入vim时会自动将光标形状更改为框,然后在退出时将其恢复为垂直条。