简体   繁体   中英

How to search only in currently open files in vscode?

I usually work on larger projects with many files that would contain the search query. So I would open the files I want to modify and do a find/replace across all currently opened files. Can this be done in vs code?

The feature I'm looking for is implemented in Notepad++, but I'd prefer not to have to switch editors for this task.

For me somehow it works just by typing ./ in the files to exclude field.

这里

"Search: target particular set of files #20530" located here: https://github.com/Microsoft/vscode/issues/20530

Is tracking a search "scope" such as "all open files".

As of v1.55 this will be enabled by default - the icon will always appear, you do not need to enable the setting mentioned below.

The v1.55 pre-release notes mention a "checkbox", but it isn't in Insiders Build so I think they mean the icon.


This is in the Stable Build v1.53 behind an experimental "flag":

Search > Experimental: Search in Open Editors

It is enabled by default in the Insiders' Build but requires a reload to take effect - so that the relevant option icon will appear. It is not enabled by default in the Stable Build (also requires a reload after enabling).

v1.53 Release Notes :

This release comes with experimental support for searching in open editors, which has been a highly requested feature for some time. This feature is enabled by default in Insiders, and can be enabled with the search.experimental.searchInOpenEditors setting in Stable.

See demo:

在打开的编辑器演示中搜索

As you can see, the icon is at the end of the files to include input so you will have to have that showing (click the three dots ... just below the search options if files to include is not already showing).

I don't think there's a way to do this. You can make a feature request on github. I think an extension could do it though.

As an alternative to using Visual Studio Code itself, you can just search the file contents within the folder where unsaved files open in Visual Studio Code are located. This would be in one of these locations depending on which OS you are running:

  • Linux: /tmp/ (someone else running Linux can verify this)
  • macOS: ~/Library/Application\\ Support/Code/Backups/
  • Windows: %APPDATA%\\Code\\User\\

1.55 版(2021 年 3 月)以来,“要包含的文件”字段中有一个复选框。

The answer was already mentioned (and accepted above) indeed typing ./ in the files to exclude box of the search window will allow you to only search in open files.

However the response mentioned that he was unsure why this worked. VSCode allows you to exclude all files in a directory by writing the directory in the exclude box. The directory . is the directory where VSCode is opened ie the root directory. The filter ./ excludes all files in the VSCodes root directory so all files are excluded. However opened files ignore any exclude filter. So if you exclude all files only the opened files will be searched.

The best way to find something you are searching for within a specific file in vs code would be:

  • Ctrl + p, then pressing @ on the search bar.

It will give you a list of all functions on the file, which makes it easier to track something down.

This extension is what I use for this purpose. You may need to change the keybinding if there is a conflict.

Hit Ctrl + Shift + F and enable the icon at the end of the 'file to include' text field

VS Code 搜索工具栏

I usually work on larger projects with many files that would contain the search query. So I would open the files I want to modify and do a find/replace across all currently opened files. Can this be done in vs code?

The feature I'm looking for is implemented in Notepad++, but I'd prefer not to have to switch editors for this task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM