In VIM, I want to delete any lines that are not 2 or 3 characters.
:g/^..$/d
:g/^...$/d
Those delete 2 or 3 character lines. How to combine the two into one and negate it, namely 'don't delete 2 or 3 character lines'
In VIM, I want to delete any lines that are not 2 or 3 characters.
:g/^..$/d
:g/^...$/d
Those delete 2 or 3 character lines. How to combine the two into one and negate it, namely 'don't delete 2 or 3 character lines'
You can use :v to execute a command on lines that do not match a pattern.
This requires that you use a single pattern though... Which in your case you can easily do by using the \= modifier to optionally match the last item.
So to delete all lines with either 2 or 3 characters, you can use:
:g/^...\=$/d
And to delete all lines except those with either 2 or 3 characters:
:v/^...\=$/d
Following would be my regex of choice
:v/\v^.{2,3}$/d
Options: Case insensitive
How about "delete all lines with less than two or more than three characters"?
:g/^.\{,1}$\|^.\{4,}/d