There are many ways to do this, as listed in vim wiki.
I tried the script way (a.vim, but not feel comfortable. Because:
- I'm doing kernel development, so I have a bunch of my own
stdio.h
,stdlib.h
, etc. Buta.vim
will bring you into the system include path, not my own - Even though I jumped to the right space, jump back is not easy
Finally, I found the ctags way very usable. Issue this command in your source tree root,
$ ctags --extra=+f -R .
Then in vim, you can just type :tag header.h
to jump to header.h
and use your
familiar ctrl+t
to jump back, very intuitive. Plus, I found a gf
command of vim
that can jump to the file under cursor, but with the same drawbacks as a.vim
,
thus not adorable.
UPDATE
Here is a Vim Wiki talking about how to jump back and forth using {%key Ctrl %}-I and {%key Ctrl %}-O, which is kind of sweet. Thanks @Partha Bera for point that out.