VI Use Summary

Source: Internet
Author: User

CHAP 1
1.~ represents a blank line.
2. Use e! in command-line mode to cancel all edits in this session.
3.ZZ is used to save and leave VI.


CHAP 2
1.VI Move cursor single character position: HJKL (lower left upper right), use number plus hjkl to move multiple times.
2. In command-line mode, the number 0 means moving the cursor to the wardrobe, $ means moving the cursor to the end of the line.
3.VI uses w/b (w/b) to move blocks, uppercase without punctuation.
The 4.c command is for modification, you can use c2w to modify the next two words, C2B to modify the first two words. C0 changes the cursor to the wardrobe, C $ modifies the cursor to the end of the line, and uses CC to delete and edit the entire line.
5. Use the R command to replace a single character and use the S command to replace a single character.
6.~ is used to transform case.
The 7.D command is used to delete, DW deletes the entire word, DD deletes the entire line (or D), and 2DD deletes the first two lines.
The 8.U command is used to restore the last operation. The 3p command shows the contents of nearly 3 modifications after the cursor (up to 9 times). Therefore, if you delete a row using DD, you can put the deleted content behind the cursor by using the P command.
9. Use XP to swap two characters.
10. Copying text requires the use of Y (drag-to-buffer) and P (place) commands. Drag and drop support yw drag a word, y0 drag the current to the end of the line, YY drag the whole line, 4yy drag four rows.
11.A adds at the end of a line, I add at the beginning of a row, O opens a new line on the next line of the cursor, and O opens a new line on the previous line of the cursor.
12. Use J to merge two rows.


CHAP 3
1. Scroll: ctr+f/d roll forward, ctr+b/u scroll backwards. H moves to the beginning of the line, and L moves to the end.
2.^ moves to the first non-space of the current line, n| moves to the nth column of the current row.
3.E moves to the end of the current word, () moves to the beginning and end of the current sentence, and {} moves to the beginning and end of the current paragraph.
4./search backwards, search forward. N repeats the search in the same direction, and N repeats the search in the opposite direction. The set Nowrapscan setting does not go around the beginning of the search.
5. Delete by search: D/move Remove the move character.
6.TX,FX is used to search for the character X in the bank. T place the cursor with x before the F cursor is after x. Use semicolons to continue searching.
7.CTRL+G displays the number of lines in the current document. G to go to the command, Ng moves to n line, ' return to the original place.


CHAP 4
1.1GdG deletes all text, where DG is used to delete the cursor position to the end of the file. YG copies the cursor position to the end of the file. CG changes the cursor position to the end of the file.
2.vi/pattern A.txt Open the a.txt in the pattern position, if the pattern has spaces, you need to add "", if there are special characters in pattern, use \ Escape.
3.vi-r A.txt opens a.txt in read-only mode. Vi-r A.txt restores the contents of the file buffers to a.txt.
4.VI Records 9 times the most recently modified content to the buffer zone, to restore the buffer using the "NP command, restore the contents of the last nth buffer. Multiple restores are typically placed using the P command, and then use the. Repeat command or u to undo the recovery command.
5. Use the Anyy command to drag the current n row to buffer a.


CHAP 5
The 1.ex command is the lower-level editor command, and VI is its visible shell. where d is the deletion, M is the move, and the CO is the copy line. For example, the command: 100,200d indicates that rows 100 to 200 are deleted.
2.:set Nu Displays line number,: Set Nonu suppress display.
3. Line addressing symbol:. Current line, $ last row,% represents each row in the file. Command:., $d Delete the current line to the end of the line. : 20,.m$ represents moving 20 rows to the current line to the end of the line. :%co$ means that all rows are copied to the end of the line. :.,. +20d represents the deletion of the current line to 20 rows after the current row.
4. Search and delete command:/pattern/d means to delete the next line containing the pattern. :/PATTERN1,/PATTERN2/D indicates that the next line containing the PATTERN1 is removed to the next row that contains the pattern2.
5.:G is used for global search. Command: g/pattern/n means to find and display all line numbers that contain the pattern: g/pattern/p Displays the rows that were searched. : GL Search does not contain rows.
6. Save a portion of the file command: a.txt, $w writes 100 lines to end to A.txt, command: +, $w >>a.txt to add.


Char 6
1. Global substitution using G (global), S (replace). Command: S/OLD/NEW/G Global replaces the current row's old as new. Command:%s/old/new/g globally replaces old with new.

2. Regular expressions:. Represents a single character (including spaces, not including line breaks), * means matches 0 to more characters, ^ represents a costume, $ denotes the end of the line, \ is used to escape, [] is used to match the characters appearing in it, [a-za-z] matches all letters, [^a-z] matches all characters that are not lowercase.


PS: Reference book "Learning VI and Vim editor Seventh edition"

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

VI Use Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.