Install and use under ubuntu

When improving the code under ubuntu, you will encounter situations where you want to jump to the function definition, or jump to other related files. At this time, you need to use the ctags tool
under Here, I will try my best to be as detailed as possible. Make it clear how to turn vim into source insight, however you still need to think positively and have to figure things out on your own.
In order to avoid being too wordy, I will put the basic part at the back. If you feel that it is too simple the more you read, then this article is not suitable for you; , don't worry, there will be some necessary knowledge introductions later.
First, make good use of the system's own software ctags
Most unix systems have ctags software, which can work well with vim.
Purpose:
Generate label files in c language to realize jumping between related c files.
usage:

Taking the creation of tags in the Linux kernel code linux-3.5 as an example, it is recommended to compile the linux-3.5 kernel code first, because after the ctags package is added, compiling or modifying the ctags environment will destroy the ctags environment, and you need to re-type ctags; the kernel code will not be compiled Jumping between codes can also be implemented normally.
In the main directory of the program project (the directory where you want to jump between codes), for example /home/kernel/linux-3.5/:

cd /home/kernel/linux-3.5

ctags -R

After running, a tags file will be generated in the /home/kernel/linux-3.5/ directory.
Set the tags package to global:
under Redhat system:

vim /etc/vimrc

Under Ubuntu system:

vim /etc/vim/vimrc

Add at the end of the vimrc file:

set tags+=/home/kernel/linux-3.5/tags

Note:
"+=" must be used and there must be no spaces on either side.
There is no need to restart the computer, just close and reopen the file that vim has opened, and you can realize the jump between the program code and the kernel code.

If you want to realize the jump between multiple program files written by yourself, or between functions in different places in a single file, you can also use ctags to achieve the same method as above, for example:
if the driver code you are writing is /home /helloworld/.

cd /home/helloworld

ctags -R

A tags file will be generated in the /home/helloworld/ directory.
Set the tags package to global:
under Redhat system:

vim /etc/vimrc

Under Ubuntu system:

vim /etc/vim/vimrc

Add at the end of the vimrc file:

set tags+=/home/helloworld/tags

There is also no need to restart the computer. You only need to close and reopen the file that vim has opened to realize the jump between the program code and the kernel code.
3. How to use

Ctrl + ]
Ctrl + o
Functions in program files in any directory in Linux environment, to jump to the kernel code for viewing, just move the vim cursor to the function name or macro definition name, use the shortcut key "Ctrl+ ]", you can jump to the function or macro definition in the kernel for viewing. When there are multiple paths to jump to, several lines of options will appear under vim, and you can directly enter the number and press Enter to perform the corresponding function or Macro definition selection; to return to the previous function or macro definition, just use the shortcut key "Ctrl+o" to jump to the last viewed function.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324774142&siteId=291194637