Vim Tips Wiki
(Move categories to tip template)
(Removed 'I ' character that was added on accident)
 
(2 intermediate revisions by 2 users not shown)
Line 15: Line 15:
 
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:
 
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>
+
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.
 
So that typing ctrl-e in any buffer opens the folder that the file lives in in Windows.
Line 25: Line 25:
 
I changed it to this:
 
I changed it to this:
   
map &lt;C-e&gt; :!start explorer %:p:h:gs?\/?\\\\\\?&lt;CR&gt;
+
map <C-e> :!start explorer %:p:h:gs?\/?\\\\\\?<CR>
   
 
This stops the console window from flashing up on the screen. See {{help|:!start}}.
 
This stops the console window from flashing up on the screen. See {{help|:!start}}.
Line 34: Line 34:
   
 
It is an X-based file explorer, similar to Windows explorer. I had to modify the mapping to:
 
It is an X-based file explorer, similar to Windows explorer. I had to modify the mapping to:
map &lt;C-e&gt; :silent !worker %:p:h&lt;CR&gt;
+
map <C-e> :silent !worker %:p:h<CR>
   
 
----
 
----
Line 43: Line 43:
 
if has("gui_running")
 
if has("gui_running")
 
if has("win32")
 
if has("win32")
let s:stored_shellslash = &amp;shellslash
+
let s:stored_shellslash = &shellslash
 
set noshellslash
 
set noshellslash
 
!start explorer.exe %:p:h
 
!start explorer.exe %:p:h
let &amp;shellslash = s:stored_shellslash
+
let &shellslash = s:stored_shellslash
 
elseif has("gui_kde")
 
elseif has("gui_kde")
!konqueror %:p:h &amp;
+
!konqueror %:p:h &
 
elseif has("gui_gtk") " TODO: test!
 
elseif has("gui_gtk") " TODO: test!
!nautilus %:p:h &amp;
+
!nautilus %:p:h &
elseif has("mac") &amp;&amp; has("unix")
+
elseif has("mac") && has("unix")
!open %:p:h
+
let s:macpath = expand("%:p:h")
  +
let s:macpath = substitute(s:macpath," ","\\\\ ","g")
  +
execute '!open ' .s:macpath
 
endif
 
endif
 
endif
 
endif

Latest revision as of 16:44, 7 May 2013

Duplicate tip

This tip is very similar to the following:

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

Tip 493 Printable Monobook Previous Next

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"?