This chapter introduces the ex editor. Why should we introduce such a new editor? In fact, the ex editor cannot be regarded as a new editor. VI is just its visual model, which is more common, line-based editor. Ex provides more mobile and range editing commands. Using ex, there are many ways to easily switch files and transfer file content, faster editing of text blocks larger than a screen.
Open a file
Ex File---- Use ex to open a file without displaying the file content. Displays the status of a file and a command line
Show File Content
[Number]-[p]---- The content of the first line in reality, P can be omitted
[Number]-,-[number]---- Display the content from the row to the row
Replace
S/[fromcharacter]/[tochracter]--- Replace from current row
Switch to VI Mode
VI---- Switch to VI Mode
Move the cursor in VI Mode
[Number]---- Move the cursor to the row
Edit command
[Number], [number] d---- Delete the content from the row to the row
[Number], [number] M [number]---- Move the content from the row to the row under the row
[Number], [number] Co/T [number]---- [CO or T] copy the contents from the row to the row
Set nu [mber]----- Display the row number
Set Nonu [mber]---- Do not display the row number
[Number], [number] #---- Number of the first row to the second row of the temporary reality
=---- Display the total number of rows
. =---- Display the current row number
/Pattern/=---- Display the row number with a matching item
.---- Indicates the row number of the current row.
$---- Indicates the row number of the last row. For example, 20,. M $ indicates moving the content of row 20th to the current row to the end of the file.
%---- Indicates all rows. For example, % d Indicates deleting all rows.
+ [Number]---- Indicates the number of rows down, and number does not indicate + 1. For example,. + 20d indicates deleting the content of the 20 rows down from the current
-[Number]---- Indicates the number of rows up, and number does not represent-1. For example, 226, $ M.-2 indicates moving the content from row 226th to the last row to the first two rows of the current row
0--- Indicates that the file starts.
[Number1]; + [number2] P---- Display the number2 rows after the number1 row
/Pattern/; + [number] P---- Display the [number] line after the first matched row
Search
/Pattern/d---- Delete the row where the next match is located
/Pattern/+ d---- Delete the next matched row
/Pattern1/,/pattern2/d---- Delete the content of the first row matching pattern1 to the first row matching pattern2
.,/Pattern/M/[number]----- Move the content of the current row to the first line matching the Patten to the end of the given row
G/pattern/P--- Search for and display all rows containing Pattern
! G/pattern/P--- Find and display all rows that do not contain Pattern
[Number1], [number2] g/pattern/P---- Search for and display rows containing pattern from row number1 to row number2
Command connection
[Command1] | [command2]---- Connect two commands, such as 1, 3D | S/thier/their, to delete 1-3 rows and replace them
Save
[Number1], [number2] W newfile---- Save the content from row number1 to row number2 to a new file.
[Number1], [number2] W> newfile---- Add the content from row number1 to row number2 to the end of the newfile file.
Copy Between Files
[Number]/[0]/[$] [/pattern/] r filename---- Copy the filename content of the file to the end of the current cursor/file start/file end/first line containing Pattern
VI/Vim use zhibei ---- introducting the ex Editor