Vim open file under cursor

Posted by ereOn on Stack Overflow See other posts from Stack Overflow or by ereOn
Published on 2010-05-17T10:06:09Z Indexed on 2010/05/17 10:10 UTC
Read the original article Hit count: 253

Filed under:

Hi,

Let's 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 at the root directory. So when I want to load a.hpp I do :

:tabnew include/library/a.hpp

or:

:tabnew **/a.hpp

I'd like to map <F4> to open the file under the cursor in a new tab, using a recursive search.

I tried the following mapping command:

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

But obviously, this can't work, as it tries to open the file "/expand(" instead.

Any clue on how I could do that ?

Thanks.

© Stack Overflow or respective owner

Related posts about vim