Use VIM to delete even-numbered rows or odd rows in Linux systems _linux

Source: Internet
Author: User

The following methods are used to delete even rows:

: G/^/+1 D

It used: Gbobal command, gbobal command format as follows:

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

The global command is actually divided into two steps: First scans all rows in the range specified by [range], marks the rows that match {pattern}, and then, in turn, executes the {command} command on the tagged row, if the tagged row is deleted in the command action for the previously matched row, Move or merge, the tag disappears automatically, but the {command} command is not executed for the row. {command} can be an ex command, or multiple ex commands separated by |, so that we can do many different things with rows that are marked or addressed from a tag line.

A command that deletes even rows, matches all rows, and then deletes each other (of which +1 is positioned on the next line of the current row). Why is it interlaced? Because the second row is deleted when the +1 d command is executed on the first line, and the second row is marked but no longer exists, the command to delete the third row is not executed.

The commands for deleting several lines are as follows:

: g/^/d|m

The role of M is to remove even-numbered lines of markup to prevent even-numbered rows from being deleted.

Delete several rows of even rows, or you can use the normal command (the first command is a few rows):

:%norm jkdd
:%norm JDD

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.