Last Updated: February 25, 2016
·
1.254K
· kn0tch

Open files in the directory of current file in vim

Tiny vim hack I've been using that proved to be extremely helpful to open files in the directory of current file, place the below in your .vimrc

cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
map <leader>v :view %%

%% will now provide you the name of the current directory.

2 Responses
Add your response

The first line is a bit useless since you're just shortening :e %:h to :e %% You're doing a lot of work to just save one letter. You can just do map <leader>e :e %:h<CR> Personally I have it opening in a new tab

over 1 year ago ·

@shawncplus Probably should've mentioned more use cases, I currently use %% for several other things like clearing my CtrlP caches.

map <leader>F :CtrlPClearAllCaches<cr>\|:CtrlP %%<cr>

But I agree it is redundant in the case :-)

over 1 year ago ·