vim editing mode and command mode

5.5 Enter Edit Mode

Return to normal mode "Esc" from edit mode

5.6 vim command mode

Order

: "nohl"=no high light No highlight, cancel the highlight mark
"x" in the content: save and exit, the difference from wq is that when a file is entered and not edited, using this command will not change the atime of the file.

Find and replace command in edit mode

eg1 :

Find abc and replace it with ABC (replace all within a certain range)
'/1,100s/abc/ABC/g' That is: replace all abc in line 1 to line 100 with ABC. (s: replace; g:=global, all. If g is not added, only the first abc of each line will be replaced), '/' can be replaced with # or @.

eg2:

Find /etc/111.txt and replace it with adai.
At this time, if you use '/' to execute the command, it will cause it to conflict with the replaced object, so use # to execute the command (this method is commonly used), if you still use '/' to To execute the command, the following operations are required:
'/ \ /etc \ /111.txt/adai/g' Here, '\' is the underwriting character, indicating that the following characters are not recognized

5.7 vim practice

# cp /etc/dnsmasq.conf  /tmp/1.txt

(1) Move 6 characters down, right, left, and up respectively (6j 6l 6h 6k).

(2) Turn down and up two pages respectively (press ctrl+f and ctrl+b twice respectively).

(3) Move the cursor to line 49 (49G).

(4) Move the cursor to the end of the line, and then to the beginning of the line (Shift+4, Shift+6).

(5) Move to the last line (G) of the 1.txt file.

(6) Move to the first line of the file (gg).

(7) Search the file for occurrences of "dnsmasq" and count the number of occurrences of the string (/dnsmsq then n).

(8) Replace dnsmasq from line 1 to line 10 with dns (:1,10s/dnsmasq/dns/g).

(9) Restore the previous operation (u).

(10) Replace all etc in the entire file with cte (:1, $s/etc/cte/g).

(11) Move the cursor to line 25 and delete the string "ly" (25G and then press j to move the cursor to the right to find "ly", press v to select, then press x).

(12) Restore the previous operation (u).

(13) Delete line 50 (50G dd).

(14) Restore the previous operation (u).

(15) Delete everything on lines 37-42 (37G 6dd).

(16) Restore the previous operation (u).

(17) Copy the content of line 48 and paste it below line 52 (48G yy 52G p).

(18) Restore the previous operation (u).

(19) Copy the content of lines 37-42 and paste it above line 44 (37G 6yy 44G P).

(20) Restore the previous operation (press u).

(21) Move the contents of lines 37-42 below line 19 (37G 6dd 19G p).

(22) Restore the previous operation (press u).

(23) Move the cursor to the first line, and change the content of the first line to "#!/bin/bash" (press gg first, position the cursor to the first line, then press the letter A to enter the editing mode, and at the same time > cursor to the end of the line, make the modification, and press ESC when done).

(24) Insert a new line below line 1, and enter "# Hello!" (press o to enter edit mode, and at the same time the cursor goes down another line, enter "# Hello!").

(25) Save the document and exit (press the Esc key and enter ":wq").

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325363869&siteId=291194637