缓冲区切换后,Vim光标跳转到行的开头

时间:2011-11-28 07:43:07

标签: vim

当我切换缓冲区然后返回它(基本上当我回到之前打开的任何缓冲区时),光标放在行的开头,丢失前一行的位置。这非常烦人。

2 个答案:

答案 0 :(得分:38)

您可以使用设置

:se nostartofline

或简称:

:se nosol

文档:

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

答案 1 :(得分:0)

我不得不在插入模式下禁用自动保存。它在插入模式下自动保存,导致光标跳到开头:

添加

let g:auto_save_in_insert_mode = 0 " do not save while in insert mode

到您的.vimrc

文档:https://github.com/vim-scripts/vim-auto-save.