In the reference learning the VI and Vim editor when found that the ex editors as the parent class VI, for our in-depth understanding of VI and VI clones of the past life has great help, it is necessary to separate a document to introduce some common commonly used directives . $ex Practice uses the EX editor under UNIX to call the file. Results: "Practice" 6 lines, characters: Displays the number of lines of the file, how many characters. Stop at: Colon command prompt. p Print to screen, 1p print line 1th to screen, can remove P, Because the line number itself is equivalent to the command that prints the line. Display results:: 1pWith A screen editor you can : separated by commas, the middle space is dispensable, printing 1 to 3 lines. Results:: 1,3with A screen editor canscroll the page, move the cursor,delete lines, insert characters, and More,: vim . Note the replace command for ex has been introduced, and if no line number is assumed to be active on the current line.: 1With a screen editor can:/screen/line/with a lines editor you can command changes and then will be displayed again.: 1s /screen/line/ with a line editor you can Use ex for editing many of the edits performed by the ex command have a simpler equivalent command in VI. However, in the ex command, a single command can be used to modify large blocks of text, so the ex command is more useful when you want to modify many rows. (It is important to emphasize that the ' Execute ex command under VI ' and ' execute ex ' in Ex ' is completely different) remember that each ex command in VI must be preceded by: Colon . Delete & nbsp d Delete line move & Nbsp;m &NBsp Mobile line copy  CO Copy lines T Copy line line address for the Ex Editor command, you must give the line that you want to edit for ex. move and copy of the before must give the target location to move or copy the text. So how do you tell ex which lines to edit? 1 Use explicit line numbers 2 Use a symbol that will help you specify the line number relative to the current position in the file &NB Sp 3 Use search mode as the address that identifies the row you want to edit define the range of rows you can use line numbers to explicitly define a row or range of rows. Addresses that use explicit numbers are called absolute row addresses. Example: 3,18d Delete Rows 3 to 18:160,224M23 moves 160 to 224 rows to the back of the 23 row: 23,29co100 copies 23 to 29 rows to the back of the 100 row :1,10# # You can temporarily display the line number of a part of a row. Ctrl+g can display the line number of the current line.: = Show total number of rows:. = Displays the line number of the current line the operation of the line number above may make you feel the fireworks sportive, but it is not related to the configuration file later: SETNU command permanent display line number, mother no longer have to worry about my absolute positioning. & nbsp;:/ Pattern/= Displays the line number of a line that matches a pattern The line address character represents the line address of the symbol called the line address character, commonly used in the following three: . represents the current row 0 represents the first line in a file $ represents the last line of the file % represents each line in the file Example::., $d Delete the text of the current line to the last line: 20,.m$ Moves the text of line 20 to the current line after the last line:%d Delete said rows:%t$ Copy all the text to the end of the text:-,+t0 The previous line and the next line in the current row are copied to the beginning of the text with the current line In addition to the absolute address, You can also specify an address relative to the current row. With symbols + and-just like the number operators, when you place them in front of a number, the symbols add or subtract the values that follow them. Example::.,. +20d Delete the current line at the beginning of the 20 lines below: 226, $m. -2 Move the text from line 226 to the end of the file to the top 2 lines of the current line:., +20# Displays the line number of the current line and the 20 rows below the current line is the assumed starting position, so the dot is missing when using + or-. If there are no numbers after + and-they are equal to + 1 and 1. Note that you cannot separate the plus sign from the number following the minus sign. Otherwise, the difference will occur. ++ represents the current row +1+1 is the current row +2--represents the current row-1-1 is the current row -2 search mode (note: The front and rear of the pattern is bound with a diagonal bar ):/pattern/d Delete a line that contains the pattern:/pattern/+d Deletes the following line of a line containing the pattern:/pattern1/,/pattern2/d Delete the text from the first row containing pattern1 to the first row containing the pattern2:.,/pattern/m23 moves the line between the current line and the first matching pattern to the back of the 23 row The delete operation with pattern matching in VI differs from the use of pattern matching in ex to delete operations: D/while removes all characters from the current cursor to the first matching while character after the cursor, but characters on the same line except those characters are retained:.,/while/d Ex deletes all of the specified rows, as long as the rows in the match are deleted, and all characters on the same line are deleted redefine the position instance of the current row:: 100,+5 pfirst address exceeds second first address after second address :100;+5 p When you use the number, the first line will beThe address is recalculated as the current line.  :/PATTERN/;+10 p Prints the first line that matches the/pattern/and 10 lines below it you can use spaces to separate the different elements of the ex command. However, you cannot use whitespace as a delimiter in a pattern or at the end of a replacement command . Global search uses/in VI to search for characters in a file, and ex has global command G, which allows you to search for characters and display all rows that contain the pattern. Use: g! In contrast to: G instead, use: g! to search for lines that do not contain characters. You can use a row address to restrict a global search to a specified row or row range. Example:: G/pattern Find where to move to the last occurrence of the pattern: g/pattern/p Find and display all lines in the file that match the pattern: G!/pattern/nu Find and display all rows that do not contain a pattern, and display the line numbers of those lines: 60,124g/pattern/p Find and display all matching patterns between rows combinations from 60 rows to 124 The EX command can use the vertical bar (|) in Ex. It allows the user to combine multiple commands at the same ex prompt. When using |, be aware of the line address you specify. If a command affects the order in the file, the next command will work with the new row location. Note: | The command in the shell, which plays a role in the shell ; function very much like: 1,3d | s/thier/their/remove the first line to the third row. Then replace the current line: 1, 5 M 10 | G/pattern/nu moves the contents of the first and fifth rows to the back of line 10th, and then displays all the lines that contain the pattern and the travel number save and exit files in VI, the command ZZ exits and saves the file, and the command ZZ moves the current line to the center of the screen in Ex, Use the following command to control the Save and exit:: W writes the contents of the buffer to disk but does not exit. Can be used during editing: W protect the edits to avoid system paralysis or significant editing errors.: Q Exit Editor If the file has been modified, You will be blocked and prompted when you exit. Only if no changes have been made to smooth the use: Q exit: Wq save and exit, even if the file is not modified, the write operation will be unconditionally executed: X Write file and exit, only modify the file write operation can also be done: Wq and: X Although it is all written and exited. However: Wq is unconditional, and: X is modified in the premise, if not modified: X, will error: No write since last change.: w! Forcibly save can be written in read-only mode, but must have write permission: q! Forced exit do not make any changes to the buffer content is deleted: w practice.new We can save the contents of the current buffer to a new file: $w NewFile can also select some of the text in the buffer to be saved to a new file: 340, $w >> NewFile can append portions of the buffer to the end of a file. Much like the output redirector in the shell, of course, the child of C + + or C # will be angry to recognize that this is the input stream, very image it? copy the file to another file: R FileName reads a new file into the current file, which is inserted by default on the next line of the current cursor: 185r filename Inserts a new file in 185 lines of the current text: $r filename Inserts a new file at the end of the file: 0r FileName Inserts a new file at the beginning of the file:/PATTERN/R filename Inserts a new file in the next line of the matching pattern edits multiple files edit multiple files without frequent closing and opening of VI. And you can keep the specified abbreviations and command sequences, and copy buffers so that text can be copied between files. VI file1 file2 The contents of the File1 are displayed first on the screen. After the file1 edit is finished,: w save file1,:n Command to invoke the next file File2:args abbreviation: AR Lists the files specified on the command line, with the current file enclosed in square brackets: Rewind abbreviation: rew command to reset the current file to the first file specified on the command line to invoke a new file can be used in ex: E command to switch to another file at any time: E filename After calling the new file VI put two filenames as the current file name and backup file name, you can also use the symbol% and #来表示.: E # Returns the last edited file  :R # Read the last edited file: E ! # Discard changes to the current text and return to the previous file: n! # Discard changes to the current file and return to the previous file: e! Discard changes to the current file reload the last saved version of the current file: W%.new Save the current file to the current filename. A file in new if you do not save the current document first, and do not add it after: E and: N! To command VI to transform the current file, You will not be allowed to switch between files using the above command. ctrl+^ can also be used to back and forth between files in VISwitch. This command with: E #相同. But also save or discard the current file, or VI will not be allowed to switch to the previous file . edit between files when you specify a single-letter name for the copy buffer, you have the channel to move the text from one file to another. When using: When the e command loads a new file into the vi buffer, the named buffer is not purged. Therefore, by copying and deleting text from a file, using: E to invoke the new file, and then refer to the new file in the name buffer exhibition, so that the text can be transferred between the files. " F4yy Copy four rows to buffer F "FP Paste the text in the buffer below the current cursor Another method: ya copy:p u paste Example:: 160,224ya a 160 lines to 224 lines of text copied into buffer a , you can then use the: E command to move to the file where you want to place the rows: Pu a paste the contents of buffer a after the current line
Summary of common EX commands (pending update)