There's a few "how do I invert a regexp" questions here on Stack Overflow, but I can't find one for vim (if it does exist, my Google-fu is lacking today).
In essence I want to match all non-printable characters and delete them. I could write a short script, or drop to a shell and use tr or something similar to delete, but a vim solution would be dandy :-)
Vim has the atom \p
to match printable characters, however trying to do this :s/[^\p]//g
to match the inverse failed and just left me with every 'p' in the file. I've seen the (?!xxx)
sequence in other questions, and vim seems to not recognize this sequence. I've not found seen an atom for non-printable chars.
In the interim, I'm going to drop to external tools, but if anyone's got any tricks up their sleeve to do this, it'd be welcome :-)
Ta!
Unfortunately you can't put \p
in character classes, although that would be a nice feature. However you can use the negative-lookahead feature \@!
to build your search:
/\p\@!.
This will first make sure that the .
can only match when it is not a \p
character.
I'm also a little puzzled why you can't use the \p. But, [:print:] works fine:
:s/[^[:print:]]//g
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