Vim缓冲区切换后光标跳转到行首

33

当我切换缓冲区并返回它时(基本上是当我回到任何先前打开的缓冲区时),光标会被放置在行的开头,失去了之前在行中的位置。这非常令人烦恼。

2个回答

44

您可以使用该设置。

: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
每当我保存一个缓冲区时,光标就会跳到缓冲区的开头,这个答案也解决了我遇到的问题。谢谢。 - qed

0

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

添加

let g:auto_save_in_insert_mode = 0 " 在插入模式下不保存

到你的.vimrc

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接