We can configure Vim to use it as an IDE. In this section, we will discuss following items
Syntax highlighting is one of the important features of IDE. To enable syntax highlighting use −
:syntax on
For instance, below image show syntax highlighting for C code −
To disable syntax highlighting use −
:syntax off
When syntax highlighting is disabled, it will show following output −
To perform auto and smart indentation use following commands −
: set autoindent : set smartindent
In addition to this you can use below command to auto-indent C code −
: set cindent
If you are using programming language which uses curly braces to combine multiple statements then % key will be your friend. This key will jump between start and end of curly braces quickly.
For instance, you are at line 11 and execute % command then it will move cursor the line 4. Below image shows this −
To execute single command from Vim editor user −
:!<command>
For instance, to execute pwd command use following syntax −
:!pwd
However, if you want to multiple shell commands then execute following command −
:shell
Above command will give you terminal access, where you can execute multiple commands. Once you are done with it, just type exit command which will return back to Vim session.
Combination of ctags and csope provides many useful features like go to function definition, go to function declaration, find function calls, search file, and many more. Perform below steps to configure these tool −
$ ctags <file>
This command will generate new file namely tags
:set tags = tag
To install and configure cscope perform following steps −
$ sudo apt-get install cscope
$ cscope –R
We can use following commands for auto-completion −
Sr.No | Command & Description |
---|---|
1 | Ctrl + x Ctrl + N
Word completion |
2 | Ctrl + x Ctrl + L
Line completion |
3 | Ctrl + x Ctrl + F
File name completion |
Note that we have to use these commands in insert mode.