Vim Tips Wiki
Advertisement

Duplicate tip

This tip is very similar to the following:

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

Tip 311 Printable Monobook Previous Next

created August 13, 2002 · complexity basic · author Thomas R. Kimpton · version 5.7


Occasionally, on Windows, I have files open in gvim, that the folder for that file is not open. This key map opens the folder that contains the currently open file. The expand() is so that we don't try to open the folder of an anonymous buffer, we would get an explorer error dialog in that case.

if has("gui_running")
  if has("win32")
    " Open the folder containing the currently open file. Double <CR> at end
    " is so you don't have to hit return after command. Double quotes are
    " not necessary in the 'explorer.exe %:p:h' section.
    :map <silent> <C-F5> :if expand("%:p:h") != ""<CR>:!start explorer.exe %:p:h<CR>:endif<CR><CR>
  endif
endif

Comments

Why have it inside a gui_running block? (Does it make a difference?)


If you prefer to use full Explorer windows (with folder pane etc), modify as follows:

!start explorer.exe %:p:h,/e<CR>:endif<CR><CR>

Notice you can simply do

 :e %:p:h

or

 :new %:p:h

to open directory containing current file in current/a new buffer

Advertisement