I want to remove blank and commented lined at one time. I already found the similar question regarding removing blank lines, so for blank lines I use:
:g/^$/d
and for commented lines:
:g/^#/d
I'm curious is there any way to merge these regex in one? Something like
:g/^[$#]/d
but obviously it doesn't work in vim.
:g/^$/d - Remove all blank lines. The pattern ^$ matches all empty lines. :g/^\s*$/d - Remove all blank lines. Unlike the previous command, this also removes the blank lines that have zero or more whitespace characters ( \s* ).
Deleting Multiple Lines in Vi and Vim Instead of simply pressing dd, you can specify the number of lines you want to delete. For example, typing 3dd will delete the next three lines from the file. You can also use wildcard characters in the aforementioned command.
You can try this command:
:g/^\(#\|$\)/d
Or
:g/\v^(#|$)/d
$
matches literal '$' inside [...] (type :help /$
for help)\|
is for alternation\v
is very magic (minimal backslash escape)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With