1

I am editing a tex file using vim, searching for words starting with capital letters, as they are most likely proper names or names of works to which I'd like to add some formatting and/or indexing commands. Now /\u\l\l will catch the beginning of words with a capital letter, but not if one of them has diacritics on them, such as "Wṛhaspatitattwa", where the dot under the r breaks it. How can I extend my search to also match such kind of letters?

4

If you are using the new regex engine (you most likely are), then /[[:upper:]][[:lower:]][[:lower:]] will work for all of the following cases:

Śiva
Śiva
Wṛhaspatitattwa

Note the difference between the first and second- one is a single unicode code-point which is two bytes when encoded in utf-8, the other uses a combining acute.

Not all of the [[]] character classes work as you'd expect with higher unicode characters, but lower and upper are documented as working under :help [:upper:].

2

It depends on exactly how careful you want to be with your matches, but there are many options. The simplest would be to just replace \l with \U (any non-uppercase character):

/\u\U\U

Unfortunately this also catches Capitol letters followed by e.g. whitespace, so we could use

/\u\(\U\U\)\&\(\S\S\)

which requires the next two characters after the capitol letter be both non uppercase letters and non whitespace characters. I might use a solution such as

/\u[^A-Z[:space:][:punct:]]\{2,}

This matches an uppercase character followed by at least 2 of any character that isn't an uppercase character, whitespace character or punctuation mark, so it will match entire words. However there are many ways of getting almost the same goal with slightly different results.

Edit: As mentioned, none of these solutions take into account the possiblity of the first character having a diacritic mark.

2
  • The first letter, in capital, could also contain a diacritical combination, such as in Śiva.
    – muk.li
    May 6 '18 at 20:47
  • 1
    True, I did not take that case into account. The other answer apparently solves that case however. May 6 '18 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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