Vim 中的当前缓冲区在打开文件时被替换

Current buffer in Vim get replaced when opening a file

当通过 :E 命令打开一个新文件时(不使用 ctrl-P 插件,这工作正常!),Vim 和 MacVim (8.0.1098) 丢弃当前缓冲区的内容,因此无法使用 :bn!:bp! 命令切换到 if。

但是,如果我修改当前缓冲区的内容,然后打开另一个文件,然后才尝试关闭 MacVim,我会收到有关未保存文件的警告消息。所以缓冲区一定还挂在某处?

另外,如果我拆分 window 然后打开一个文件,两个缓冲区都保持打开状态。

我的 .vimrc 和 运行 :set hidden? returns hidden 中确实有 set hidden,这意味着使用 :bn!:bp! 应该起作用,但它不起作用。

When opening a new file via :E command, both Vim and MacVim (8.0.1098) discard contents of the current buffer, so it becomes impossible to switch to if by using :bn! and :bp! commands.

您描述的行为不符合:

  • 预期的行为,
  • 和我在完全相同的版本中得到的行为。

以可重复的方式进行测试:

$ vim -Nu NORC a.txt     starts Vim with a.txt
:Explore                 replaces the current buffer with a netrw buffer
(press <CR> on b.txt)    replaces the netrw buffer with b.txt
:bn (or :bp)             replaces the current buffer with a.txt

However, if I modify the contents of current buffer, then open another file and only then try to close MacVim, I get a warning message about unsaved file. So the buffer must be still hanging somewhere?

是的,几乎可以肯定它在缓冲区列表中。对列出的缓冲区尝试 :ls,对所有缓冲区尝试 :ls!:ls 应该在 #1 处向您显示 a.txt,在 #3 处显示 b.txt,而 :ls! 应该向您显示相同的内容,加上在 #2 处的 netrw 缓冲区。

另请参阅 :help 'hidden'

--- 编辑 ---

作为参考,:ls! 的预期输出应该是:

1      "a.txt"                        line 1
2u#h-  "~/"                           line 11
3 %a   "~/b.txt"                      line 1

请注意,唯一的 "unlisted" 缓冲区应该是 Netrw 缓冲区:~/ 在 #2。

您是否更改了 $HOME 之外的任何 Vim 相关文件或目录?

ctrlP 在打开和切换缓冲区时没有问题这一事实表明 netrw 有问题。

仔细检查后发现我的 netrw 插件已经过时了。

升级到 v162j(通过 Vundle)解决了问题。