Vim regex matches unicode characters are as non-word

馋奶兔 提交于 2019-12-24 03:34:37

问题


I have the following text:

üyü

The following regex search matches the characters ü:

/\W

Is there a unicode flag in Vim regex?


回答1:


Unfortunately, there is no such flag (yet).

Some built-in character classes (can) include multi-byte characters, others don't. The common \w \a \l \u classes only contain ASCII letters, so even umlaut characters aren't included in them, leading to unexpected behavior! See also https://unix.stackexchange.com/a/60600/18876.

In the 'isprint' option (and 'iskeyword', which determines what motions like w move over), multi-byte characters 256 and above are always included, only extended ASCII characters up to 255 are specified with this option.




回答2:


I always use:

ASCII                           UTF-8
-----                           -----
\w                              [a-zA-Z\u0100-\uFFFF]
\W                              [^a-zA-Z\u0100-\uFFFF]



回答3:


You can use \%uXXXX to match a multibyte character. In that case…

/\%u00fc

But I'm not aware of a flag that would make the whole matching multibyte-friendly.

Note that with the default value of iskeyword on UNIX systems, ü is matched by \k.



来源:https://stackoverflow.com/questions/19385458/vim-regex-matches-unicode-characters-are-as-non-word

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!