How to go to the end of the file in vim while preserving the current column under the cursor?

前端 未结 1 514
醉酒成梦
醉酒成梦 2020-12-19 00:11

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 t

相关标签:
1条回答
  • 2020-12-19 00:17

    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).

    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.
    
    0 讨论(0)
提交回复
热议问题