如何从“gf”返回 在维姆中
我使用的是在 Unix 模式下安装的 Windows 版 Vim。 感谢这个网站,我现在使用 gf
命令转到光标下的文件。
我正在寻找一个命令:
- 返回到上一个文件(类似 对于 ctags 为 Ctrl+T),或
- 重新映射
gf
自动启动新文件 在新窗口中。
I am using Vim for windows installed in Unix mode. Thanks to this site I now use the gf
command to go to a file under the cursor.
I'm looking for a command to either:
- return to the previous file (similar
to Ctrl+T for ctags), or - remap
gf
to automatically launch the new file
in a new window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我经常使用 Ctrl-6 来实现此目的。
它很方便,因为它允许我在两个文件之间快速来回跳转。
I frequently use Ctrl-6 for this.
It's handy because it allows me to quickly jump back and forth between the two files.
您可能需要使用
CTRL-W gf
在新选项卡中打开文件。您可以像往常一样使用
:bd
关闭新打开的文件,或使用CTRL-6
和其他更改缓冲区的常用方法。You might want to use
CTRL-W gf
to open the file in a new tab.You can close the newly opened file as always with
:bd
, or useCTRL-6
and other usual ways of changing buffers.使用 gf 进入文件并使用 :bf 返回
Use gf to descend into a file and use :bf to get back
只需使用
:e#
后跟 Enter - 基本上就是编辑最后一个(最新的)文件。Just use
:e#
followed by Enter - that basically says to edit the last (most recent) file.Ctrl-Shift-6 是其中之一。
:e#↲
是另一个。Ctrl-Shift-6 is one.
:e#↲
is another.我让 CTRL-Wf 开始工作。
令人沮丧的是,我花了这么长时间完善这些命令的映射,却发现有内置版本。
I got CTRL-Wf to work.
It's quite depressing that I've spent so long perfecting maps for these commands only to discover that there are built-in versions.
我不知道你问题第二部分的答案,但我可以帮助解决第一部分。使用
Vim 维护它正在编辑的文件(缓冲区)列表。 如果您键入,
它将列出您当前正在编辑的所有文件。 该列表中旁边带有 % 的文件是当前文件。 旁边带有 # 的文件是备用文件。 :e# 将在当前文件和备用文件之间切换。 我没有输入那么多内容,而是将 F2 映射到 :e#,这样我就可以轻松地在当前文件和备用文件之间切换。 我通过将其添加到 .vimrc 将命令映射到 F2
I don't know the answer to part 2 of your question, but I can help with part 1. Use
Vim maintains a list of files (buffers) that it's editing. If you type
it will list all the files you are currently editing. The file in that list with a % beside it is the current file. The one with the # beside it is the alternate file. :e# will switch between the current and alternate file. Rather than type that much, I map F2 to :e# so I can easily flip between the current and alternate files. I map the command to F2 by adding this to .vimrc
当您打开新文件(使用 gf 或 :n 或其他命令)时,旧文件保留在缓冲区列表中。 您可以使用 :ls 列出打开的文件
如果您想在 vim 中的缓冲区之间轻松导航,您可以创建如下映射:
现在您可以使用 Alt+ 在缓冲区之间切换← 或 Alt+→。
有关映射的完整文档位于此处:
When you open a new file (with gf or :n or another command) the old file remains in a buffer list. You can list open files with :ls
If you want to navigate easily between buffers in vim, you can create a mapping like this:
Now you can switch between buffers with Alt+← or Alt+→.
The complete documentation on mappings is here:
请参阅 :helpalternate-file。
See :help alternate-file.
我没有看过您的 gf 命令,但我想它使用 :e 或 :find 命令。
假设这是正确的,只需将 :e 或 :find 替换为 :new (或 :vnew )垂直分割),文件将在新窗口而不是同一个窗口中打开。
例如
I haven't looked at your gf command but I imagine it uses the :e or :find command.
Assuming that this is correct, simply replace the :e or :find with :new (or :vnew for a vertical split) and the file will open in a new window instead of the same one.
e.g.
我使用 Ctrl-O
I use Ctrl-O