开发者

How do I match a range of range combining diacritical marks in Vim?

I have a file, and some lines contain unicode characters with diacritical marks in them. I would like to delete all lines in the file that contain any unicode diacritical accent character (unicode 0x0300 - unicode 0x0362).

I can blow away pretty much any other unicode in the file as range matches like the following function fine:

:g/[{ctrl-v}u0129-{ctrl-v}u0229]/d

But for some reason when the range is in the diacritical range, the diacriticals apply to the range brackets, so I end up with square brackets with accents that dont match anything.

开发者_如何学运维I can however match them one at a time like :g/{ctrl-v}u0301/d, but I'd rather not go through 100 or so iterations to make sure I get them all.

Additionally inverse searches are failing me too. :g/[^ -~]/d will delete every line that contains a character other than those in the range of {space} to tilde, except lines with diacriticals.

Thanks


I think that there is some bug in vim: collections does not match diacritics. You can use alternatives as a workaround:

execute 'g/\('.join(map(range(0x0300, 0x0362), 'printf("\\%%u%04x", v:val)'), '\|').'\)/d'

or

execute 'g/\('.join(map(range(0x0300, 0x0362), 'nr2char(v:val)'), '\|').'\)/d'

should do what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜