Vim command mode and input mode switching

Source: Internet
Author: User
Tags modifier save file

VI Editor

VI is a screen editor that can be used to create files in Unix and Unix-like environments. VI has two modes of operation: Command mode and text input mode. To start VI, you need to enter VI, press [Spacebar] key and enter the file name.

Toggle Mode Key

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

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

Table 1 command keys for switching to text input mode

Key

Function

I

Enter body on the left of the cursor

I

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

A

Enter text to the right of the cursor

A

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

O

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

O

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

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

2. The 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, and the choice of exit mode depends on how the edited file is processed.

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

Table 2 exit commands for the VI editor

Key

Function

: Wq

Save file, Exit VI Editor

: W

Save the file, but do not exit the VI editor

: Q

Exit VI Editor

: q!

Do not save file, Exit VI Editor

Zz

Save file, Exit VI Editor

Text modifier keys

These keys are only available in 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 specified character at the cursor position

Dd

Delete the line where the cursor is located

U

Undo Recent Changes

U

Undo all changes made to the current line

R

Replaces one character at the cursor position

R

Replaces the character starting at the cursor position, changing the vi to text input mode

. (dot)

Repeat the last modification

Cursor Movement Instructions

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

Cursor movement keys for table 4 VI

Key

Function

h or []

Move the cursor one cell to the left

J or []

Move the cursor down one cell

K or []

Move the cursor up one cell

L or []

Move the cursor one cell to the right

$

Moves the cursor to the end of 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 using the cursor keys (arrow keys) in text input mode. Because in some systems, the cursor keys are interpreted as normal ASCII characters. If you use the cursor key in text input mode, the corresponding ASCII characters are inserted into the file.

Cut and paste keys

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

Table 5 The cut and paste keys of the VI editor

Key

Function

D

Deletes the text at the specified location, coexisting in a temporary buffer. You can use the put operator (p or P key) to access this buffer

Y

Copies the text of the specified position to a temporary buffer. This buffer can be accessed using the put operator

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

Flip button

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

Table 6 VI Editor's paging key

Key

Function

[Ctrl-d]

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

[Ctrl-u]

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

[Ctrl-f]

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

[Ctrl-b]

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

Three common modes: Normail mode (Command mode), Insert mode (input modes) and Visual mode (view mode).
The switch between command mode and input mode has Append,insert,replace,subsitute as AIRS, this kind of memory method is especially convenient, the English word means air, vim switches in command mode and input mode like air, invisible.

Edit text is nothing more than the basic character input and the position of the switch cursor, usually the cursor switch is through the keyboard to the upper and lower left and right keyboard to achieve, the keyboard switching cursor is also very convenient, but is not to move from our keyboard gestures, and vim can be completely without moving, through HJKL.
H: Move left one position
J: down one line
K: Go up one line
L: Move right One position

Vim command mode and input mode switching

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.