Vim is a text editor developed from VI. With color display, code completion, compilation and error jump and other convenient programming features are particularly rich, in the programmer is widely used. To put it simply, VI is an old-fashioned word processor, but the function is already complete, but there is still room for improvement. Vim can be said to be a very useful tool for program developers.
vim keyboard diagram :
VIM installation : Yum install-y vim-enhanced; (I have installed, so no installation process is shown!) )
use of vim :
VIM has three modes: normal mode, edit mode and command mode, respectively.
General mode :
The user launches the Vim editor and enters the general mode. In this state, the keystrokes are recognized by VIM as commands rather than as input characters. For example, we press I at this time and do not enter a character, I is treated as a command.
Here are a few common commands:
I switch to input mode to enter characters.
x deletes the character at which the current cursor is located.
: Switch to command mode to enter commands at the bottom of the line.
If you want to edit the text: Start Vim, enter the general mode, press I, switch to edit mode.
edit mode :
Press I in general mode to enter edit mode. In edit mode, you can edit the content and so on.
Command mode :
In general mode, press: (colon) to enter the command mode. Command mode you can enter commands for single or multiple characters, and many commands are available.
In command mode, the Basic command has (the colon has been omitted):
Q Exit Program
W Save File
Press the ESC key to exit Command mode at any time.
three modes of conversion diagram :
The following are the most commonly used keys for VIM :
Move the cursor in general mode:
Copy and paste in general mode:
Enter edit mode: (mainly Aioaio)
Command mode:
、
Practice:
# Cp/etc/dnsmasq.conf/tmp/1.txt
(1) Move Down, right, left, and up 6 characters (6j 6l 6h 6k) respectively.
(2) Two pages (two times ctrl+f and Ctrl+b respectively) downward and upward respectively.
(3) Move the cursor to line 49th (49G).
(4) Move the cursor to the end of the line, and then move to the beginning (Shift+4, shift+6).
(5) Move to the last line of the 1.txt file (G).
(6) Move to the first line of the file (GG).
(7) Search for "DNSMASQ" in the file and count the number of occurrences of the string (/dnsmsq then press N).
(8) Replace the DNSMASQ from line 1th to line 10th with DNS (: 1,10s/dnsmasq/dns/g).
(9) Restore the previous action (U).
(10) Replace all the etc in the entire file with a CTE (: 1, $s/etc/cte/g).
(11) Move the cursor to line 25th, delete the string "ly" (25G then press L to move the cursor to the right to find "ly", press V to select, and press X).
(12) Restore the previous action (U).
(13) Delete line 50th (50G dd).
(14) Restore the previous action (U).
(15) Delete all contents of 第37-42 line (37G 6DD).
(16) Restore the previous action (U).
(17) Copy the contents of line 48th and paste it below line 52nd (48G yy 52G p).
(18) Restore the previous action (U).
(19) Copy the contents of the 第37-42 line and paste it onto line 44th (37G 6yy 44G P).
Linux Text Editing Tool vim