Vim editor Basics

Source: Internet
Author: User
Tags exit in

Vim Editor


Question 1: What is the difference between word processors in a text editor?

The text editor only processes plain ASCII files.


Nano (full screen editing), sed (line, command line)


Question 2: What is Vi?

VI: Visual Interface

VIM: VI improved (enhanced version of VI)


VI: Full Screen Editor and model Editor


Vim mode:

Edit mode (command mode)

Input mode

Last Row Mode


Mode Conversion:

Edit --> input:

I: Switch to input mode before the character of the current cursor;

A: After the character of the current cursor, convert it to the input mode;

O: at the bottom of the row where the current cursor is located, create a new row and convert it to the input mode;

I: Switch to input mode at the beginning of the row where the current cursor is located

A: At the end of the row where the current cursor is located, convert it to the input mode.

O: Create a new row above the row where the current cursor is located and convert it to the input mode;


Enter --> EDIT:

ESC

Edit --> last line:

:


Last line --> EDIT:

ESC, ESC


I. How to Use Vim to open a file

# Vim/path/to/somefile

VIM + #: open the file and locate it in line #

VIM +: open the file and navigate to the last line.

VIM +/pattern: open the file and locate the beginning of the line that is matched by pattern for the first time.


The editing mode is used by default.


Ii. How to Use Vim to close files

1. close the file in the last line.

: Q exit

: WQ save and exit

: Q! Do not save and exit

: W save

: W! Force save

: WQ -->: x

2. Exit in edit mode

ZZ: Save and exit


3. move the cursor (editing mode)

1. move by character:

H: left

L: Right

J: Bottom

K: Upper

# H: move # characters;

Upper, lower, and left: kjhl can be used with the number key,

 

2. Move words in editing mode)

W: Move to the beginning of the next word

E: jump to the end of the current or next word

B: Jump to the beginning of the current or previous word

# W:

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: Last line

In the last row mode, you can directly give the row number.

Iv. Screen flip

CTRL + F: Flip down the screen

CTRL + B: Flip the screen up


CTRL + D: Flip down half screen

CTRL + u: half screen up


5. delete a single character

X: delete a single character at the cursor

# X: Delete the cursor at and back # characters in total


Vi. delete command: d

D. Use commands in combination with jump commands;

# D jump command range

# DW, # de, # DB


DD: deletes the row where the current cursor is located.

# DD: Delete the rows that contain the current cursor;


In the last row mode:

Startadd, endaddd

.: Indicates the current row.

$: Last line

+ #: Downward # Rows

-#: Up # Line


The last n items deleted by VIM will not be deleted immediately and will be saved to the buffer;

In addition, the last deleted content can be pasted to other places you specified.


7. paste command P

P: If the row content is deleted or copied as the whole line content, paste it below the row where the cursor is located. If the deleted or copied content is not the whole line content, paste it behind the character where the cursor is located.

P: If the row content is deleted or copied as the whole line content, paste it above the row where the cursor is located; if the deleted or copied content is not the whole line content, paste it before the character where the cursor is located.


8. Copy command y

The usage is the same as that of the d command. The D command is delete, and the y command is copy;


9. Modify: Delete the content first and then convert it to the input mode.

C: Same as the D command


10. Replacement: R

R: Enter the replacement mode directly.

ESC: exit the replacement mode.


11. Cancel the edit operation u

U: cancels the previous edit operation.

Consecutive U commands may cancel n previous operations

# U: directly undo # operation

What if I undo more?

Restore the last Undo operation: Ctrl + R


12. Repeat the previous edit operation

.


XIII. Visualization Mode

V: select by character

V: select by rectangle


14. Search

/Pattern

? Pattern

N: Down

N: Up

15. Search for and replace

Use the S command in the last line mode

The usage is exactly the same as SED


Addr1, [email protected] @ [email protected]


Vim editor Basics

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.