开发者

Vim open file under cursor [duplicate]

开发者 https://www.devze.com 2022-12-31 02:08 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: Open file from complete path under cursor in Vim
This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Open file from complete path under cursor in Vim

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 cu开发者_JAVA百科rsor 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.


:help gf gives a hint at how to accomplish this.

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

It seems <cfile> is automatically expanded in mappings.

0

精彩评论

暂无评论...
验证码 换一张
取 消