问题
I am currently using emacs where someone had already setup the configurations, but because I like vim better, I wanted to do the same in vim. In emacs when a user enters a shortcut, emacs opens a new split and shows the data related to that function in the new split, which is under the cursor in the former file. All subsequent info is shown in the same split window.
I wanted to do the same in vim. When I take the cursor over a function name in a file, it should pull up the associated secondary file in a horizontal split and goto the line number where that function name appears with the associated data.
How can I start writing such a script? Is it possible using entirely vim scripts to do this? Do I need to write perl scripts on the side which can get me the line number? Where do I start learning this stuff?
回答1:
This is possible for various scenarios; it depends on what your “associated data” is. If it’s the documentation for the function, then see :h K
.
If you’ve generated ctags (:h ctags
, available for several languages), you can use tag-jumping (<C-]>
and <C-t>
). E.g., you can bounce between C source and header files.
Various plugins have their own means to bounce around associated files. See vim-rails for examples of many commands for jumping to associations between controllers, templates, models, etc.
The standard vim commands for jumping into split windows are described in :h windows
. You may be interested in :ptag
to see the tag in a preview window.
来源:https://stackoverflow.com/questions/31440046/vim-script-to-open-file-at-certain-line-number