Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search in VS Code for multiple terms

Suppose I search on VS Code the terms 'word1 word2'. Then it finds all the occurrences where 'word1' is followed by 'word2'. In reality I want to find all the files where word1 and word2 occur, but they don't have to be consecutive. How can I do it?

like image 641
becko Avatar asked Apr 20 '18 14:04

becko


People also ask

How do I search multiple files in VS Code?

VS Code allows you to quickly search over all files in the currently-opened folder. Press Ctrl+Shift+F and enter in your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location.

How do you select multiple times in VS Code?

“select multiple in vs code” Code Answer'sWindows: Ctrl + Alt + Arrow Keys. Linux: Shift + Alt + Arrow Keys. Mac: Opt + Cmd + Arrow Keys.


3 Answers

Use regex flag and search for (word1[\s\S\n]*word2)|(word2[\s\S\n]*word1)


Made a small extension based on @tonix regex:

https://marketplace.visualstudio.com/items?itemName=usernamehw.search

like image 188
Alex Avatar answered Oct 08 '22 11:10

Alex


Here is also a simple way for simple needs - use this as regex

(word1)|(word2)|(word3)  

It may not cover some cases, but has been working fine for me, and easy to remember to type it in.

like image 32
Kirill Yunussov Avatar answered Oct 08 '22 12:10

Kirill Yunussov


VSCode has an open issue to support multiple searches. You may want to get on there and push them a little.

like image 11
pushkin Avatar answered Oct 08 '22 12:10

pushkin