Search

作者: 一口亅 | 来源:发表于2021-05-15 09:42 被阅读0次
  • vimrc中添加配置,不区分搜索的大小写问题
set ignorecase smartcase

如果搜索模式至少包含一个大写字符,则可以搜索不区分大小写的字符串。当您输入所有小写字符时,您可以将两者组合起来,执行不区分大小写的搜索,当您输入一个或多个大写字符时,执行区分大小写的搜索。

  • /hello\C
  • \Chello
    此时这是执行区分大小写,只搜索小写字符

First And Last Character In A Line

^ $

  • /^ hello
  • /hello$

Repeating Search

  • .
  • //

Searching For Alternative Words

  • /hello|hola
    To match both "hello" and "hola"

Setting The Start And End Of A Match

  • /11\zsvim\ze22
    搜索以vim开头,22结尾的中间的11

搜索字符范围

  • [ ]
  • /[0-9a-fA-F]
  • /[^abc]
    搜索除abc外的字符

Searching For Repeating Characters

  • {n,m}
  - {n}精确匹配。/[0-9]\{2\}
  - {n,m} is a range match. matches between 2 and 3 digit numbers: "11" and "111"./[0-9]\{2,3\}
  - {,m} is an up-to match. matches up to 3 digit numbers: "1", "11", and "111"./[0-9]\{,3\}
  - {n,} is an at-least match. matches at least a 2 or more digit numbers: "11" and "111"./[0-9]\{2,\}

预定义的字符范围

\d    Digit [0-9]
\D    Non-digit [^0-9]
\s    Whitespace character (space and tab)
\S    Non-whitespace character (everything except space and tab)
\w    Word character [0-9A-Za-z_]
\l    Lowercase alphas [a-z]
\u    Uppercase character [A-Z]

搜索双引号括起来的短语

/"[^"]\+"
  • "
    匹配第一个双引号。
  • [^"]
    表示除双引号外的任何字符。它匹配任何字母、数字和空格字符,只要它不是双引号。
  • +
    表示一个或多个。由于前面有前缀,Vim将查找一个或多个非双引号的字符。
  • "
    它匹配结束的双引号。

搜索电话号码

/\d\{3\}-\d\{3\}-\d\{4\}

美国的电话号码由一组三位数组成,然后是另外三位数,最后是四位数。

  • \d{3}
    匹配恰好重复三次的数字

可以用:\v来避免输入转义

/\v\d{3}-\d{3}-\d{4}

相关文章

网友评论

      本文标题:Search

      本文链接:https://www.haomeiwen.com/subject/miyljltx.html