string 如何在vi编辑器中搜索带有空格和特殊字符的字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34036575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 16:28:10  来源:igfitidea点击:

How to search a string with spaces and special characters in vi editor

stringsearchvimspecial-charactersvi

提问by user5628973

I edit in the vi editor. I want to search in the text for a specific phrase, e.g "Dec 1 15:13:00". I have tried this search string, but it's not working:

我在 vi 编辑器中编辑。我想在文本中搜索特定短语,例如"Dec 1 15:13:00"。我试过这个搜索字符串,但它不起作用:

/Dec\ 1\ 15

How do I search for this string properly? Note that there may be more than one space between the parts.

如何正确搜索此字符串?请注意,部件之间可能有多个空格。

回答by Xavier T.

Numbers and spaces are not special characters so

数字和空格不是特殊字符,所以

 /Dec 1 15 

is enough.

足够。

Generally speaking special characters are escaped with a \. For example, if you search for Dec., you should type /Dec\.

一般来说,特殊字符用\. 例如,如果您搜索Dec.,您应该输入/Dec\.

If you are using Vim, you might also want to check

如果您正在使用 Vim,您可能还想检查一下

:help pattern.txt

And specifically the magicchapter.

特别是magic章节。

If you want to know if magic is set, type :set magic?

如果您想知道是否设置了魔法,请输入 :set magic?

The magic option can change the behavior of pattern matching.

魔法选项可以改变模式匹配的行为。