How to install rtags for vim in Ubuntu 18.04
How to install rtags for vim in Ubuntu 18.04 / 如何在 Ubuntu 18.04 vim 上安装 rtags 插件
This blog introduces how to install the best cross-reference tool, rtags, that I have ever used in vim, step by step. I hope it helps.
What’s rtags
Rtags is a client/server application that indexes C/C++ code and keeps a persistent file-based database of references, declarations, definitions, symbolnames etc. It allows you to find symbols by name (including nested class and namespace scope). Most importantly, it gives you proper follow-symbol and find-references support.
Rtags comes with emacs support but there are projects supporting other IDEs: vim-rtags and sublime-rtags.
In this blog, We would install vim-rtags later.
How to install rtags
First, you need clang, which is a compiler front end for the C, C++, Objective-C and so on. It uses the LLVM compiler infrastructure as its back end and has been part of the LLVM release cycle since LLVM 2.6.
1 | // Commands in Ubuntu terminal |
Secondly, make and install rtags as follows.
1 | // Commands in Ubuntu terminal |
Thirdly, you should install vim-rtags in Vundle.vim. I think it’s the easiest way to install rtags plugin in vim.
You need to add the following line to .vimrc if you have installed Vundle, and then run :PluginInstall in vim.
1 | Plugin 'lyuts/vim-rtags' <-- install in vim |
Finally, the last but essential step is that forcing cmake to output compile_commands.json (like DCMAKE_EXPORT_COMPILE_COMMANDS) and link it with rtags according to your project.
1 | cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 [***] your_src_path |