History Report a problem
Article Edit this page Discussion

Open the directory for the current file in Windows

From Vim Tips Wiki

Jump to: navigation, search
 

[edit] Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 493Previous TipNext Tip

Created: June 24, 2003 Complexity: basic Author: Adam Wolff Minimum version: 6.0 Karma: 29/16 Imported from: Tip#493


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.

[edit] References

[edit] 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")
      !open %:p:h
    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"?


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Terminator Wiki
Legend of Zelda Wiki
Flash Gordon
Everquest II Wiki
Yo-Yo Wiki
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for featured Wikia!

Send this article to a friend
"Open the directory for the current file in Windows"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation