VI common command

xiaoxiao2021-03-06  22

My most commonly used VI command

First, move: HJKL's left upper right moving o Insert a holiday line after the cursor is located. O Insert a holiday in front of the cursor. 0 Moving the cursor to the Launch of the Lower Move the cursor to the row ctrl f backwards. Ctrl D rolls backwards. Ctrl b rolls forward. Ctrl U rolls forward half. The Ctrl E screen rolls down. Ctrl Y screen item rolled up. H, l The top / end of the current screen (N) g: Press a number, then press G, jump to the nth line of the cursor, 1G is the first line of the file. If you don't play, jump to the end of the file. Second, the operation I insert i After the first insertion A, insert a after the head is inserted into the R substitute DD delete the tribute DW Delete the cursor where the cursor is located D or D $ delete the cursor, the content U recovered the last modification, revoked recovery: Ctrl R

YY copys 2YY copy 2 lines,

YW Copy Current to the word tail y $ copy cursor position to the end

p stick

Block replication (minimum memory method)

Start location ma

End position y`

Paste position P

w Save W FileName Save As Q Exit Q! Do not save exit

Third, replacement

In a row, a string OLD is a new string new, please enter: s / old / new

Replace all strings in one line OLD for new string new, please enter: S / OLD / New / G

Replace all strings in both lines for new strings New, please enter: #, # s / old / new / g

Replace all strings in the file for new strings New, type:% s / old / new / g

Inquiry the user to confirm the user to confirm that each replacement is added to add a C option, type:% s / old / new / gc

When you are replaced with full text, you can also enter: 1, $ S / OLD / NEW / G. Where 1, $ represents from the first line to the text.

Fourth, other: / look up, match n to find the next, n look up Previous: SH Switch to Shell, EXIT switch back

There is also a very common situation: VI modified a file and found readonly when saved, because the authority is not enough. Editing a half-day thing, always can't quit the weight. It is too low to use the mouse. If the current user is authorized by the administrator, there is a solution: w! Sudo tee%, enter the password, enter a few times a few times, then:! Q Exit.

转载请注明原文地址:https://www.9cbs.com/read-43059.html

New Post(0)