Ethan
Ethan

Reputation: 9768

Vim: Can you delete a specific line number from another line?

I was on line 93 and realized I wanted to delete line 89. I typed :d89 in hopes that line 89 wold be deleted. It didn't work.

Does anyone know a good way to accomplish this type of interaction? I am a comfortable Vim user but have not (yet) taken the leap to writing plugins...

Thanks.

Upvotes: 44

Views: 23570

Answers (3)

Nick Podratz
Nick Podratz

Reputation: 682

What you're searching for is probably

:89d|'`

The | chains commands together.

Upvotes: 1

ZhaoGang
ZhaoGang

Reputation: 4915

:89d will delete the 89th line.

:89,91d will delete the 89th 90th and 91st line.

These functions also work in the Vrapper plugin for Eclipse, and the Vim Extension for Visual Studio Code.

Upvotes: 21

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143334

The address of a colon-command (eg: the line number) comes first.

:89d

Note that this will also cause you to navigate to the location of the change. You can use `` to jump back.

If you'd prefer to have this be a single command you can define a custom command. eg:

command! -range -nargs=0 Delete <line1>,<line2>d|norm ``

This defines a command called Delete that deletes the addressed range (<line1>,<line2>d) and then navigates back (norm ``).

You can call it like:

:89Delete

You can actually invoke it with any unique prefix, so you may be able to get it down to:

:89D

Upvotes: 73

Related Questions