Skip to content

Comment on Vim Splits – Move Faster and More Naturallyparent

Comments

Isn't there some way of using % to open a file relative to the current one perhaps? To get the best of both worlds.

I'm using the following to expand "%%" in command mode to the full path of the current open file's directory:

  cabbr <expr> %% expand('%:p:h')
You could also use :. instead of :p to get the relative path, see :help c_% and :help filename_modifiers

Wow, elegant. Thank you!

I use:

    map <leader>e :e <C-r>=expand("%:p:h") . "/" <cr>
you can make one that splits:
    map <leader>v :vs <C-r>=expand("%:p:h") . "/" <cr>
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.