This command, which has been mentioned many times before, is a necessary tool in Linux. No amount of work can be done without it. Early UNIX was used as the system default editor for the VI. You may have doubts, what is the difference between VI and VIM? It is easy to understand that Vim is an upgraded version of VI. Many Linux system administrators are accustomed to VI, that is because they are in contact with Linux when the use of Vi,vim later is more popular. So, it doesn't matter with VI and vim, as long as you can achieve the purpose you want.
In Amin's view, the biggest difference between VI and VIM is that when editing a text, vi does not display color, and vim displays the color. Display colors are easier for users to edit. There's no difference in other features. So under Linux, the use of VI or VIM depends entirely on your personal interests. Amin has been using vim since the beginning of Linux, so it will be taught to you in the role of Vim. Maybe you just installed a CentOS system without this command, please install it like this yum install-y vim-enhancedvim three modes: General mode, edit mode, command mode. That's what you need to remember.
General mode:When you vim filename to edit a file, it is normal mode to enter the file. In this mode, you can do the following actions: Move the cursor up or down, delete a character, delete a row, copy, paste one line, or multiple lines.
Cp/etc/dnsmasq.conf/tmp/1.txt//Because the file line is much more suitable for us to do experimentsVim/tmp/1.txt
First copy a file to the/tmp/directory and rename it to 1.txt. Then use the Vim tool to edit it, press ENTER after entering the file 1.txt, this mode is the general mode. In this mode, we can move the position of the cursor, operation methods such as table in the general mode we can also implement the character or string copy, delete, paste and other operations
edit mode:In general mode, it is not possible to modify a character, only to edit mode. From normal mode into edit mode, you can just press a key (I, I, A, A, O, O, R, R). When you enter edit mode, the words "insert or replace" appear on the bottom line of the screen. To return to normal mode from edit mode, simply click the ESC key at the top left of the keyboard.
Command mode:In normal mode, enter ":" or "/" to enter the command mode. In this mode, you can search for a character or a string, or you can save, replace, exit, display line numbers, and so on. The following Amin teaches you how to write a piece of text in a blank document and then save it.
[[email protected] ~]# vim test.txt input vim test.txt Direct enter into general mode. Then press the "I" letter into the edit mode, in the lower left corner of the window will show "– Insert –" or "–insert–" This means entering insert mode, you can edit the document. The following Amin casually write a text:
This is a test file. And this was the first time to using "vim". It's easy-to-use "vim". I like-to-use it, does it? If you have finished editing and want to save, you need to first click the "ESC" key in the upper left corner of the keyboard, "– Insert –" or "–insert–" disappears, and then enter ": Wq" Carriage will save the text just now The word.
This is a test file. And this was the first time to using "vim". It's easy-to-use "vim". I like-to-using it, do-like it?~~:wq at this point, take a look at the contents of the Test.txt document:
[email protected] ~]# cat test.txtthis is a test file. And this was the first time to using "vim". It's easy-to-use "vim". I like-to-using it, do you like it? In fact, "vim" is a full keyboard-operated editor, so there are many function keys in each mode. The following list, where Amin that the commonly used will be marked in red, you need to practice more, but also the less common you need to know.
_images/vim.png _images/vim2.png _images/vim3.png _images/vim4.png so much for the time being. If you can master it all, you must be a master of vim. If you feel too much, just remember Amin marked red part can, other time to come back check on OK. Below Amin to leave a small homework for you, hope you can finish earnestly! Please copy the/etc/init.d/iptables to the/root/directory and rename it to Test.txtcp/etc/dnsmasq.conf/tmp/1.txt//Copy the file again with Vim open test.txt and set line number VIM/ Tmp/1.txt
Move down, right, left, and right 6 characters (6j 6l 6h 6l) down, up two pages (press two ctrl+f and ctrl+b respectively) move the cursor to line 49th (49G) so that the cursor moves to the end of the row, then to the beginning of the start (SHIFT + 4, SHIFT + 6) to T The last line of the Est.txt file (G) moves to the first line of the file (GG) to search for a file that appears in the iptables and counts how many (input/iptabels, and then press N) Replace the iptables that appear from the first line to the third row into iptable ( : 1,10s/dnsmasq/dns/g) Restore previous action (U) Replace all iptables in the entire file with iptable (: 1, $s/etc/cte/g) to move the cursor to line 25, delete the character "$" (Enter 25G, Then press J to move the cursor to the right to find Y, press V to select, and then press X to restore the previous action (U) Delete the 50th row (50G dd) restore the previous action (U) Delete all content from 37 rows to 42 rows (37G 6DD) restore the previous action (double-click UU) Copy the 48 rows and paste them below 52 lines 48G yy 52G P) Restore the previous action (press two U) to copy the contents from 37 rows to 42 rows and paste it onto line 44 (37G 6yy 44G p) to restore the previous action (by two times u) move the contents of line 37 to 42 to 19 lines (37G 6DD 19G p) to restore the previous action (by two times u) move the cursor to the first line, change the/bin/sh to/bin/bash (first press GG, position the cursor to the first line, then press the letter A, go to edit mode, move the cursor to the end of the line to modify the operation, press ESC after completion), insert a new line below the first line, and enter "# Hello! "(Press O to enter edit mode while moving the cursor down another line, enter #hello) Save the document and exit (press ESC, enter: WQ)
Seventh Chapter-vim Text Editor