如何在vim中转到文件的末尾,同时保留光标下的当前列?

l7mqbcuq  于 2022-11-11  发布在  其他
关注(0)|答案(2)|浏览(164)

通常当我使用可视化模式时,我想把选择范围扩展到整个文件。但是点击VG会把我带到最后一行的第一个字符。我想让它把我带到最后一行的同一列,就像我使用这个命令之前一样。有没有简单的方法来实现这个目标?我可以用200000j来实现这个目标,但是这样做不太优雅。谢谢。

vdzxcuhz

vdzxcuhz1#

如果你在vimrc中添加了set nostartofline,在可视化模式下输入G会跳到最后一行,而不会改变列。但是,这可能会改变你正在使用的一些其他行为,因为它会改变一些其他命令。(这可能是不需要的)。
下面复制了startofline帮助,以便您可以查看哪些命令受此设置影响


* 'startofline'* *'sol'* *'nostartofline'* *'nosol'*

'startofline' 'sol' boolean (default on)
            global
            {not in Vi}
    When "on" the commands listed below move the cursor to the first
    non-blank of the line.  When off the cursor is kept in the same column
    (if possible).  This applies to the commands: CTRL-D, CTRL-U, CTRL-B,
    CTRL-F, "G", "H", "M", "L", gg, and to the commands "d", "<<" and ">>"
    with a linewise operator, with "%" with a count and to buffer changing
    commands (CTRL-^, :bnext, :bNext, etc.).  Also for an Ex command that
    only has a line number, e.g., ":25" or ":+".
    In case of buffer changing commands the cursor is placed at the column
    where it was the last time the buffer was edited.
    NOTE: This option is set when 'compatible' is set.
xwbd5t1u

xwbd5t1u2#

如果不希望更改sol选项,则可以仅为可视模式MapG

vnoremap G 99999j

相关问题