vim (Vi IMproved) editor
Introduction to vim
vim stands for Vi IMproved. vim editor is an advanced (enhanced) version of default vi editor in linux. It is very useful for the programmers. The improvements in vim editor can be clearly seen in the handling of tags and writing of programs.
Default it is not installed in the linux system, you have to download it from the internet using the following command in linux terminal.
How to install & open?
To install vim, run following command with sudo.
$ sudo apt-get install vim
Once, vim installed successfully, you can use it.
You can get information about the vim editor by typing vim command.
To open/create file in vim, just type the $ vim file-name and hit enter.
The vim editor will open; see the following snap shot (it is the screen shot of vim editor).
commands that can make vim very useful to you
||Indent all file contents
When you want to indent all your source code in a proper indent, just press gg=G (small g, small g, equal and capital G).
||Indent current block
Bring the cursor at the starting braces of code and press % (shift + 5). Current block’s code will be indented in a proper format.
||switch into visual mode
This command convert vim, from text to GUI (visual) mode, where you can easily edit file’s contents. If you want to copy and paste, you can select the lines (that you want to copy) and press y to copy and press p to paste copied lines at the current cursor location.
This command allows you to edit in files in diff mode, here you can compare and edit more than one files.
$ vimdiff file1 file2