wj7gmq
Last Updated: February 25, 2016
·
777
· kn0tch
9c6165b107059ea5dfa2e81985fe8272

Open files in the directory of current file in vim

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.

Say Thanks
Respond

2 Responses
Add your response

6874
D54f65ad3ff9ee1c9c033a403d4b5f9f

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 ·
6875
9c6165b107059ea5dfa2e81985fe8272

@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 ·
Filed Under