unconsciously a week of time is over, feeling unprecedented enrichment! This week learning the Vim editor is said to be important!
One. Open File
★vim +n filename After opening the file, leave the cursor at the beginning of line N, + the default tail line.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9D/BD/wKioL1mFJILD1K0FAAA2cJ0v6J0757.png "title=" 2.png "Style=" width:563px;height:100px; "width=" 563 "vspace=" 0 "hspace=" 0 "height=" "border=" 0 "alt=" Wkiol1mfjild1k0faaa2cj0v6j0757.png "/>
★vim +/to search for the word filename after opening the file, leave the cursor directly at the beginning of the first line to be matched.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9D/BD/wKiom1mFJKfR_U5DAAB0QVyOhC4157.png "title=" 1.png "Style=" width:608px;height:180px; "width=" 608 "vspace=" 0 "hspace=" 0 "height=" 0 "border=" alt= " U5daab0qvyohc4157.png "/>
★vim
-M read-only mode open file
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9D/C1/wKioL1mFYqWw-5_GAAArT_rQEcA620.png "title=" a.png "Style=" float:left;width:743px;height:50px; "width=" 743 "vspace=" 0 "hspace=" 0 "height=" "border=" 0 "alt=" Wkiol1mfyqww-5_gaaart_rqeca620.png "/>-B binary Open file
-D file1 file2 compare multiple files
Two. The Vim editor mode switch
Insert mode--------> Command mode
Esc
Command mode---------> Extended command mode
:
Extended Command mode--------> Command mode
Enter,esc
★ Command mode
ZZ: Save exit
ZQ: Do not save exit
Command mode Flip screen operation:
CTRL +f down one screen
CTRL +b turn up one screen
CTRL +d flip down half screen
CTRL +u flip up half screen
★ Extended Command mode:
: Q exit
: q! Force exit, discard the modifications made
: Wq Save Exit
: X Save exit
Note: wq! or x! can be forced to save and exit when the file is read-only for the current user rights (root and current file owner only)
Extended Command mode
Press ":" To enter expansion mode
Create a command prompt: On the left side of the screen at the bottom
Command: W Write (Save) disk File
Wq Write and exit
X Write and exit
Q exit
Q!! Do not save the log out, even if the changes are lost
R filename reads the contents of the file into the current file
W FileName writes the current file contents to another file
!command Execute command
R!command read-in command output
★ Address definition (Extended command mode)
#具体第 # line, for example, 2 for line 2nd
#,# from the left # represents the starting line to the right # indicates the end line
#,+# the starting line from the left # representation, plus the number of rows on the right # representation. ": 2,+3 = 2 to 5 rows
. When moving forward
$ last line
., $-1 current line to penultimate line
% full text, equivalent to 1,$
/pat1/,/pat2/
Starts from the first line that is matched to the pat1 pattern, until the end of the line that was first matched to by the PAT2
★ Find (Extended command mode)
/pattern: Looks at the end of the file from the current cursor location
? PATTERN: Finds the file header from the current cursor location
N: Same direction as command
N: Opposite direction of command
★ Replace (Extended command mode)
Format: s/What to look for/replace with content/modifiers
What to look for: Available modes
Replace with: cannot use mode, but can use \1, \2, ... You can also use "&" to refer to the entire content found in the previous lookup.
Modifier:
I: Ignore case
G: global substitution; By default, each row replaces only the first occurrence of the
GC: Global substitution, asking before each replacement
Find the delimiter in the replacement/can be replaced with other characters, such as [email protected]/[email protected]/[email protected] s#/boot#/#i
★ Multi-file Mode: Vim F1 F2 F3
: First One
: Next Next
: Last One
: Prev Before a
: Wall Save All
: Qall Quit all
: Wqall Save to exit all
★ Use multiple Windows
Multi-file Segmentation: Vim-o|-o file1 file2 file3
-O Horizontal Split
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/C2/wKiom1mFZDXykJI9AABULMVn5po007.png "title=" A2.png "style=" width:431px;height:350px; "width=" 431 "vspace=" 0 "hspace=" 0 "height=" border= "0" alt= " Wkiom1mfzdxykji9aabulmvn5po007.png "/>
-O Vertical Split
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9D/C1/wKioL1mFZOrhmPqhAABx3w8RqvE561.png "title=" A3.png "style=" width:772px;height:180px; "width=" 772 "vspace=" 0 "hspace=" 0 "height=" 0 "border=" Wkiol1mfzorhmpqhaabx3w8rqve561.png "/>
Switch between multiple windows: Ctrl+w Arrow
Single File Segmentation:
Ctrl+w,s:split Horizontal Split
Ctrl+w,v:vertical Vertical Segmentation
Ctrl+w,q: Canceling adjacent windows
Ctrl+w,o: Cancel All windows
: Wqall exit
Exercise
1. Copy the/etc/profile to/tmp/directory and use the Find replacement command to remove the white space characters from the beginning of the/tmp/profile file.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9D/BF/wKiom1mFN5GCxGq0AAA9KRhjWAs868.png "title=" 3.1. PNG "style=" width:402px;height:150px; "width=" 402 "vspace=" 0 "hspace=" 0 "height=" border= "0" alt= " Wkiom1mfn5gcxgq0aaa9krhjwas868.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9D/BF/wKiom1mFN96RaQ6vAAALaVJv1I4873.png "title=" 3.2. PNG "style=" width:220px;height:25px; "width=" "vspace=" 0 "hspace=" 0 "height=" "border=" 0 "alt=" Wkiom1mfn96raq6vaaalavjv1i4873.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9D/BE/wKioL1mFODrD72JoAAAmHb2dgOE013.png "title=" 3.png "Style=" width:389px;height:120px; "width=" 389 "vspace=" 0 "hspace=" 0 "height=" "" border= "0" alt= " Wkiol1mfodrd72joaaamhb2dgoe013.png "/>
The knowledge points used in this question are:
1. Address Definition% means full
2. Format of replacement: format: s/What to look for/replace with content/modifiers
3. Use regular expressions for the content you want to find
4. To replace with a space can be used//representation
2. Copy the/etc/rc.d/init.d/functions file to the/tmp directory and add a # number to the beginning of the line beginning with each line of/tmp/functions with the find replacement command.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9D/BF/wKioL1mFPzzDAAbfAABIPYhR1Vg287.png "title=" 4.png "Width=" 742 "height=" 104 "alt=" Wkiol1mfpzzdaabfaabipyhr1vg287.png "/>
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9D/BF/wKioL1mFP7zSiP3zAAAOxjnIRUU885.png "title=" 4.2. PNG "width=" 425 "height=" "alt=" Wkiol1mfp7zsip3zaaaoxjniruu885.png "/>650" this.width=650; "src=" https:// S4.51cto.com/wyfs02/m00/9d/bf/wkiom1mfqarbmas7aaa425qc7dk287.png "title=" 4.1.png "width=" 848 "height=" alt= " Wkiom1mfqarbmas7aaa425qc7dk287.png "/>
Compared with the above problem, this problem to use the latter reference , but to note that the back reference when the content to be quoted must be added ()
3. Copy the/etc/rc.d/init.d/functions file to the/tmp directory, replacing the/etc/sysconfig/init in the/tmp/functions file with the/var/log.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/C1/wKioL1mFaOywwTyfAAArmBsmlWQ786.png "title=" 5.png "Style=" width:639px;height:90px; "width=" 639 "vspace=" 0 "hspace=" 0 "height=" all "border=" 0 "alt=" Wkiol1mfaoywwtyfaaarmbsmlwq786.png "/>
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/C2/wKiom1mFaVrxTmgYAAAikn3KIYY265.png "title=" 5.1. PNG "style=" width:584px;height:90px; "width=" 584 "vspace=" 0 "hspace=" 0 "height=" all "border=" 0 "alt=" Wkiom1mfavrxtmgyaaaikn3kiyy265.png "/>
Answer::%[email protected]\/etc\/sysconfig\/[email Protected]\/var\/[email protected]
Parsing: This problem has many "/", for anti-aliasing can be found in the replacement of the delimiter/replaced with another, such as: @,#, in addition to find in the replacement/to be escaped
Text editor Vim