我怎样才能做像 gf 这样的事情,但是是在一个新的垂直分割中?
在 vim 中 gf
打开当前窗口中光标下名称的文件。
执行相同的操作,但在新窗口中打开它。然而,这个新窗口是通过水平分割创建的。
我怎样才能做同样的事情并获得垂直分割?
我尝试了各种可行的替代方案(例如 :vsplit +normal\ gf
),但有一个小问题:如果文件不存在,则无论如何都会创建一个新窗口。 gf
和
都不会发生这种情况。我也希望通过“在垂直分割上打开光标下的文件”命令来实现这种行为。我怎样才能做到这一点?
In vim gf
opens the file whose name is under the cursor in the current window. <C-W>f
does the same but opens it in a new window. However this new window is created with an horizontal split.
How can I do the same and get a vertical split?
I tried various alternatives that did work (like :vsplit +normal\ gf
), but have a slight problem: if the file doesn't exist, a new window is created anyways. This does not happen with gf
nor <C-W>f
. I'd like to have this behaviour as well from the "open file under cursor on a vertical split" command. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是可能的映射:
将文件名放在光标下,按 F8,瞧。
Here is possible mapping:
With a file name under cursor, hit F8 and voila.
这是一个涉及 5 个按键的解决方案:
即 Ctrl-wv 后跟gf 在正常模式下。
下面是一个等效的解决方案,涉及 7 个按键:
:vs
这是命令中的
:vs
命令在正常模式下,-line 模式后跟 gf。假设我们处于正常模式,光标已位于文件名上,则完整的击键顺序为: Shift:vs 输入gf。当我们在普通模式下输入 Ctrl-wv 或在命令行模式下输入
:vs
时,当前窗口被分成两个,两个窗口中都有相同的文件,并且光标保持在相同的位置(即,在我们想要在新的垂直分割中转到的文件的文件名上)。因此,如果我们现在按 gf,当前窗口就会更新为我们想要访问的文件。最终结果是两个垂直分割窗口:一个包含第一个文件,另一个包含我们想要访问的文件。
Here is a solution involving 5 key strokes:
That is Ctrl-wv followed by gf in the normal mode.
Here is an equivalent solution that involves 7 key strokes:
:vs
That is
:vs
command in command-line mode followed by gf in normal mode. Assuming we are in the normal mode with the cursor on the filename already, the complete sequence of keystrokes are: Shift:vsEntergf.When we enter Ctrl-wv in normal mode or
:vs
in the command-line mode, the current window is split into two with the same file in both and the cursor remains in the same position (i.e., on the filename of the file that we want to go to in a new vertical split). So if we press gf now, the current window is now updated with the file we want to go to.The end result is two vertical split windows: one with the first file and another with the file we wanted to go to.
如果我们正在玩 Vim Golf,我认为获胜的解决方案是:
Ctrl-w 然后 f
在 a 中打开相关文件水平分割。
将活动窗口发送到屏幕的左侧或右侧
然后将其更改为垂直分割,然后通过执行Ctrl-w 然后 L (活动窗口在左侧)
或
Ctrl-w 然后 R (活动窗口在右侧)
请注意左/右的最终击键必须是大写。其他的应该小写
If we're playing Vim Golf, I think the winning solution is to do:
Ctrl-w then f
to open the relevant file in a horizontal split.
Then change it to a vertical split, send then active window to the left or right side of the screen by doing either
Ctrl-w then L (active window to the left)
or
Ctrl-w then R (active window to the right)
Note that the final keystroke for left / right must be uppercase. The others should be lowercase