Suppose I have 50 lines in my vim editor and I have to delete particular lines (5,9,16,28) in a single command.
2 Answers
: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
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 ... .:ddeletes 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).