Wikia

Vim Tips Wiki

Changes: Open the folder containing the currently open file

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 18: Line 18:
 
if has("gui_running")
 
if has("gui_running")
 
if has("win32")
 
if has("win32")
" Open the folder containing the currently open file. Double <CR> at end
+
" 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
 
" is so you don't have to hit return after command. Double quotes are
 
" not necessary in the 'explorer.exe %:p:h' section.
 
" not necessary in the 'explorer.exe %:p:h' section.
:map &lt;silent&gt; &lt;C-F5&gt; :if expand("%:p:h") != ""&lt;CR&gt;:!start explorer.exe %:p:h&lt;CR&gt;:endif&lt;CR&gt;&lt;CR&gt;
+
:map <silent> <C-F5> :if expand("%:p:h") != ""<CR>:!start explorer.exe %:p:h<CR>:endif<CR><CR>
 
endif
 
endif
 
endif
 
endif
Line 32: Line 32:
 
If you prefer to use full Explorer windows (with folder pane etc), modify as follows:
 
If you prefer to use full Explorer windows (with folder pane etc), modify as follows:
   
!start explorer.exe %:p:h,/e&lt;CR&gt;:endif&lt;CR&gt;&lt;CR&gt;
+
!start explorer.exe %:p:h,/e<CR>:endif<CR><CR>
   
 
----
 
----

Latest revision as of 05:34, September 29, 2008

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

CommentsEdit

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>

Around Wikia's network

Random Wiki