VIM: combine two searches
Often I do a search for something (using hotkeys, menu command or commandline) and after that I want to keep the first search and add another search..
p.e.
- First I search doubles spaces in my text. - Then I want to keep the matches and add the search all end of line space开发者_如何学编程sIs there a way to combine 2 searches?
1) search 1
2) press F9 or other key: ADD 3) search 2You can do this:
exe '/\('.histget('/',-1).'\)\|\('.newSearch.'\)'
where newSearch is your new search string. A nice way of doing it is just do the searches separately to make sure you get what you want and then combine them with:
exe '/\('.histget('/',-1).'\)\|\('.histget('/',-2).'\)'
You can do this repeatedly to build quite long search strings, since it builds a new search string in the history.
This just or's the searches together, which isn't quite the same as what you asked, (since it doesn't keep the same matches). It just concatenates the search criteria--but I suspect it's what you meant.
You could just press Esc then \ then Up-Arrow to scroll back through your searches and edit your previous search to include the extra term. So the first Up-Arrow will show your last search.
Example
You wanted to search for the text _pipe(
so you typed:
Esc /_pipe(
You now want to add to that search and decide that as well as _pipe(
it would be useful to only include the ones with the argument option
so you type:
Esc / Up-Arrow
and then edit your previous search to read /_pipe(.*option.*)
This now uses the new search which is updated from the previous search.
In Normal mode, you can use the last search register ("/
)to recall your last search pattern:
/<C-r>/\|\(\[ ]\+$\)
Breaking it down:
<C-r>
is CTRL + r, it will bring up a"
so you can choose a register,- / to choose the search register,
\|
to add another pattern in your search (OR
),\(\[ ]\+$\)
search for and group trailing spaces.
精彩评论