Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Vim to delete even or odd rows in linux system

Shulou Source: shulou.com Published: 2022-06-01 04:00:08 09月28日 Update

This article mainly explains "how to use Vim to delete even or odd rows in linux system". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to delete even or odd rows using Vim in the linux system.

The method to delete even rows is as follows:

: G / ^ / + 1 d

The gbobal command is used above, and the gbobal command format is as follows:

: [range] global/ {pattern} / {command}

The global command is actually executed in two steps: first, all lines within the specified range of [range] are scanned to mark the lines that match {pattern}; then the {command} command is executed on the marked line in turn, and if the marked line is deleted, moved, or merged in the command operation on the previous matching line, the tag automatically disappears without executing the {command} command on the line. {command} can be an ex command or multiple ex commands separated by | so that we can do a variety of different operations on marked lines or rows addressed from marked lines.

The above command to delete even lines matches all lines and then deletes them interlaced (where + 1 is used to locate on the next line of the current line). Why is it interlaced? Because the second line is deleted when the + 1d command is executed on the first line, and although the second line is marked, it no longer exists, so the command to delete the third line will not be executed.

The command to delete several lines is as follows:

: G / ^ / d | m

The function of m is to remove the tag of even rows to prevent even rows from being deleted.

To delete even lines, you can also use the normal command, which is (the first command is the number of lines):

:% norm jkdd:%norm jdd so far, I believe you have a deeper understanding of "how to delete even or odd rows using Vim in the linux system". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Commands even tags odd system one line content actual method learning different wrong practical deeper superscript function interest multiple multiple practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Shulou Technology Huawei Linux