sica07
sica07

Reputation: 4956

How to search for all uppercase words in vim?

I would like to search for all uppercase words in a file but I have no idea how to do it (or if it's possible). I found this solution here on stackoverflow, but it doesn't work on vim.

Upvotes: 18

Views: 16062

Answers (3)

Luc Hermitte
Luc Hermitte

Reputation: 32946

If you want a list of all the matching uppercase words (i.e. you aren't interested in jumping from one word to the other), you can use:

echo filter(split(join(getline(1, '$'), ' '), '\v(\s|[[:punct:]])'), 'v:val =~ "\\v<\\u+>"')

With:

  • getline(1, '$') that returns a list of all the lines from the current buffer
  • join(lines, ' ') that flattens this list of lines
  • split(all_text, separators_regex) that build a list of word-like elements
  • and finally filter(words, uppercase-condition) that selects only the uppercase words.

Upvotes: 1

William Pursell
William Pursell

Reputation: 212248

From command mode, assuming you do not have the option ignorecase set:

/\<[A-Z]\+\>

or

/\v<[A-Z]+>

Finds any string of capital letters greater than length one surrounded by word boundaries. The second form uses 'very-magic'. :help magic for details

Upvotes: 33

agudulin
agudulin

Reputation: 259

The shortest answer: /\<\u\+\>

Upvotes: 26

Related Questions