Opening files in the same folder as the current file, in vim Opening files in the same folder as the current file, in vim unix unix

Opening files in the same folder as the current file, in vim


:Ex short for :Explore does exactly what you asked for.


I have the following three lines on my .vimrc:

map ,e :e <C-R>=expand("%:p:h") . "/" <CR>map ,t :tabe <C-R>=expand("%:p:h") . "/" <CR>map ,s :split <C-R>=expand("%:p:h") . "/" <CR>

Now ,e <some-file> opens on this buffer. ,t and ,s do the same but on a new tab/split window.


Newer versions of vim have a autochdir command built in, if not you can fall back to a BufEnter like setup.

" set vim to chdir for each fileif exists('+autochdir')    set autochdirelse    autocmd BufEnter * silent! lcd %:p:h:gs/ /\\ /endif