Let's say I am in my home directory. I open a file that is present in some deep nested directory structure:
vim /some/really/long/path/file.txt
Now, within vim, I want to start a vertical split with another file from that same long location (but I don't want to change the current directory to that path, I still want to be in the home directory).
A layman (like me) will do something like:
:vsp /some/really/long/path/file2.txt
But I want to find out from all you VIM geniuses out there, is there an easier way to do this?
On the same note, if I had multiple files already open residing in different paths, can VIM automatically assign some sort of internal variables to all the locations? And then when I want to start a new VSP or SP with one of the files from one of those locations, I simply use those internal variables?
Try this:
:vs %:p:h/otherfile
as %:p:h
gives you the path of the current file.
See :help %:p
for more info.
Edit another file in the same directory:
:vs %<Tab><C-w><C-w><C-w>file2<Tab>
With a mapping:
nnoremap <key> :vs <C-R>=expand('%:p:h')<CR>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With