如何在vim中搜索所有大写的单词?

时间:2022-09-13 09:40:24

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 *, but it doesn't work on vim.

我想在一个文件中搜索所有的大写字母,但是我不知道怎么做(或者如果可能的话)。我在*上找到了这个解,但是它在vim上不起作用。

3 个解决方案

#1


22  

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

从命令模式,假设您没有选择ignorecase集:

/\<[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

查找任何大于字数边界的大写字母字符串。第二种形式使用“very-magic”。详情:帮助魔术

#2


20  

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

最简单的答案:/ \ < \ \ u + \ >

#3


1  

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
  • getline(1, '$')返回当前缓冲区中所有行的列表
  • join(lines, ' ') that flattens this list of lines
  • 连接(行,' ')使这个行列表变得平坦
  • split(all_text, separators_regex) that build a list of word-like elements
  • split(all_text, separators_regex),用于构建类似单词的元素列表
  • and finally filter(words, uppercase-condition) that selects only the uppercase words.
  • 最后筛选(单词,大写条件),只选择大写的单词。

#1


22  

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

从命令模式,假设您没有选择ignorecase集:

/\<[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

查找任何大于字数边界的大写字母字符串。第二种形式使用“very-magic”。详情:帮助魔术

#2


20  

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

最简单的答案:/ \ < \ \ u + \ >

#3


1  

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
  • getline(1, '$')返回当前缓冲区中所有行的列表
  • join(lines, ' ') that flattens this list of lines
  • 连接(行,' ')使这个行列表变得平坦
  • split(all_text, separators_regex) that build a list of word-like elements
  • split(all_text, separators_regex),用于构建类似单词的元素列表
  • and finally filter(words, uppercase-condition) that selects only the uppercase words.
  • 最后筛选(单词,大写条件),只选择大写的单词。