Linux VIM Editor

Source: Internet
Author: User
Tags set background

Commonly used vim operation self-summary, the great god please avoid:

Vim Open Exit Save

Open it:
Open Vim Practice_1.txt directly
You can also open vim first, after: E file path

Save:
: W file name
or exit Save: wq!

Exit Vim:shift+zz in Normal mode

Vim moves and enters insert mode

Move:
W Next word
B Previous Word

Enter insert mode
Command description
I edit at the current cursor
I Insert at the beginning of the line
A inserts at the end of A row
A inserts an edit after the cursor
o Insert a new row after the current line
O insert a new row before the current line
CW replaces characters from the position of the cursor to the end of a word

Vim selection mode

V (lowercase), enter character selection mode
Shift+v (lowercase), enter row selection mode
Ctrl + V (lowercase), which is the area selection mode, allows you to select a rectangular region,
Enter d in Visual mode to delete the selection area
Enter Y in visual mode to copy the selection area

Vim inline jump and inline jump

NG jumps to nth row
GG First Line
G Last line
Ctrol + O jumps to the position of the previous jump, can repeat similar history

Command description
W to the beginning of the next word
E to the end of the next word
B to the beginning of a previous word
GE to the end of the previous word
0 or ^ to the wardrobe
$ to end of line
f< Letters > backwards search < letters > and jumps to the first matching position (very useful)
f< Letters > forward Search < letters > and jumps to the first matching position
t< Letters > Backward Search < letters > and jumps to a letter before the first matching position (not commonly used)
t< Letters > forward Search < letters > and jumps to a letter after the first matching position (not commonly used)

Vim Copy and paste

Y copy
In normal mode, yy copies the entire row of the cursor (3yy means copy 3 rows)
In normal mode, y^ is copied to the beginning of the line, or y0. Does not contain the character at which the cursor is located.
In normal mode, y$ is copied to the end of the line. Contains the character at which the cursor is located.
In normal mode, yw copies a word.
In normal mode, y2w copies two words.
In normal mode, YG is copied to the end of the text.
In normal mode, y1g is copied to the beginning of the text.
P Paste
In normal mode, the P (lowercase) representation is pasted to the cursor (bottom)
In normal mode, the P (uppercase) represents the paste to the front of the cursor (top)
D Cut

Vim Delete shortcut keys

Command description
x Delete the character that contains the cursor
X Delete the previous character of the cursor
Delete with X
DD Delete entire row
DW Delete a word (not in Chinese)
d$ or D Delete to end of line
d^ Delete to the beginning of the line
DG deleted at end of document
D1G Delete to document header

command preceded by a number indicating a repeat operation
2dd

Vim Multi-file editing

Vim 1.txt 2.txt
Open new file after entering vim

Input in command line mode: E 3.txt open new file 3.txt
Input in command line mode: e# back to the previous file
Input in command line mode: LS to list previously edited documents
Command line mode input: B 2.txt (or number) can be directly into the file 2.txt edit
Input in command line mode: BD 2.txt (or number) can delete file items from previously edited list
Input in command line mode: e! 4.txt, new Open file 4.txt, discard the file being edited
Input in command line mode: F Displays the file name being edited
Command line mode input: F new.txt, change the file being edited name to New.txt

If the document is not saved due to a power outage, you can use the recovery method, Vim-r Enter the document, enter: Ewcover 1.txt to restore
$ vim-r 1.txt

Vim Display line number

: Set Nu

Vim replacement

r+< to replace letter > replace cursor with specified letter
R is continuously replaced until ESC is pressed
CC replaces the entire row, which deletes the row of the cursor and enters insert mode
CW replaces a word, which deletes a word and enters insert mode
C (uppercase) Replace cursor later to end of line
~ Reverses the case of the cursor in the same letter
U{n} undo once or N operations
U (uppercase) undo all changes to the current line
Ctrl+r redo, that is, undo undo operation

Vim Finder

/ICMP looking backwards for ICMP
? TCP Forward Lookup TCP
N Next
N moves to the previous

Vim Repeat command

.
You can also enter a number before the command

Vim internal Execution External command

Input!
:!ls to display the contents of the current directory
:!RM filename is used to delete a file named filename
: W FILENAME to save the file you are editing in the current VIM as a filename file

Vim text alignment

: CE
: RI
: le

Vim Document Encryption

Vim-x file1

Vim Indent

>>
<<
To view the settings:
Set shiftwidth?
Set the value:
Set shiftwidth=10

Vim settings

2.7.1 Vim's function setting
Vim configuration file ~/.VIMRC (configuration file in lab building environment/ETC/VIM/VIMRC), can open file for modification, but be careful not to affect the normal use of vim

2.7.2 Get the current settings

Input in command line mode: Set or: SE shows all modified configurations
Input in command line mode: Set all displays all SetPoint values
Input in command line mode: SET option? Display the Set value of option
command-line Mode input: Set nooption cancel the current set value
2.7.3 description of the Set function

Input in command line mode: Set Autoindent (AI) settings Auto Indent
command-line Mode input: Set Autowrite (AW) Sets AutoArchive, default not open
Input in command line mode: Set Background=dark or light, setting the background style
Command line mode input: Set backup (BK) sets automatic backup, default is not turned on
Input in command-line mode: Set Cindent (CIN) Set C language style indentation

Linux VIM Editor

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.