How can I do something like gf, but in a new vertical split?
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
Here is a solution involving 5 key strokes:
- Ctrl-wv
- gf
That is Ctrl-wv followed by gf in the normal mode.
Here is an equivalent solution that involves 7 key strokes:
:vs
- gf
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.
Here is possible mapping:
:nnoremap <F8> :vertical wincmd f<CR>
With a file name under cursor, hit F8 and voila.