Learpcs
Learpcs

Reputation: 282

How to open a new file in a new window which is located in the other directory with vim?

I wanted to work with two files in a "split-mode" like this answer suggests. But one of them is located in different directory (in home) and the other somewhere in desktop folder. In my case, I have two these files (looking from home directory)

  1. .vimrc

  2. /Desktop/repos/my_vimrc/linux/.vimrc

I've tried to open .vimrc in home folder and then use command vert /Desktop/repos/my_vimrc/linux/.vimrc (which is not convenient option to write entire path to the file by my hands, but still I had to try something), and it seems like vim created a new file somewhere, since it opened an empty window and I don't even know where is this file supposed to be created. Is there a way to use vert command here?

Upvotes: 1

Views: 1279

Answers (1)

romainl
romainl

Reputation: 196546

Are you sure /Desktop/repos/my_vimrc/linux/.vimrc is the right path? It doesn't correspond to anything I am used to, either on Unix-like systems or on Windows.

Also, :help :vert doesn't really do anything on its own. It is a modifier for other commands that split the current window so you can't expect :vert /path/to/file to do anything useful. I would expect it to throw an error, actually.

  • The proper command for opening a file in a vertical window is :help :vsplit:

    :vs /path/to/file
    
  • You can tab-complete the path:

    :vs /p<Tab>
    

    See :help cmdline-completion.

  • You can combine tab-completion with * and ** as well:

    :vs /p*/**/file<Tab>
    

Upvotes: 1

Related Questions