How does the vim editor delete one or more lines of content
This article mainly explains the "vim editor how to delete one or more lines of content", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "vim editor how to delete one or more lines of content" bar!
Install vim
# installation method in Ubuntu/Debian $sudo apt install vim# installation method in RHEL/Centos #] yum-y install vim
Delete single line content
Move the cursor to the line that needs to be deleted
Press the ESC key to make sure you exit edit mode
Press the d key on the keyboard twice to delete it.
Delete all rows
Here are three ways to delete
The first way
Press the ESC key to make sure you exit edit mode
Press the g key on the keyboard twice to move the cursor to the first line of the text
Then press the d and G keys on the keyboard. Where the d key is lowercase and the G key should be switched to uppercase.
So you can delete everything.
The second way
Press the ESC key to make sure you exit edit mode
Press: colon key, (shift +;) and you can type: colon.
Then type 1 _
The third way
Press the ESC key to make sure you exit edit mode
Click: colon key, shift +; you can type: colon.
Then enter d. % represents all lines in the file.
Delete multiple Lin
Move the cursor to the line that needs to be deleted
Press the ESC key to make sure you exit edit mode
Add the number of rows to delete before the dd command. For example, if you want to delete 3 lines below line 4, press 3 dd
Delete rows in a given range
Example one
If you want to delete a specified range of lines, such as lines 3 to 5, press ESC, then type the following command, and then enter.
: 3,5d
Example two
Delete the last line, press ESC, then enter the following command, and then press enter.
: $d
Example three
Delete all rows before the current line
: 1mem.Murray 1D
Example 4
Delete all lines after the current line
:. + 1.
Delete rows by conditional matching
Example one
Delete the line that contains the text keyword
: g/text/d
Example two
Delete lines that do not contain # keywords
:% ginkgo Universe Universe d # or: v Universe d
Example three
Delete comments that are opened with #.
: G / ^ # / d
Example 4
Delete all blank lines
: G / ^ $/ d
Summary
Vim has many useful features, including support for regular expression search, the ability to easily repeat commands, direct recording and execution of macros, autocomplete, file merging, mouse integration, spell checking, syntax highlighting, branch undo / redo history, support for popular network protocols and file archive formats.
Thank you for your reading, the above is the "vim editor how to delete one or more lines of content" of the content, after the study of this article, I believe you on the vim editor how to delete one or more lines of content this problem has a deeper understanding, the specific use of the need for you to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!