Common VI commands

Source: Internet
Author: User

Input mode command

Input/Output Method

Command Function
<A> Enter Text behind the cursor
<A> Enter text at the end of the current row
<I> Input text before the cursor
<I> Enter text in the current line
<O> Enter a new row after the current row
<O> Enter a new row before the current row

Cursor movement command

Move cursor

Command Function
<B> Move to the start of the current word
<E> Move to the end of the current word
<W> Move a word forward
<H> Move one character forward
<J> Move up a row
<K> Move a row down
<L> Move one character backward

Delete Operation Command

Delete operation

Command Function
<X> Delete the character of the cursor
<DW> Delete the word with the cursor
<D $> Delete all characters from cursor to end of line
<D> Same as <D $>
<DD> Delete current row

You can add a number before the DELETE command, for example, <5x> to delete five lines.

Change and replace operation commands

Change and replace operations

Command Function
<R> Replace the character of the cursor
<R> Replacement Character Sequence
<CW> Replace a word
<Ce> Same as <CW>
<CB> Replace the previous character of the cursor
<C $> Replace all characters from the cursor position to the end of the line
<C> Same as <C $>
<CC> Replace the current row

Query command

Query

Command Function
</ABC> Forward query ABC
<? ABC> Backward query ABC
<N> Forward Query
<N> Continue backward Query

Copy and paste commands

Copy and paste

Command Function
</YW> Upload the word with the cursor to the clipboard.
<Y $> Hover the cursor to the end of the line into the clipboard
<Y> Same as <Y $>
<YY> Upload the current row to the clipboard.
<P> Paste the content in the clipboard after the cursor
<P> Paste the content in the clipboard before the cursor

File Save and exit VI command

Save and exit vi

Command Function
<: Q> Exit Without saving the package
<: Q!> Do not save mandatory exit
<: W> Save and edit
<: W filename> Store in Filename
<: W! FILENAME> Forcibly saved to file filename
<: WQ> Save and exit
<: X> Same as <: WQ>
<ZZ> Same as <: WQ>

VI user manual access VI command
VI filename: open or create a file and place the cursor at the beginning of the first line
Vi + N filename: open the file and place the cursor at the beginning of line N
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
VI-r filename: a system crash occurred when VI was being edited last time, restoring filename
VI filename... filename: open multiple files and edit them in sequence

Move cursor command
H: move the cursor one character to the left
L: move the cursor one character to the right
Space: move the cursor one character to the right
Backspace: move the cursor one character to the left
K or Ctrl + P: move the cursor up a row
J or Ctrl + N: move the cursor down a row
Enter: move the cursor down a row
W or W: move one word to the beginning of the word to the right of the cursor.
B or B: move one word left to the beginning of the word
E or E: move the cursor right to the end of a word J.
): Move the cursor to the end of the sentence.
(: Move the cursor to the beginning of the sentence.
}: Move the cursor to the beginning of the paragraph
{: Move the cursor to the end of the paragraph
NG: move the cursor to the beginning of line N
N +: move the cursor down n rows
N-: Move n rows above the cursor
N $: move the cursor to the end of line N
H: move the cursor to the top line of the screen
M: move the cursor to the middle line of the screen
L: move the cursor to the last line of the screen
0: (Note the number is zero) move the cursor to the beginning of the current row
$: Move the cursor to the end of the current row

Screen tumble command
CTRL + u: half screen at the beginning of the file
CTRL + D: Flip the half screen to the end of the file
CTRL + F: Flip the screen to the end of the file
CTRL + B; open a screen at the beginning of the file
NZ: Rolls row n to the top of the screen. If n is not specified, the current row is rolled to the top of the screen.

Insert mode command
I: Before the cursor
I: at the beginning of the current row
A: After the cursor
A: At the end of the current row
O: open a new row under the current row
O: open a new row above the current row.
R: Replace the current character
R: Replace the current and subsequent characters until you Press ESC.
S: Starting from the current cursor position, replace the specified number of characters with the input text
S: delete a specified number of rows and replace them with the input text
NCW or NCW: modify a specified number of characters
NCC: modifies a specified number of rows.

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.
CTRL + u: delete text entered in input mode

Search and replace commands:
/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.
: S/P1/P2/G: replace all p1 in the current row with P2.
: N1, N2s/P1/P2/G: replace all P1 from line N1 to line N2 with P2.
: G/P1/S // P2/G: replace all P1 files with P2.

Option settings
ALL: lists all options.
Term: Set the terminal type
Ignorance: Case Insensitive in search
List: displays the stop table (CTRL + I) and end mark ($)
Number: displays the row number.
Report: displays the number of changes made by line-oriented commands.
Terse: displays brief warning information
Warn: No write information is displayed if the current file is not saved when it is transferred to another file.
Nomagic: allows you to use special characters without "\" in search mode.
Nowrapscan: Prohibit VI from searching at both ends of the file and starting from the other end.
Mesg: Allows VI to display the information that other users write to their terminal using write.

Baseline command
: N1, N2 Co N3: copy the content from line N1 to line N2 to line N3.
: N1, N2 M N3: Move the content from line N1 to line N2 to line N3
: N1, N2 D: Delete content from line N1 to line N2
: W: Save the current file
: E filename: open the file filename and edit it.
: X: Save the current file and exit.
: Q: Exit VI.
: Q! : Do not save the file and exit vi
:! Command: execute shell command
: N1, N2 W! Command: The content from line N1 to line N2 in the file is used as the command input and executed. If N1 and N2 are not specified, the entire file content is used as the command input.
: R! Command: place the output result of the command to the current line.

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.