Vim logo vim online Vim Book Ad

basic Tip #311: Open the folder containing the currently open file

 tip karma   Rating 13/7, Viewed by 761 

created:   August 13, 2002 16:40      complexity:   basic
author:   Thomas R. Kimpton      as of Vim:   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

Tom.

 rate this tip  Life Changing Helpful Unfulfilling 

<<showing ascii value of the current character in decimal, hex, and octal | Copy, Cut, and Paste >>

Additional Notes

Anonymous, August 14, 2002 7:46
Why have it inside a gui_running block?  (Does it make a difference?)
[email protected], August 21, 2002 2:28
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>
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo