如何在vim中转到文件末尾同时保留光标下的当前列? [英] How to go to the end of the file in vim while preserving the current column under the cursor?

查看:24
本文介绍了如何在vim中转到文件末尾同时保留光标下的当前列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Often when I use a visual mode, I would like to expand the selection to the whole file. But hitting VG takes me to the first character of the last line. I would like it to take me to the same column of the last line as I was before I used that command. Is there an easy way to achieve that? I could use 200000j for that or something, but that's not too elegant. Thanks.

推荐答案

如果你在 vimrc 中添加 set nostartofline 在可视模式下输入 G 将转到底部行而不更改列.但是,这可能会更改您使用的其他一些行为,因为它更改了一些其他命令.(这可能是不可取的).

If you add set nostartofline to your vimrc typing G while in visual mode will go to the bottom line without changing the column. However this might change some of the other behaviors you are used because it changes some other commands. (which might be undesirable).

startofline 的帮助被复制到下面,以便您可以查看哪些命令受此影响设置.

Help for startofline is copied below so you can see which commands are affected by this setting.

               *'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.

这篇关于如何在vim中转到文件末尾同时保留光标下的当前列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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