如何从“gf”返回 在维姆中

发布于 2024-07-05 08:18:25 字数 234 浏览 10 评论 0原文

我使用的是在 Unix 模式下安装的 Windows 版 Vim。 感谢这个网站,我现在使用 gf 命令转到光标下的文件。

我正在寻找一个命令:

  1. 返回到上一个文件(类似 对于 ctags 为 Ctrl+T),或
  2. 重新映射 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:

  1. return to the previous file (similar
    to Ctrl+T for ctags), or
  2. remap gf
    to automatically launch the new file
    in a new window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

鲜肉鲜肉永远不皱 2024-07-12 08:18:27

我经常使用 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.

-黛色若梦 2024-07-12 08:18:27

您可能需要使用 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 use CTRL-6 and other usual ways of changing buffers.

慕巷 2024-07-12 08:18:27

使用 gf 进入文件并使用 :bf 返回

Use gf to descend into a file and use :bf to get back

国产ˉ祖宗 2024-07-12 08:18:27

只需使用 :e# 后跟 Enter - 基本上就是编辑最后一个(最新的)文件。

Just use :e# followed by Enter - that basically says to edit the last (most recent) file.

套路撩心 2024-07-12 08:18:27

Ctrl-Shift-6 是其中之一。

:e#↲ 是另一个。

Ctrl-Shift-6 is one.

:e#↲ is another.

攒一口袋星星 2024-07-12 08:18:27

我让 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.

手心的温暖 2024-07-12 08:18:27

我不知道你问题第二部分的答案,但我可以帮助解决第一部分。使用

:e#

Vim 维护它正在编辑的文件(缓冲区)列表。 如果您键入,

:buffers

它将列出您当前正在编辑的所有文件。 该列表中旁边带有 % 的文件是当前文件。 旁边带有 # 的文件是备用文件。 :e# 将在当前文件和备用文件之间切换。 我没有输入那么多内容,而是将 F2 映射到 :e#,这样我就可以轻松地在当前文件和备用文件之间切换。 我通过将其添加到 .vimrc 将命令映射到 F2

nmap `<F2> :e#<CR>`

I don't know the answer to part 2 of your question, but I can help with part 1. Use

:e#

Vim maintains a list of files (buffers) that it's editing. If you type

:buffers

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

nmap `<F2> :e#<CR>`
孤凫 2024-07-12 08:18:27

当您打开新文件(使用 gf:n 或其他命令)时,旧文件保留在缓冲区列表中。 您可以使用 :ls 列出打开的文件

如果您想在 vim 中的缓冲区之间轻松导航,您可以创建如下映射:

nmap <M-LEFT> :bN<cr>
nmap <M-RIGHT> :bn<cr>

现在您可以使用 Alt+ 在缓冲区之间切换Alt+

有关映射的完整文档位于此处:

:help map.txt

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:

nmap <M-LEFT> :bN<cr>
nmap <M-RIGHT> :bn<cr>

Now you can switch between buffers with Alt+ or Alt+.

The complete documentation on mappings is here:

:help map.txt
合约呢 2024-07-12 08:18:27

我没有看过您的 gf 命令,但我想它使用 :e:find 命令。
假设这是正确的,只需将 :e:find 替换为 :new (或 :vnew )垂直分割),文件将在新窗口而不是同一个窗口中打开。

例如

"Switch between header and cpp
nmap ,s :find %:t:r.cpp<CR>
nmap ,S :new %:t:r.cpp<CR>
nmap ,h :find %:t:r.h<CR>
nmap ,H :new %:t:r.h<CR>
nmap ,F :new =expand("<cfile>:t")<CR><CR>
nmap ,d :new =expand("<cfile>")<CR><CR> 

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.

"Switch between header and cpp
nmap ,s :find %:t:r.cpp<CR>
nmap ,S :new %:t:r.cpp<CR>
nmap ,h :find %:t:r.h<CR>
nmap ,H :new %:t:r.h<CR>
nmap ,F :new =expand("<cfile>:t")<CR><CR>
nmap ,d :new =expand("<cfile>")<CR><CR> 

倒带 2024-07-12 08:18:25

我使用 Ctrl-O

I use Ctrl-O

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文