Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: How to open new vertical split for file under cursor

I know gf opens the file under cursor, and CTRL-w f opens the file under cursor in a new split window.

I'm probably being greedy but, how do you open it in a new vertical window?

like image 888
Dunctem Avatar asked Jul 14 '17 19:07

Dunctem


1 Answers

From normal mode, you could type C-w f C-w L or C-w v gf, and from the command-line you could execute :wincmd f | wincmd L or :vert wincmd f.

They are not strictly equivalent, though.

With C-w f C-w L and :wincmd f | wincmd L, the height of your vertical viewport will be maximized no matter the current layout. So, for example, if you have a horizontal viewport below, its width should be decreased:

        +-----------------+     +--------+-------+
        |  path/to/fileC  |     |        |       |
        |                 |  →  |        |       |
        |      fileA      |     |  fileA | fileC |
        +-----------------+     +--------+       |
        |                 |     |        |       |
        |      fileB      |     |  fileB |       |
        +-----------------+     +--------+-------+

With C-w v gf and :vert wincmd f, the height of your vertical viewport should be the same as the current one, and thus it shouldn't affect the horizontal viewport below:

        +-----------------+     +--------+-------+
        |  path/to/fileC  |     |        |       |
        |                 |  →  |        |       |
        |      fileA      |     |  fileA | fileC |
        +-----------------+     +--------+-------+
        |                 |     |                |
        |      fileB      |     |      fileB     |
        +-----------------+     +----------------+
like image 159
user852573 Avatar answered Sep 21 '22 14:09

user852573