在Vim中如何在两个文件之间跳转

Neh*_*kar 7 vim

我需要在Vim中的两个文件之间来回跳转.

我可以手动执行此操作,:e file1.txt然后按:e file2.txt.是否有直接跳转到以前打开的文件的快捷方式?

注意:我不想在拆分窗口或多个选项卡中打开这两个文件.

我正在寻找类似的东西[ctrl + o],只有跳转应该是以前的文件,而不是以前的位置在同一个文件中

谢谢你的任何提示

rom*_*inl 10

使用<C-^><C-6>.

来自:h ctrl-^:

Edit the alternate file. Mostly the alternate file is
the previously edited file. This is a quick way to
toggle between two files. It is equivalent to ":e #",
except that it also works when there is no file name.

If the 'autowrite' or 'autowriteall' option is on and
the buffer was changed, write it.
Mostly the ^ character is positioned on the 6 key,
pressing CTRL and 6 then gets you what we call CTRL-^.
But on some non-US keyboards CTRL-^ is produced in
another way.
Run Code Online (Sandbox Code Playgroud)


Boh*_*ohr 10

这是文件和缓冲区管理的主题。您可以查看相关文档。我想出了一些您可能感兴趣的命令:

CTRL+^:转到同一窗口中最后编辑的文件。

gf:如果可以找到光标下的链接,则转到文件。

:bn :bp:转到下一个或上一个缓冲区。

:n :N:转到下一个或上一个 arg 文件。

还有一个叫unimpaired的插件,让你更开心!

如果你想按照你的意愿跳转到一个文件:

:b partial_word然后按Tab,您将获得自动完成。

:ls然后:b a_number去那个缓冲区。

一些插件如 bufexplorer、nerdtree 非常有用。但在这种情况下,您可以考虑CtrlP,它可以非常快速地搜索所有文件!


Grz*_*lik 6

我不确定我是否理解正确,但只打开两个文件buffer next :bn就足够了?


eck*_*kes 5

要真正在两个文件之间切换,请使用:b#:当打开两个以上的文件时,这样更方便.

也就是说,如果你有file1,file2,file3加载和希望之间翻转23:

  • :b file2 打开file2
  • :b file3 打开file3
  • 从现在开始,:b#从3切换到2,反之亦然.

在这种情况下,:bn将循环通过1,2,3,1,2,3 ......