1. Vim Introduction
In the previous chapters, we used the VI command many times, and Vim and VI were actually the same commands, using the same.
Here's a look at Vim,
For example, use the command vi/etc/passwd, enter, see the contents are black and white, no color.
Direct input ": Q", enter, you can exit the interface.
Use the VIM command to see the colors, but before you do this, you need to install VIM, enter the command yum install-y vim-enhanced, and go to the installation.
After the installation is complete, enter the command vim/etc/passwd, return, enter,
As you can see, the color is very obvious. Notice this way, do not edit this file, do not change the content. After the change, the system boot will be affected, because this file is a user file, very critical.
Vim is divided into three different modes:
General mode, is not yet into the editing mode, you can do some operations;
Edit mode, press the letter "I" to enter the editor;
Command mode, which can be searched, can be used to find replacements, including saving exits.
2. Vim color display and move cursor
Using the command vim/etc/passwd above, you can see the color content. Now move the file passwd from directory/etc to the directory/TMP, then use the command to view, see,
You can see that the color is gone, which means that the same file is in a different directory and may cause the color to not exist. In the Cent OS,/etc The file is often a configuration file, in/etc will be displayed under the color, placed in other directories will not display color. And then enter the command vim/etc/fstab, enter, select Read-only mode to open, you can see the color, see,
Similarly, to the file fstab to move a place, enter the command cp/etc/fstab/tmp/, carriage return, and then enter the command vim/tmp/fstab, carriage return, the display interface is the same, with color. This is because the file fstab preceded by a line that begins with "#".
Next do an experiment, the/tmp passwd file to make a change, the cursor to the first line, and then Shift + O, the cursor will go up a line, and enter the editing mode, see,
At this point, enter # in the above, add a little bit of content in the back, write two lines, see,
Exit after saving, then use command vim/tmp/passwd to enter, see,
You can see, there are colors, but only in one or two lines, in the middle also use # beginning to edit the content, you will see the color, see,
The above indicates that the file itself is not without color, but the contents of the file itself does not have the condition to display color. Then do the experiment, enter the command mv/tmp/passwd/tmp/passwd.sh, change the name of the file, and then enter the command vim/tmp/passwd.sh, see,
As you can see, there are now colors, indicating that the color display is not only related to the contents of the first line, but also to the name of the file.
In short, vim shows a lot of color conditions, and the final result is not quite the same. This doesn't have to be too tangled. When you edit a file, Vim displays the color, and the color is often related to the contents and file name of the document itself.
VIM has its own configuration file, under/ETC/VIMRC, Input command VIM/ETC/VIMRC, enter, see,
Inside is some control of the use of vim content, more complex, to make an understanding on it.
In your user's add-on directory, you can edit vimrc this file, enter the command VIM/ROOT/.VIMRC. , enter, see,
Default this file does not exist, when we encounter vim some more advanced usage, you can try to search some documents, in this file configuration can be.
First copy the file, enter the command cp/etc/dnsmasq.conf/tmp/1.txt, then enter the command vim/tmp/1.txt, enter the editor,
You can see that this file does not have a color display, because the filename is called 1.txt, as long as the file name is a. txt suffix, the color is not displayed. Want to make this file display color can also, change the file name, enter the command mv/tmp/1.txt/tmp/xxx.conf, and then enter the command Vim!$, enter, see,
You can see that the content color is displayed in blue. Edit the content, but also can see the different color changes, here is not much to explain, make a understand can.
Vim Introduction and color display