5.5 entering edit mode
I key in the current word match either insert
The I key is inserted at the beginning of the line where the cursor
A key starts at the next character where the cursor is located
A key is inserted at the end of the line where the cursor is located
The O key inserts a new line on the next line of the row where the cursor is located
The O key inserts a new line on the previous line of the row where the cursor is located
5.6 VIM Command mode
/word after the cursor looks for a string word, press N to go back to search, N or shift+n forward
Word to search for a string before word, press N to continue searching, N or shift+n backwards
: n1,n2s/word1/word2/g find word1 in n1~n2 and replace with Word2, no G replaces only the first of each row word1
: 1, $s/word1/word2/g Replace all word1 of the document with Word2, and no G replaces only the first word1 of each row
: W Save Text
: Q Quit Vim
: w! Force save, under root user, even if the text is read-only can be saved
: Wq forced exit, all changes not in effect
: Set NU Displays line number
: Set Nonu does not display line numbers
: ↑ Last used command
: Nohl highlighted words, not highlighting hints
: x save exit, change file is similar to Wq; File Open is not operational, change mtime
: 1,100s/dnsmasq/aminglinux/g from line 1th to line 100, s means start substitution, replace DNSMASQ with aminglinux,g to replace all
1, $s/\/etc\/hosts\//aminglinux/g replace/etc/hosts/with Aminglinux, escape with \ or 1, $s #/etc/hosts/#aminglinux/g or @ symbol delimited
Set NU Display line number
5.7 Vim Practice
#cp/etc/dnsmasq.conf/tmp/1.txt
1, respectively down, right, left, move up 6 characters (6j,6l,6h,6k)
2, respectively down, up two pages (two times ctrl+f and Ctrl+b 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 (/DNSMASQ then press N)
8, replace the DNSMASQ from line 1th to line 10th with DNS (: 1,10s/dnsmasq/dns/g)
9, Restore 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 J to move the cursor to the right to find "lyl", press V to select, then press x)
12, Restore previous action (U)
13, delete line 50th (50G DD)
14, Restore previous action (U)
15. Delete all contents of 第37-42 (37G 6DD)
16, restore previous action (U)
17, copy the contents of line 48th and paste it below line 52nd (48G yy 52G p)
18, restore previous action (U)
19. Copy the contents of the 第37-42 line and paste it onto line 44th (37G 6yy 44G P)
20, restore previous action (U)
21. Move the contents of the 第37-42 line below line 19th (37G 6DD 19G p)
22, Restore previous action (U)
23. Move the cursor to the first line and change the contents of line 1th to "#! /bin/bash "(First press GG, position the cursor to line 1th, then press the letter A, enter the edit mode, > Cursor to the end of the line, modify the operation, after completion, press ESC)
24, insert a new line below line 1th and enter "#Hello!" (Press O to enter edit mode, while the cursor goes down another line, enter "#Hello!" )
25. Save the document and exit (press the ESC key, enter ": Wq")
2018-1-4 4 weeks 3 lessons VIM 2