Duplicate tip
This tip is very similar to the following:
These tips need to be merged – see the merge guidelines.
created June 24, 2003 · complexity basic · author Adam Wolff · version 6.0
It's often handy to open the folder that corresponds to a file I'm editing (as much as I hate to leave Vim!) I've added this mapping:
map <C-e> :silent !explorer %:p:h:gs?\/?\\\\\\?<CR>
So that typing ctrl-e in any buffer opens the folder that the file lives in in Windows.
References[]
Comments[]
I changed it to this:
map <C-e> :!start explorer %:p:h:gs?\/?\\\\\\?<CR>
This stops the console window from flashing up on the screen. See :help :!start.
On Unix, try using a free program called Worker: http://www.boomerangsworld.de/worker/woverview.php3?lang=en
It is an X-based file explorer, similar to Windows explorer. I had to modify the mapping to:
map <C-e> :silent !worker %:p:h<CR>
For quite a while now I've been doing it this way:
func! OpenCWD() if has("gui_running") if has("win32") let s:stored_shellslash = &shellslash set noshellslash !start explorer.exe %:p:h let &shellslash = s:stored_shellslash elseif has("gui_kde") !konqueror %:p:h & elseif has("gui_gtk") " TODO: test! !nautilus %:p:h & elseif has("mac") && has("unix") let s:macpath = expand("%:p:h") let s:macpath = substitute(s:macpath," ","\\\\ ","g") execute '!open ' .s:macpath endif endif endfunc command! OpenCWD call OpenCWD() " or whatever you like
I'm not sure how flawless it is, but it has worked for me on a couple of different platforms.
A solution that I like is to use the vi file manager (http://vifm.sourceforge.net). You can use it with or without being in vim (a vim plugin comes with the distribution). Unfortunately, I have not been able to get it to compile in cygwin on windows yet, and I am on a windows machine right now, so I can't access it to give more of the specifics. I think the plugin comes with a command like :Vifm, but, that could be mapped.
Since I prefer to stay within Vim, I use the following:
:sf %:p:h
This splits the window and lists the contents of the directory of the file. Putting the cursor on an item from the list in that window and typing o opens up a new window with the contents of the item.
How is this different from ":Sexplore" or the shorter ":Sex"?