【问题标题】:Vertical vim cursor in command mode命令模式下的垂直 vim 光标
【发布时间】:2017-02-15 17:27:28
【问题描述】:

我在 Mac 上,我将终端光标设置为竖线选项。但是在 vim 命令模式下,光标是竖线,但它不会让我使用 hjkl 转到行尾,它总是在行尾之前停止。这特别烦人,因为您必须在插入模式下使用箭头键才能使光标移到行尾。任何修复将不胜感激

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

【问题讨论】:

    标签: css macos vim terminal cursor


    【解决方案1】:

    我想你正在寻找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!
    

    我自己从未发现任何问题,因此尽管有警告,但它似乎相当安全。

    【讨论】:

      【解决方案2】:

      如果您使用的是 iTerm2,有一个小技巧:您可以根据您的模式自动切换光标。如果您的默认光标是块光标,并且您只想要插入模式下的竖线,这会更好,但我会展示它:

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

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

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

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

      这会在进入 vim 时自动将您的光标形状更改为一个框,然后在退出时将其恢复为竖线。

      【讨论】:

        猜你喜欢
        • 2016-05-08
        • 1970-01-01
        • 1970-01-01
        • 2023-04-09
        • 2019-06-21
        • 2018-10-14
        • 1970-01-01
        • 1970-01-01
        • 2014-12-06
        相关资源
        最近更新 更多