Vim for development


In this article I will educate you on how to go about setting vim for your software development. Vim is or was one of the popular editors used by many top C or Linux developers to have translated to the popular softwares that one is using today. Be it Linux, git, you name it. Although not limited to C language, it can be it extendeded to other langauges too. However in this post I will show for the C language and you can try similar for other languages.
Include file navigation
First, one need to navigate to the include files in say like
#include <linux/module.h>
Place the cursor between <> and press gf
to go to the file and Ctrl + O
to come back. If this is not working, you may have to add the include dir to the path like this
:set path+=/path/to/dir
This will append a new include path, but what if you don't need some path to be included? First check existing paths using :checkpath
, may be you realized that you do not need /usr/bin/include
now and only path is needed to be included. In that case one can do.
:set path=/path/to/dir
withuot the +
sign.
Method or symbol navigation
Important feature for any editor is to be able to navigate a method call or a symbol. This can be done via Ctrl+]
to go to the method and Ctrl+O
to come back.
For this all to work one may have to have ctags
or the latest exuberant-tags
installed and setup. One can install the later by following their distribution specific instructions. Once installed, navigate to the source directory and do below.
ctags --recurse=yes --exclude=.git --exclude=BUILD --exclude=.svn --exclude=vendor/* --exclude=node_modules/* --exclude=db/* --exclude=log/
which will generate a tags
file which is used by vim when it is launched. Now the navigation on a method should work provided the call method exists in that source directory.
What if the include directory is in some other path like for linux/module.h
.
In that case one needs to navigate to that directory and generate the tags
file like we just did. Afer that, that tags file needs to be updated within vim like below.
:set tags+=/path/to/include/dir
This way any number of tags file can be updated and their declared methods or symbol can be easily navigated.
Ctrl+t
can be used to access method definitions and :tag method_name
to navigate the method can be used as well.