1

I very often need to open files through vsplit/split. Very often I want to open files in the same directory. Still, I must pass their paths to vsplit/split.

:vsplit @/siblingfile.txt

@ is an alias equal to the path of the current file (that exists only in my imagination of course but you got the idea :) ).

Is this possible?

UPDATE

--> vim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Nov 24 2016 16:00:18)

:echo has('cmdline_compl') displays 1

  • 1
    Not what you're asking for, but related: :Vex and :Sex – Rich Aug 24 '17 at 13:42
  • As long as autocomplete does not work for me with %:h/, your solution is faster thx – smarber Aug 24 '17 at 14:08
2

You're looking for %:h/

NB: you can tab-complete at any point after the :h.

  • thanks, but the autocomplete does not work at all, neither does CTRL-d – smarber Aug 23 '17 at 15:22
  • 1
    You'll need to make sure your version of vim supports command-line expansion (:echo has('cmdline_compl') shall display 1). See :h cmdline-completion regarding the various options vim looks at. – Luc Hermitte Aug 23 '17 at 16:42
2

As Luc indicated, you can type: :vsplit %:h then <Tab>.


I use this mapping to transform %% into the current directory from the command line:

cnoremap <expr> %% getcmdtype() ==# ':' ? fnameescape(expand('%:h')) . '/' : '%%'

Usage: :e %%

  • :help c_% (% replaced with the current file name)
  • :help %:h (%:h to get the head of the file name, aka last part removed)
  • Thanks, but the autocomplete does not work at all, neither does CTRL-d – smarber Aug 23 '17 at 15:37
  • 2
    Try :set nocompatible but compatibility mode should already be disabled if you use a vimrc file. – LEI Aug 23 '17 at 15:47
  • Still not work :/ – smarber Aug 23 '17 at 16:03
  • 2
    Strange, should be the fix if you see ^I when pressing <Tab>. You don't even need auto completion, just :e %:h and enter to open the current directory. – LEI Aug 23 '17 at 16:09
  • pressing <Tab> has no effect and <CTRL-D>-d supposed to show the content of a directory does as if there is nothing – smarber Aug 24 '17 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.