Vim 和 Ctags 提示和技巧
我刚刚使用我的 Vim(或者更确切地说 gVim)安装了 Ctags (以帮助 C++ 开发),并想找出您最喜欢的命令、宏、快捷方式、与之相关的提示...
分享您最好的武器库。 您会推荐哪些其他 Vim 插件用于 Vim 上的 C++ 开发?
编辑您还会将哪些其他附加组件与 Ctags 结合使用?
EDIT2 您使用标签的 gVim 版本是什么? 这有什么不同吗?
EDIT3 您如何增强大型和小型项目的编程经验?
I have just installed Ctags (to help with C++ development) with my Vim (or rather gVim), and would like to find out your favorite commands, macros, shortcuts, tips that go along with it...
Share your best arsenal. What other Vim add-ons you would recommend for C++ on Vim development?
EDIT What other add-on you would use in conjunction with Ctags?
EDIT2 What version of gVim you use with tags? Does it make a difference?
EDIT3 How do you enhance your programming experience for both big and small projects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
我改编了上面的 SetTags() 搜索函数(应将其替换为等效的
settags+=./tags;/
)以适用于 cscope。 似乎有效!I adapted the SetTags() search function above (which should be replaced by the equivalent
set tags+=./tags;/
) to work for cscope. Seems to work!上面 SetCscope() 函数的另一个迭代。 这将设置 cscope 预路径来获取匹配项,而无需位于“cscope.out”所在的目录上:
Another iteration on the SetCscope() function above. That sets cscope pre-path to get matches without being on the dir where "cscope.out" is:
Ctrl+] - 转到定义
Ctrl+T - 从定义跳回。
Ctrl+W Ctrl+] - 以水平分割打开定义
在 vimrc 中添加这些行
地图> :tab split:exec("tag ".expand(""))
地图:vsp:exec("tag ".expand(""))
Ctrl+\ - 打开新选项卡中的定义
以垂直分割方式打开定义
Alt+] -生成标签后 。 您可以使用以下键标记进入和标记出函数:
Ctrl+
鼠标左键单击
- 转到定义Ctrl+
鼠标右键单击
- 从定义跳回Ctrl+] - go to definition
Ctrl+T - Jump back from the definition.
Ctrl+W Ctrl+] - Open the definition in a horizontal split
Add these lines in vimrc
map <C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
Ctrl+\ - Open the definition in a new tab
Alt+] - Open the definition in a vertical split
After the tags are generated. You can use the following keys to tag into and tag out of functions:
Ctrl+
Left MouseClick
- Go to definitionCtrl+
Right MouseClick
- Jump back from definition我的 .vimrc 中总是有一行:
这将在当前目录中查找“标签”,并沿着树向根方向向上移动,直到找到一个。 IOW,您可以位于源树中的任何位置,而不仅仅是它的根。
One line that always goes in my .vimrc:
This will look in the current directory for "tags", and work up the tree towards root until one is found. IOW, you can be anywhere in your source tree instead of just the root of it.
另一个有用的 C 开发插件是 cscope
正如 Ctags 让您跳转到定义一样,Cscope 跳转到调用函数。
如果 ~/bin/ 目录中有 cscope,请将以下内容添加到 .vimrc 并使用 g^] 转到调用函数(请参阅 :help cscope)。
差点忘了...就像 ctags - 您必须生成(并定期更新)数据库。 我使用以下脚本
,其中“select_files”是另一个从 Makefile 中提取 C 和头文件列表的脚本。 这样我只索引项目实际使用的文件。
Another useful plugin for C development is cscope
Just as Ctags lets you jump to definitions, Cscope jumps to the calling functions.
If you have cscope in your ~/bin/ directory, add the following to your .vimrc and use g^] to go to the calling function (see :help cscope).
Almost forgot... Just as ctags - you have to generate (and periodically update) the database. I use the following script
Where 'select_files' is another script that extracts the list of C and header files from the Makefile. This way I index only the files actually used by the project.
您可以将目录添加到 ctags 查找中。 例如,我有一个为 Qt4 构建的 ctags 索引,并将其放在我的 .vimrc 中:
You can add directories to your ctags lookup. For example, I have a ctags index built for Qt4, and have this in my .vimrc:
以上所有内容以及...
code_complete :函数参数完整、代码片段等等。
taglist.vim :源代码浏览器(支持 C/C++、java、perl、python、tcl、sql、php 等)
All of the above and...
code_complete : function parameter complete, code snippets, and much more.
taglist.vim : Source code browser (supports C/C++, java, perl, python, tcl, sql, php, etc)
我使用 ALT-left 和 ALT-right 从标签堆栈弹出/推送到标签堆栈。
如果您使用
hjkl
进行移动,则可以改为映射
和
。I use ALT-left and ALT-right to pop/push from/to the tag stack.
If you use
hjkl
for movement you can map<M-h>
and<M-l>
instead.同名的多个定义
g
以拆分方式打开定义,但也执行:tjump
它要么转到定义,要么如果有多个定义,则显示一个定义列表供您选择。Several definitions of the same name
<C-w>g<C-]>
open the definition in a split, but also do:tjump
which either goes to the definition or, if there are several definitions, presents you with a list of definitions to choose from.我最常用的命令是 C-],它跳转到光标下函数的定义。 您可以更频繁地使用它来关注更多来电。 之后,Co 会将您带回一级,Ci 会再次深入。
The command I am using most is C-] which jumps to the definition of the function under the cursor. You can use it more often to follow more calls. After that, C-o will bring you back one level, C-i goes deeper again.
我发现 taglist 插件是必备的。 它在单独的窗口中列出了它知道的所有标签(您已打开的文件),并且可以非常轻松地导航较大的文件。
我主要将它用于 Python 开发,但对于 C/C++ 来说它只会更好。
I've found the taglist plug-in a must-have. It lists all tags that it knows about (files that you have opened) in a seperate window and makes it very easy to navigate larger files.
I use it mostly for Python development, but it can only be better for C/C++.
我已将标签操作封装在 实验插件< /a> 我的。
关于vim中的C++开发,我已经回答了那里 :我使用自己的套件和一些其他插件。
I've encapsulated tags manipulation in an experimental plugin of mine.
Regarding C++ development in vim, I've already answered there: I use my own suite, and a few other plugins.
两年来我一直在调整我的 vim 插件来支持足够大的 c++ 项目。 你可以看看它们。
他们使用 ctags 和 cscsope。
http://www.vim.org/scripts/script.php?script_id= 1638
http://www.vim.org/scripts/script.php?script_id=第2507章
I've been adapting my vim plugins for two years to support big enough c++ project. You can take a look at them.
They use ctags and cscsope.
http://www.vim.org/scripts/script.php?script_id=1638
http://www.vim.org/scripts/script.php?script_id=2507
我将以下内容放入我的 .gvimrc 文件中,该文件在 gvim 启动时从任意点搜索树中的标签文件:
然后,我使用如下脚本定期在源树顶部重新生成标签文件:
I put the following in my .gvimrc file, which searches up the tree from any point for a tags file when gvim starts:
I then periodically regenerate a tags file at the top of my source tree with a script that looks like:
我在macos中使用vim,原来的ctags不能很好地工作,所以我下载最新的并配置make make install它。
我将 ctgas 安装在 /usr/local/bin/ctags 中(以保留原始版本)
I use vim in macos, and the original ctags doesn't work well, so I download newest and configure make make install it.
I install ctgas in /usr/local/bin/ctags(to keep original one)