Vim 20 common commands

Source: Internet
Author: User
1. W [file name] is equivalent to saving
2. R [file name]: add the content of [file name] to the end of the line with the cursor
3. N1, N2 W [filename] Save the content from N1 to N2 as [filename]
4. 50dd delete 50 rows of 5X Delete 5 Characters
5. Move 20 rows down under 20
6. 50 GB move to 50th rows
7. 20 move 20 places right to the right
8./word search for word strings
9. Text replacement
: 50,100 S/man/g replace man between 50 and 100 rows with man
: S/str1/str2 Replace the first str1 of the current row with str2 -- S represents the current row
: S/str1/str2/g replace all str1 in the current row with str2 -- S represents the current row G represents all the global
: M, NS/str1/str2 Replace the first str1 from row n to row N as str2
: M, NS/str1/str2/g replace all str1 from row n to the last row as str2
: % S/str1/str2/g replace all str1 in the text as str2

10. U recovery
11. Copy n rows of P and paste nyy
12. gg first line G last line
 
13.: tlist OPEN function list Ctrl + WW to complete window switching, close the same tlist
Copy and delete a block
V character selection
Select row v
CTRL + V Block Selection
Y copy P paste D Delete
 
14. open multiple texts at the same time
Open one first and separate the command line SP itself
SP [filename]: Separate one
CTRL + W + upper/lower switch window
Exit separately Q
 
Vim file1 file2
: N
: N.
: F: displays the name of the document being edited.

15. Select and copy/delete all Vim files
Delete all: Press ESC and then DG
Copy all: Press ESC and then ggyg
 
16. Vim multi-line indent Technique
Keyword: Vim indent
Press V to enter the visual state, select multiple rows, and indent or contract with '>' or '<'
 
17. display the tab key (to facilitate observation of the number of tables in Python)
When the file contains the tab key, you cannot see it. To display it:
: Set list
Now the tab key is displayed as ^ I, and $ is displayed at the end of each line, so that you can find the spaces that may be ignored.
 
Change:
Use the 'listchars' option:
: Set listchars = tab:>-, trail :-
Now, the tab is displayed as ">-", and the extra blank characters at the end of the line are displayed "-".
 
18. Vim multi-line comment and uncomment
 
: 20, 30 s/^/# comment out the lines from 20th to 30. You can also use other characters
: 20, 30 s/^ # // uncomment
// Or/* can be replaced with: 20, 30 s/\ // With/(null) replace \ (\/has two major characters '\')
: S/^ [^ I] \ + // remove the blank characters at the beginning of the line
Use. to indicate the current row.
:., 30 s/^ /#
You can see that the vim command is for the current line, and you can add a range in front of it to target multiple lines.
: CO 12
Copy the current row to the location of row 12.

19. method 2
Add comments to multiple rows
1). CTRL + V visual block mode, select the comment line
2). Insert the annotator in uppercase I, for example //
3) press the ESC key and all comments will be made.


Cancel multi-line comment
1). CTRL + V visual block mode, select Delete Column
2). d. Delete the column.


20. Call the shell command in VIM

:! Command
Do not exit vim and run the shell command to display the command output in the vim command area, without changing the content of the currently edited file.
Example:
1): R! Command
Insert the shell command result to the next line of the current line.

: R! Date
Reads the system time and inserts it into the next row of the current row.


2) start line number, end line number! Command
Enter the content in the range specified by the starting line number and ending line number to shell command for processing, and replace the content in the range specified by the starting line number and ending line number with the processing result.
Example: 62,72! Sort: sorts the content from 62 rows to 72 rows.

: 62! Tr [A-Z] [A-Z], converts 62 rows of lowercase letters into uppercase letters


3): start line number, end line number W! Command
Use the content in the range specified by the start and end line numbers as the command input. Does not change the content of the currently edited File
Example: W! Sort sorts the content from 62 rows to 72 rows, but the sorting result is not directly output to the file being edited, but is displayed in the area where Vim knocks the command.

 
 

Vim 20 common commands

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.