44

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.

3 Answers 3

70

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
6
  • hum... why not simply try the suggestion and see what happens? Dec 13, 2011 at 19:42
  • +1, well the command here consists of the "address" (which may be a line number) and the command. Dec 13, 2011 at 19:44
  • @Ethan The behavior is similar to navigating to 89 and then deleting it. This is pretty common behavior for colon-commands. :s leaves you on the line of the last substitution, for example. Dec 13, 2011 at 19:46
  • Excellent - thanks for the fix. Any modifications that can skip/reduce the '' requirement?
    – Ethan
    Dec 13, 2011 at 19:55
  • @Ethan '' is a little easier to type, but it doesn't preserve the column position. You could also define a custom command if you wanted to. See update to answer. Dec 13, 2011 at 23:21
20

: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.

0
1

What you're searching for is probably

:89d|'`

The | chains commands together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.