0

Suppose I have 50 lines in my vim editor and I have to delete particular lines (5,9,16,28) in a single command.

  • 1
    Where do you keep track of the line numbers to delete? – Kusalananda Mar 9 at 6:51
2

It's unwieldy to manipulate on separate lines at once, but can be done:

:g/\v%5l|%9l|%16l|%28l/d
  • :g/.../ - Act on lines matching pattern /.../.
  • \v - very magic, less escaping for special characters in regular expressions.
  • %<num>l - match on line number <num> (so %5l|%9l|... matches the 5th line or the 9th line or ... .
  • :d deletes the lines.

If it's just one line, or a range of lines, you could do :<num>d or :<start>,<end>d (e.g., :5d for the fifth line, or :9,16d for the range of lines from 9th to the 16th line (inclusive).

| improve this answer | |
2
:5d|9d|16d|28d

Is how to put four single commands in a row. But better turn it around:

:28d|16d|9d|5d

To keep the numbering constant.


A more flexible way is to use vimscript. Squeezed on one line this is:

:for n in [28,16,9,5] | call deletebufline("%",n,n) | endfor
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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