Vim command mode and input mode switching

Source: Internet
Author: User
Tags modifier save file switches
VI Editor

VI is a screen editor in Unix and Unix-like environments that can be used to create files. VI has two modes of operation: Command mode and text input mode. Start VI need to enter VI, press [SPACEBAR] key and enter the filename after the return. Toggle Mode Key

VI switch from command mode to text input mode. Each key makes vi enter the text input mode in different ways. Press the [ESC] key to return VI from the text input mode back to command mode.

Table 1 lists the command keys and their functions that VI switches from command mode to text input mode.

Table 1 command keys for switching to text input mode

Key

function

I

Enter the body at the left of the cursor

I

Enter the text at the beginning of the line where the cursor is located

A

Enter body text to the right of the cursor

A

Enter the text at the end of the line where the cursor is located

O

Adds a new row to the next line on the line where the cursor is located, at the beginning of the new line

O

Adds a new row to the line on the row that contains the cursor, at the beginning of the new line

Description: 1. The position of the cursor is indicated by a double underline (═).

2. Current line refers to the line where the cursor is located. Exit Command

There is only one way to enter VI, but there are several ways to exit VI, the choice of exit depends on how to handle the edited file.

In addition to the ZZ command, these commands end with the command line: Start with [Return]. Table 2 lists the exit commands and their functions for the VI editor.

Table 2 Exit command for VI Editor

Key

function

: Wq

Save file, Exit VI Editor

: W

Save file, but do not exit VI Editor

: Q

Exit VI Editor

: q!

Do not save file, Exit VI Editor

Zz

Save file, Exit VI Editor

text modifier key

These keys apply only to command mode. Table 3 lists the exit commands and their functions for the VI editor.

Table 3 text modifier keys for the VI Editor in command mode

Key

function

X

Deletes the character specified by the cursor position

Dd

Delete the line where the cursor is located

U

Undo the most recent changes

U

Undo all changes made to the current line

R

Replace one character at the cursor position

R

Replaces the character starting at the cursor position while changing the VI to text input mode

. (point)

Repeat the last modification

Cursor Move Command

In command mode, these keys can move the cursor in the document. Table 4 lists the exit commands and their functions for the VI editor.

Table 4 VI's CURSOR move key

Key

function

h or []

Move the cursor one grid to the left

J or []

Move the cursor down one grid

K or []

Move the cursor up one grid

L or []

Move the cursor one grid to the right

$

Moves the cursor to the end of the line at the current line

W

Move the cursor one word to the right

B

Move the cursor one word to the left

E

Move the cursor to the end of the word

0 (0)

Moves the cursor to the beginning of the current line

[Return] Key

Move the cursor to the beginning of the next line

[SPACEBAR] Key

Move the cursor to the right one

[Backspace] Key

Move the cursor to the left one

 

Note : Avoid the use of cursor keys (arrow keys) in text entry mode. Because in some systems, the cursor key is interpreted as a normal ASCII character. If you use the cursor key in text input mode, the corresponding ASCII character is inserted into the file. cut and paste keys

These keys are used to rearrange the text in the user file, which is available in command mode VI. Table 5 lists the VI Editor's cut and paste keys and their functions.

Table 5 The cut and paste keys for the VI editor

Key

function

D

Deletes the text at the specified location, and coexists in the temporary buffer. You can use the put operator (p or p) to access this buffer

Y

Copies the text of the specified location to the temporary buffer. You can use the PUT operator to access this buffer

P

Places the contents of the specified buffer above the position of the current cursor

P

Places the contents of the specified buffer below the current cursor position

page Key

The page-flipping key is used to scroll through the user's files, which are available in the VI command mode. Table 6 lists the page keys for the VI editor and their functions.

Table 6 The page key of the VI editor

Key

function

[Ctrl-d]

Move the cursor down to the end of the file, usually 12 rows at a time

[Ctrl-u]

Move the cursor up to the file header, usually 12 rows at a time

[Ctrl-f]

Move the cursor down to the end of the file, usually 24 rows at a time

[Ctrl-b]

Move the cursor up to the file header, usually 24 rows at a time

Three common patterns: Normail mode (Command mode), Insert mode (input pattern), and visual mode (view modes).
Switch between command mode and input mode is Append,insert,replace,subsitute AIRS , this memory method is particularly convenient, the English word means air, VIM switches between command mode and input mode just like air, invisible. The

Editing text is nothing more than the basic character input and the position of the toggle cursor, at ordinary times the cursor switch is through the keyboard on the keyboard to achieve the next, the keyboard switch up and down around the cursor is very convenient, but it is not to move from our keyboard gestures, and vim can not move at all, Through the HJKL.
H: Move one position to the left
J: Down line
K: up one line
L: Move to the right position

Related Article

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.