Advanced searching in Vim

笑着哭i 提交于 2020-01-12 07:37:06

问题


Is there a way to search for multiple strings simultaneously in Vim? I recall reading somewhere that it was possible but somehow forgot the technique.

So for example, I have a text file and I want to search for "foo" and "bar" simultaneously (not necessarily as a single string, can be in different lines altogether).

How do I achieve that?


回答1:


/^joe.*fred.*bill/          : find joe AND fred AND Bill (Joe at start of line)
/fred\|joe                  : Search for FRED OR JOE



回答2:


Actually I found the answer soon after I posted this (yes I did google earlier but was unable to locate it. Probably was just searching wrong)

The right solution is

/(foo\|bar)

@Paul Betts: The pipe has to be escaped




回答3:


Vim supports regular expressions by starting in command mode with a '/'.

So using something like "/(foo\|bar)" (as was stated before) would solve the problem. It's good to know why that works and what you are using (regular expressions).




回答4:


/(foo|bar)


来源:https://stackoverflow.com/questions/131559/advanced-searching-in-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!