Vim open file under cursor

Possible duplicate:
Open the file from the full path under the cursor in Vim

Say I have the following file tree:

/ include/ library/ a.hpp b.hpp src/ a.cpp b.cpp 

And the following /src/a.cpp file:

 #include "a.hpp" #include "b.hpp" 

I always open Vim in the root directory. So when I want to download a.hpp , I do:

 :tabnew include/library/a.hpp 

or

 :tabnew **/a.hpp 

I would like to display <F4> to open the file under the cursor in a new tab using a recursive search.

I tried the following display command:

 :map <F4> :tabnew **/expand("<cfile>")<cr> 

But obviously this will not work, because instead it tries to open the file "/expand(" .

Any clue to how I can do this?

Thanks.

+7
vim
source share
1 answer

:help gf gives a hint on how to do this.

:nmap <F4> :tabe **/<cfile><cr>

<cfile> automatically expand in mappings.

+3
source share

All Articles