10

English language users probably don't have this trouble, but vim is pretty dumb when it comes to regular expressions. In my case most letters in the Turkish alphabet outside the EN alphabet don't seem to qualify as word characters.

Given a document that contains a Turkish word:

gerçekleşiyor

The search expression

/ger\wek

…will not match the start of the word. For whatever reason ç is not a word character.

This becomes maddening when plugins use \w as part of their regular expression repertoire. A case in point is neocompcache (which I use instead of neocomplete because it in compatible with Neovim). Baring extra matching rule sets for some language syntax, autocomplete only happens in word sized chunks. When I'm writing large amounts of Turkish prose it would actually be handy to have functional autocomplete, but with most words being broken into smaller chunks with the Turkish characters left out it is beyond useless.

How can I convince vim (preferably neovim if it matters) to accept a larger range of characters as "word" characters?

4
  • What encoding and fileencoding are you using?
    – cxw
    Commented Jun 27, 2015 at 11:56
  • @cxw utf-8 across the board. And yes it is set in both those settings.
    – Caleb
    Commented Jun 27, 2015 at 12:22
  • 1
    You've tagged this question as neovim. I would suggest you open an issue in the NeoVim issue tracker, if there isn't one already. This probably won't be fixed in the short-term, but will be down the line... You can also try posting a message to vim_dev about this, but I suspect everyone will agree that something needs to be done, after which nothing changes. Commented Jun 27, 2015 at 14:15
  • @Carpetsmoker Neovim Issue opened.
    – Caleb
    Commented Jul 6, 2015 at 7:59

2 Answers 2

7

\w is explicitly short-hand for [0-9A-Za-z_]. Use \k instead if you want to match Unicode characters outside of that range. For example, /ger\kek matches gerçekleşiyor.

By the way, neocomplete is aware of this but intentionally does not use \k (by default) because of performance concerns. You can change neocomplete's g:neocomplete#keyword_patterns setting. See also:

https://github.com/Shougo/neocomplete.vim/issues/207

6

Looks like there's not an easy way to redefine \w. See, for example, Vim regex matches unicode characters are as non-word and Match word containing characters beyond a-zA-Z.

However, you might be able to use a custom range if you don't mind retyping it regularly (ha): [a-zA-Z\%u00c7-\%u015f]. That will unfortunately match lots of non-Turkish characters as well, but if those characters don't appear in your text, that might be OK.

1
  • 1
    Unfortunately I'm not in control of all the places such regular expressions are used. Any number of plugins make use of \w and hence they all fall down when it comes to this. Rather than patching every since one (if I can even track down the culprits) it would be easier for me to patch vim so that \w works. Bah.
    – Caleb
    Commented Jun 27, 2015 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.