Vim Common Operations Summary: Set line number, delete, exit, etc.

Source: Internet
Author: User



1. Set the line number



VIM Displays the line number when it is opened by default, so that you can display the line number manually in command mode without having to edit it each time.



To create a configuration file for a. vimrc.



When Vim is started, the. vimrc file under the current user's root directory is automatically read, and the file can contain settings and even scripts, so it is generally convenient to create a. vimrc file under the current user's root directory, which is created as:



$vi ~/.VIMRC



Add content to File: Set number, save exit.






2. Select all, copy all, delete all



Select All (Highlight ): Press ESC, then GGVG or GGVG



Copy all: press ESC, then GGYG



Delete all: press ESC, then DG



Analytical:


gg: move the cursor to the first line, it is valid in vim, invalid in vi
v: enter the Visual mode
G: Move the cursor to the last line
After selecting the content, you can perform other operations, such as:
d Delete selected content
y Copy the selected content to register 0
"+ y Copy the selected content to the + register, which is the system's clipboard, for other programs





1. Open a file first:



Vim filename



2, go to the end of the file:



Enter G in command mode



3, go to line 10:



Enter 10G in command mode



4. Delete all content: First go to the end of the file with G, then use the following command:



: 1,. D



5, delete the contents of line 10th to 20th: First use 20G to go to line 20th, then use the following command:



: 9,. D



6, some notes about the deletion:



6.1 in VI, ". "Represents the current line," 1,. " Represents the deletion from the first row to the current row and "D".



6.2 If you just want to delete a row, point the cursor to the line and then enter D D.






3. Multiple ways to exit vim



Click the ESC key and Vim enters command mode. Then enter:


: q-Quit (this is short for: quit)
: q!-exit without saving (this is short for: quit!)
: wq-write to file and exit; (this is short for: writequit)
: wq!-(if the file only has read permission) write and exit (if the file does not have write permission, force write)
: x-similar to: wq, if the file has no changes, it will not be written
: qa-Quit all (this is short for: quitall)
ZZ —— (uppercase Z) If the file is changed, write / save and then exit;
ZQ —— If you do not want to save the file, you can also use this command to exit; 


In fact, Vim has a very detailed help, enter the command mode after the input and then enter.



Vim Common Operations Summary: Set line number, delete, exit, etc.


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.