Vi-vim basic operations

Source: Internet
Author: User

Vi-vim basic operations
Vi-vim Editor: Full Screen Editor and modular Editor


Vim mode:
Edit mode (command mode)
Input mode
Last Row mode (bottom row Mode)

Mode Conversion:
Edit mode --> input mode:
I: Enter it before the character of the current cursor
I: enter at the beginning of the row where the current cursor is located
A: Enter the character behind the current cursor
A: insert the last name of the row where the current cursor is located.
O: Enter the following line in the row where the current cursor is located.
O: Enter the last line in the row where the current cursor is located.
Input mode --> edit mode:
Esc
Edit mode --> last line mode:
:
Last line mode --> edit mode
Esc [Esc]



Open a file
Vim/path/to/file
Vim + N/path/to/file: When opening the file, move the cursor to the beginning of line N
Vim +/path/to/file: When opening the file, move the cursor to the beginning of the line at the end of the file
Vim +/pattern/path/to/file: When the file is opened, the cursor moves to the first line of the 1st matching mode.


Close file
1. close the file in last row Mode
: Q exit
: Q! Force exit without saving
: W save
: W! Force save (only the Administrator has this permission for read-only files)
: Wq save and exit
: X save and exit
2. close the file in edit mode
ZZ save and exit

Move cursor
1. move the cursor character by character
H: move the cursor one character to the left
L: move the cursor one character to the right
J: move the cursor down a line
K: move the cursor up a row
# H the command above can be preceded by a number, it will move the entered number characters.

2. Move in words
W: Move to the beginning of the next word
E: Move to the end of the current word or the next word. If the cursor is not at the end of the current word, It will jump to the end of the current word.
B: Move to the beginning of the current or previous word
# W: Number Unit

3. In-row jump
0: Beginning of the absolute line
^: The first non-blank character at the beginning of the line
$: End of the absolute line

4. jump between lines
# G: Jump to line #
G: Jump to the last line

Screen flip
1. Ctrl + f: Flip the screen forward
2. Ctrl + B: Flip back
3. Ctrl + d: front half screen flip
4. Ctrl + u: half screen flip

Edit command:
1. delete a single character
X: delete a single character at the cursor
# X: Delete the # characters behind the cursor
2. Delete multiple characters
D. How many commands can be deleted in combination with the jump command?
De, db, dw
Dd: delete a row
# Dd: delete # Row

In the last line mode, you can use:
StartADD, EndAddd
.: Indicates the current row.
$: The row at the top
+ #: Downward # Rows


Paste command:
P: If the row is deleted or copied as the whole line, paste it to the bottom of the row where the cursor is located. If the copied or deleted content is not the whole line, paste it after the character where the cursor is located
P: If the row is deleted or copied as the whole line, paste it above the row where the cursor is located. If the copied or deleted content is not the whole line, paste it before the character where the cursor is located

Copy command:
Y: Same as the d command

Delete the content first, and then convert it to input mode -- modify
C: Same as the d command

Replace:
R:

Unedit:
U: undo the previous operation
Can be undone multiple times in a row
# U: directly undo the latest # operation

Undo the last operation:
Ctrl + r

Repeat the previous edit operation:
.

Visualization Mode
V: select by character
V: select by rectangle

Search
/Pattern: forward lookup
? Pattern: backward Lookup

Search and replace
Use the s command in the last line mode
S/pattern/string/g


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.