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.
Written by Greg Osuri
Related protips
2 Responses
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Vim
Authors
Related Tags
#vim
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#