Article Title: Linux vi editor command excellent edition. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Recently I started to use the vi editor. After several days, I found that it is actually quite easy to use. Summarize your frequently used commands for Real-Time query. The following is a summary of multiple articles on the Internet.
Run the following command to access vi:
Vi filename: open or create a file and place the cursor at the beginning of the first line
Vi + filename: open the file and place the cursor at the beginning of the last line
Vi +/pattern filename: open the file and place the cursor at the first string matching pattern
SEARCH command:
/Pattern: Search for pattern from the beginning of the cursor to the end of the file
? Pattern: Search for pattern from the beginning of the cursor
N: Repeat the previous search command in the same direction.
N: Repeat the previous search command in the reverse direction.
Move the cursor command:
┌ ── ─ ┬ ── ─ ┐
│ Command │ description │
├ ── ─ ┼ ── ─ ┤
│ J or down arrow │ move down a line │
├ ── ─ ┼ ── ─ ┤
│ K or up arrow │ move up a line │
├ ── ─ ┼ ── ─ ┤
│ H or the left arrow │ move one character to the left │
├ ── ─ ┼ ── ─ ┤
│ L or right arrow │ move one character to the right │
├ ── ─ ┼ ── ─ ┤
│ W │ shift one word to the right │
├ ── ─ ┼ ── ─ ┤
│ W │ right shift a word separated by spaces │
├ ── ─ ┼ ── ─ ┤
│ B │ move one word left │
├ ── ─ ┼ ── ─ ┤
│ B │ move one word left separated by spaces │
├ ── ─ ┼ ── ─ ┤
│ 0 │ move to the beginning of the line │
│ Ctrl-F │ flip forward │
├ ── ─ ┼ ── ─ ┤
│ Ctrl-B │ flip back │
├ ── ─ ┼ ── ─ ┤
│ NG │ to line n │
├ ── ─ ┼ ── ─ ┤
│ G │ to the last line │
└ ── ─ ┴ ── ─ ┘
Insert a text command:
┌ ── ┬ ── ─ ┐
│ Command │ description │
├ ── ┼ ── ─ ┤
│ I │ insert text before the current character │
├ ── ┼ ── ─ ┤
│ I │ insert text at the beginning of the line │
├ ── ┼ ── ─ ┤
│ A │ add text after the current character │
├ ── ┼ ── ─ ┤
│ A │ add text at the end of the line │
├ ── ┼ ── ─ ┤
│ O │ insert an empty row behind the current row │
├ ── ┼ ── ─ ┤
│ O │ insert an empty row before the current row │
├ ── ┼ ── ─ ┤
│ R │ input text in rewrite mode │
└ ── ┴ ── ─ ┘
DELETE command:
Ndw or ndW: n-1 characters starting at and following the cursor
Do: Delete to the beginning of a row
D $: Delete to the end of the row
Ndd: Delete the current row and the next n-1 row
X or X: delete a character. x deletes the character after the cursor, and X deletes the character before the cursor.
Move command:
┌ ── ─ ┬ ── ─ ┐
│ Command │ description │
├ ── ─ ┼ ── ─ ┤
│ $ │ To the end of the line │
├ ── ─ ┼ ── ─ ┤
│ (│ To the beginning of a sentence │
├ ── ─ ┼ ── ─ ┤
│) │ To the end of the sentence │
├ ── ─ ┼ ── ─ ┤
│ {│ To the beginning of a paragraph │
├ ── ─ ┼ ── ─ ┤
│ }│ To the end of the section │
└ ── ─ ┴ ── ─ ┘
Text editing command:
┌ ── ┬ ── ─
│ Life temple │ description │
├ ── ┼ ── ─
│ Yy │ move a line of text to the default buffer │
├ ── ┼ ── ─
│ Yn │ move the next word to the default buffer │
├ ── ┼ ── ─
│ Ynw │ move the next n words to the default buffer │
├ ── ┼ ── ─
│ P │ if the default buffer contains a line of text
│ Insert an empty line well behind the row to inject the sound in the default buffer zone │
│ Paste to this line; if the default buffer contains │
│ Multiple words, paste these words to the right of the cursor. │
├ ── ┼ ── ─
│ P │ if the default buffer contains a line of text, the current │
│ Insert an empty hole in front of the row to insert the default buffer zone │
│ Paste to this line; if the default buffer contains │
│ Multiple words, paste these words to the left of the cursor │
└ ── ┴ ── ─