Vim Tips Wiki
No edit summary
 
(Removed 'I ' character that was added on accident)
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
{{Duplicate|311|1336}}
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=493
 
|id=493
  +
|previous=492
|title=Open the directory for the current file in Windows
 
  +
|next=494
|created=June 24, 2003 9:10
+
|created=June 24, 2003
 
|complexity=basic
 
|complexity=basic
 
|author=Adam Wolff
 
|author=Adam Wolff
 
|version=6.0
 
|version=6.0
 
|rating=29/16
 
|rating=29/16
  +
|category1=
|text=
 
  +
|category2=
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.
 
 
 
 
See [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:filename-modifiers}} :help filename-modifiers] for more.
 
 
}}
 
}}
 
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>
== Comments ==
 
Good tip, I changed it to this:
 
   
 
So that typing ctrl-e in any buffer opens the folder that the file lives in in Windows.
map &lt;C-e&gt; :!start explorer %:p:h:gs?\/?\\\\\\?&lt;CR&gt;
 
   
  +
==References==
This stops the console window from flashing up on the screen. See [http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:!start}} :help !start]
 
  +
*{{help|filename-modifiers}}
 
Rog
 
 
rpilkey at magma.ca
 
, June 24, 2003 9:42
 
----
 
Very good!
 
 
I call instead the windows explorer the explorer plugin with:
 
 
map &lt;C-e&gt; :Exp %:p:h:gs?\/?\\\\\\?&lt;CR&gt;
 
 
But this works only on Windows. Anybody knows how it should looks for unix?
 
   
 
==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}}.
   
'''Anonymous'''
 
, June 24, 2003 12:59
 
 
----
 
----
 
On Unix, try using a free program called Worker:
 
Well, I found I can reuse iexplore.exe, as in the following:
 
 
map &lt;silent&gt; &lt;C-E&gt; :sil!!start C:/PROGRA~1/INTERN~1/iexplore -nohome -e &lt;C-R&gt;=getcwd()&lt;CR&gt;&lt;CR&gt;
 
 
If cygwin is installed, we can have a simple one:
 
 
map &lt;silent&gt; &lt;C-E&gt; :sil!r!cygstart -x .&lt;CR&gt;
 
 
 
 
 
maxiangjiang--AT--hotmail.com
 
, June 24, 2003 15:10
 
----
 
On Unix, try using a free program called Worker:
 
 
http://www.boomerangsworld.de/worker/woverview.php3?lang=en
 
http://www.boomerangsworld.de/worker/woverview.php3?lang=en
   
It is an X-based file explorer, similar to Windows explorer.
+
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>
I had to modify the mapping to:
 
map &lt;C-e&gt; :silent !worker %:p:h&lt;CR&gt;
 
   
randydefauw--AT--yahoo.com
 
, June 24, 2003 15:12
 
 
----
 
----
For quite a while now I've been doing it this way:
+
For quite a while now I've been doing it this way:
   
  +
<pre>
func! OpenCWD()
+
func! OpenCWD()
if has("gui_running")
 
if has("win32")
+
if has("gui_running")
  +
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")
endif
 
  +
let s:macpath = substitute(s:macpath," ","\\\\ ","g")
endif
 
  +
execute '!open ' .s:macpath
endfunc
 
  +
endif
  +
endif
 
endfunc
 
command! OpenCWD call OpenCWD() " or whatever you like
  +
</pre>
   
 
I'm not sure how flawless it is, but it has worked for me on a couple of different platforms.
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.
 
 
 
nlm--AT--valtech.se
 
, June 26, 2003 7:14
 
 
----
 
----
 
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.
 
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.
   
radbelt_res--AT--yahoo.com
 
, June 26, 2003 19:07
 
 
----
 
----
Since I perfer to stay within Vim, I use the following:
+
Since I prefer to stay within Vim, I use the following:
:sf %:p:h
+
: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.
 
   
  +
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.
   
sgovindachar at yahoo
 
, June 27, 2003 8:38
 
 
----
 
----
How is this different from ":Sexplore" or the shorter ":Sex"?
+
How is this different from ":Sexplore" or the shorter ":Sex"?
 
   
'''Anonymous'''
 
, June 4, 2005 19:26
 
 
----
 
----
<!-- parsed by vimtips.py in 0.465740 seconds-->
 

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