For example:
1. How to delete other rows by retaining only Matching content rows?
: V/pattern/d
: Help: V
2. How to keep Matching content for each row and delete other content in this row
: % S/^. * \ (pattern \). * $/\ 1/g
3. Delete rows containing specific strings
: G/pattern/d
4. delete a row containing a specific string. A prompt is displayed before each deletion.
: % S/^. * pattern. * \ n/C
5. Processing string:/123/456/789/109/example.txt. How can I delete it to the last one/and then get example.txt?
0dte
Explanation: 0 to the beginning of the line
Delete DTE to the First E
6. Processing string:/123/456/789/EF/109/example.txt. How can I delete it to the last one/and then get example.txt?
$ T/D0
Explanation: $ to the end of the line
T/search for the first one from the back/
D0 Delete to the beginning of a row
D/ex and press ENTER
Explanation: D Delete
/Ex found the first ex
Delete full row matching
If the character string starting with a specific row is datetime, you can delete this row in batches by using Vim to open the log file. In command mode, enter the following on the keyboard:
: 0, % S/^ datetime. * // G
In normal mode (Press ESC to enter), press V to enter visualization mode, and then press the left and right keys on the keyboard or H, and press the L key to select text.
Other related commands:
V: select by character. Frequently used mode, so try it yourself.
V: select by row. This is especially useful when you want to copy or move many lines of text.
CTRL + V: select by block. Very powerful. This function is available only in a few editors. You can select a rectangle and the text in the rectangle is highlighted.
It is worth noting that if Vim uses an automatic line feed, VIM regards the content you entered before you press enter, instead of several lines you see, when selecting by block, the block is selected based on the rows in vim.
When selecting a mode, use the arrow keys and commands described above (motion ). For example, vwww will highlight the three words behind the cursor. Vjj will highlight the current line and the following two lines.
Select all methods
V + G + $ select all, but only when the cursor is in the first line of the first letter, and ggvg does not need to be positioned in the first line.