[英]Searching for backslash character in vim
How to search word start \\word
in vim. 如何在vim中搜索单词start
\\word
。 I can do it using the find menu. 我可以使用查找菜单来完成它。 Is there any other short cut for this?
这还有其他捷径吗?
Try: 尝试:
/\\word
in command mode. 在命令模式下。
You can search for most anything in your document using regular expressions. 您可以使用正则表达式搜索文档中的大多数内容。 From normal mode, type '/' and then start typing your regular expression, and then press enter.
在普通模式下,键入“/”然后开始键入正则表达式,然后按Enter键。 '\\<' would match the beginning of a word, so
'\\ <'将匹配单词的开头,所以
/\<foo
would match the string 'foo' but only where it is at the beginning of a word (preceded by whitespace in most cases). 将匹配字符串'foo',但仅限于它在单词的开头(在大多数情况下前面有空格)。
You can search for the backslash character by escaping it with a backslash, so: 您可以通过使用反斜杠转义来搜索反斜杠字符,因此:
/\<\\foo
Would find the pattern '\\foo' at the beginning of a word. 会在单词的开头找到模式'\\ foo'。
The reason searching for something including "\\" is different is because "\\" is a special character and needs to be escaped (prepended with a backslash) 搜索包括“\\”在内的内容的原因是不同的,因为“\\”是一个特殊字符,需要进行转义(前缀为反斜杠)
Similarly, to search for "$100", which includes the special character "$": 同样,要搜索“$ 100”,其中包含特殊字符“$”:
Press /
Type \$100
Press return
To search for "abc", which doesn't include a special character: 要搜索“abc”,其中不包含特殊字符:
Press /
Type abc
Press return
Not directly relevant ( /\\\\word
is the the correct solution, and nothing here changes that), but for your information: 不直接相关(
/\\\\word
是正确的解决方案,这里没有任何改变),但是对于您的信息:
If you are for a pattern with many characters with special meaning to regexes, you may find "nomagic" and "very nomagic" mode useful. 如果你是一个具有许多对正则表达式具有特殊意义的字符的模式,你可能会发现“nomagic”和“very nomagic”模式很有用。
/\V^.$
will search for the literal string ^.$
, instead of "lines of exactly one character" ( \\v
"very magic" and the default \\m
"magic" modes) or "lines of exactly one period" ( \\M
"nomagic" mode). 将搜索文字字符串
^.$
,而不是“正是一个字符的行”( \\v
“非常神奇”和默认的“ \\m
”魔术“模式)或”恰好一个句号的行“( \\M
”nomagic“模式)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.