Visual studio code - how to copy search results? - visual-studio-code

Does Visual Studio Code have any way to copy the results of a search into a new window?
As a bonus, I'd really like to be able to drop the file name and just copy the lines containing the text of my search results to a new window.
For example, I'd like to to be able to copy the results of the search below to a new editor window. I don't mind if I need to install an extension to do it.

The following works for a single file:
CTRL + F
Type your search string
CTRL + SHIFT + L to select all occurrences found (max. 999)
ESC (or close search dialog with top-right X)
CTRL + I to select whole lines
CTRL + C
Open new file
CTRL + V

VSCode 1.23 added the ability to copy your search results, see release notes: copy search results.
The search results tree context menu includes three new options: Copy,
Copy Path, and Copy All. This was a highly 👍'd request which will
make it easier to share or export your search results.
The results are not very pretty or clickable when copied/pasted, so be forewarned. There is an issue tracking the "copy search results" format (see https://github.com/microsoft/vscode/issues/68877) and it is on the 2019 Roadmap (see https://github.com/Microsoft/vscode/wiki/Roadmap#workbench) so hopefully it will be improved.
Update as of v1.41 you can move your search results to a new editor and easily select all and copy there. After searching (which can work across multiple files); click the "Open in Editor" link, as shown in this demo:
Another advantage of the search editor is that you can get "context" around your search result. So you can get some number of lines before and after the whole line with your search term in it. And, of course, line numbers will be copied too.
And you can just save Ctrl+S the search results editor itself! And cut lines from there. Or add notes. With syntax highlighting. It will ask where you want to save it, defaulting to the folder where you initiated the search. It will be named like yourFolder\yourSearchTerm.code-search.
For more info on the new search editor, see https://code.visualstudio.com/updates/v1_43#_search-editors and

Select all occurrences of current selection
CTRL+SHIFT+L
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf

As of 12/2020 CTRL + SHIFT + L doesn't work (for me)
After search results are rendered, right-click onto the text file and select "Change all occurrences"(or CTRL+F2). This will automatically select the the matched text items. Then you can simply copy it.

This will work for a single file, assuming each line you care about begins with the search text:
1. Highlight your search string
2. CTRL + SHIFT + L to select all occurrences found
3. SHIFT + ↓ to select all of those lines
4. CTRL + C
5. Open a new file
6. CTRL + V

There's now an "Open in editor" button under search inputs

Wrong. Per the document the correct format is to use Right Alt + Enter, the use Ctrl + C and then open a new tab and paste your results with Ctrl + V

Related

how to find 'Find All refernces' in current file only with visual studio code?

when i hit Find All References it try to find all reference in files inside workspace.
i want to use current file only when search 'Find all reference' function in vs code.
i want to search only References in yellow marked file which is currently editing file and don't want to search files all other files like purple X marked area.
Open the find feature with Ctrl + f (or Cmd + f on mac)
Enter the search term and configure your desired case sensitivity/regex usage
Press Ctrl + Shift + L (or Cmd + Shift + L on mac)
All occurrences in the open file will be selected. Press Esc to return focus to the editor.
You can also select the text you'd like to find and press ctrl + d to jump to each reference of that text in the file!
ctrl + shift + f will open search.
Click on the 3 dots (Toggle search details) under search dialog box. [ ... ]
Under file to include, specify the path of the file under which you want to find all the references to the key you're searching.

Is it possible to save the search results of Find in Files in Visual Studio Code? [duplicate]

Does Visual Studio Code have any way to copy the results of a search into a new window?
As a bonus, I'd really like to be able to drop the file name and just copy the lines containing the text of my search results to a new window.
For example, I'd like to to be able to copy the results of the search below to a new editor window. I don't mind if I need to install an extension to do it.
The following works for a single file:
CTRL + F
Type your search string
CTRL + SHIFT + L to select all occurrences found (max. 999)
ESC (or close search dialog with top-right X)
CTRL + I to select whole lines
CTRL + C
Open new file
CTRL + V
VSCode 1.23 added the ability to copy your search results, see release notes: copy search results.
The search results tree context menu includes three new options: Copy,
Copy Path, and Copy All. This was a highly 👍'd request which will
make it easier to share or export your search results.
The results are not very pretty or clickable when copied/pasted, so be forewarned. There is an issue tracking the "copy search results" format (see https://github.com/microsoft/vscode/issues/68877) and it is on the 2019 Roadmap (see https://github.com/Microsoft/vscode/wiki/Roadmap#workbench) so hopefully it will be improved.
Update as of v1.41 you can move your search results to a new editor and easily select all and copy there. After searching (which can work across multiple files); click the "Open in Editor" link, as shown in this demo:
Another advantage of the search editor is that you can get "context" around your search result. So you can get some number of lines before and after the whole line with your search term in it. And, of course, line numbers will be copied too.
And you can just save Ctrl+S the search results editor itself! And cut lines from there. Or add notes. With syntax highlighting. It will ask where you want to save it, defaulting to the folder where you initiated the search. It will be named like yourFolder\yourSearchTerm.code-search.
For more info on the new search editor, see https://code.visualstudio.com/updates/v1_43#_search-editors and
Select all occurrences of current selection
CTRL+SHIFT+L
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
As of 12/2020 CTRL + SHIFT + L doesn't work (for me)
After search results are rendered, right-click onto the text file and select "Change all occurrences"(or CTRL+F2). This will automatically select the the matched text items. Then you can simply copy it.
This will work for a single file, assuming each line you care about begins with the search text:
1. Highlight your search string
2. CTRL + SHIFT + L to select all occurrences found
3. SHIFT + ↓ to select all of those lines
4. CTRL + C
5. Open a new file
6. CTRL + V
There's now an "Open in editor" button under search inputs
Wrong. Per the document the correct format is to use Right Alt + Enter, the use Ctrl + C and then open a new tab and paste your results with Ctrl + V

Open already opened file in a different editor group in Visual Studio Code

What I am looking for is a way to do the following in Visual Studio Code:
Go to Definition on a symbol (which often opens a new file in the same editor group)
Open this newly opened file in a editor group next to current
... and switch back to the original file
Is there a command / key binding that would let me do 2nd bullet item?
Short Answer
Ctrl + Alt + → does that on Windows.
Details
This is my normal flow:
F12 to go to a symbol definition.
Ctrl + Alt + → to open the file on the right.
On Linux or iOS
Find the equivalent shortcut by opening File > Preferences > Keyboard Shortcuts (or running Open Keyboard Shortcuts in the command palette), and searching for these two commands:
workbench.action.moveEditorToNextGroup
workbench.action.moveEditorToPreviousGroup
If you are here, like me, looking for a way to open files in the next group, by Ctrl + Click.
Then adding Alt to the combination may do the trick. My VSCode version is 1.60.
!IMPORTANT: The new tab opened via Ctrl + Alt + Click, will always be to the right of the current. So, if you have already opened two groups, then move the tab to the left to have new tabs at the right, otherwise it will create third group.
in mac os you can use this key binding cmd + \
in windows you can use this key binding CTRL + \
I'm pretty sure what you're looking for is a combination of the answers above. I find this works:
Ctrl + \ View: Split Editor
Ctrl + Alt + → View: Move Editor into Next Group
Equivalently
(no default keybinding) View: Split Editor into Right Group
Caveat: if the file is already open in the other editor group, then it will be opened (not "cloned"). There may be a configuration setting to alter this behavior, but I couldn't find one quickly.
The result looks as follows. Suppose you are in some file on the left, and there is another editor group on the right (e.g. after executing Ctrl + \). After running the two commands above, then the currently open file will still be open on the left, but will also be open in the editor group on the right.
Tip: if you don't feel like assigning a keybinding, but would like to access the command (relatively) quickly, just type
Ctrl + Shift + P srg

How to select current word in Visual Studio Code (VS Code)?

How to select the current word, that is where the caret is at.
Note: I am looking for the shortcut for Visual Studio Code(VS Code), the text editor, and not Visual Studio IDE.
On Mac OS: Cmd+D
On Windows & Linux: Ctrl+D
Above solved the purpose for me.
But ⌘D is defined as "editor.action.addSelectionToNextFindMatch", so if you press it more than once, it will try to search and select same word in the file which then can be used to do "multi word editing".
You are looking for Shrink/Expand Selection.
Trigger it with Shift+ Alt+Left and Shift + Alt+Right
Update:
This is now called Smart select API.
This feature uses semantic knowledge to intelligently expand selections for expressions, types, statements, classes, and imports.
It is Ctrl + D that works for me in latest Visual Studio Code on Windows.
Go to File -> Preferences -> Keyboard shortcuts, you will find this:
If you want to ctrl+w to behave the same as in Idea just go keyboard settings
Search for Expand selection. Set new shortcut cmd+w or ctrl+w depending on your OS.
Also re-bind other commands that use ctrl+w to use another shortcut that you want, for example cmd+f4
You can edit keybindings.json to avoid using UI.
Shift + Alt+Right Arrow if the word is in camelCase then you will have to click Right Arrow again to select the whole camelCase. Every time you press Right Arrow again while still holding Shift + Alt down you will select a further part of the code.
so:
first the word.
then if it's part of a camelCase then the camelCase.
then if it is in a string the whole string.
... (many other posibilities)
the whole line.
everything inside the parentheses code block
the whole file
at any given time you can go back to the last selection by clicking Left Arrow instead of Right Arrow
I don't know about CTRL + w in the old Visual Studio Code but in the JetBrains IDE's this is the equivalent to CTRL + w by holding down CTRL and clicking w to select more and holding down CTRL + Shift and clicking w to unselect.
Another possibility which helps to avoid selecting only one word in camelCase is CTRL + d this will just select the whole camelCase. This will however have the side-effect of also changing the current "find" criteria.
thanks Chandan Nayak for this extra shortcut.
An unpopular opinion: you can now have Resharper keybindings, if you come from Jetbrain's camp.
The Ctrl+W expansion grow and shrinks is different from expansion selection.
On "File/Preferences/Keyboard Shortcuts" I deleted the shortcut "Ctrl + W" to close the current tab action, because for this "Ctrl+F4" works for me.
Update (14 days later): Yesterday I installed VSCode 1.34.0 - I think since then the functionality is "Ctrl + D". I was very suprised.
For any editor, you can use the below shortcuts. These shortcuts work for every text area also.
Ctrl + Shift + LeftArrow/RightArrow - this will select text word by word
Shift + UpArrow/DownArrow - this will select text line by line
Ctrl + BackSpace - this will delete text word by word
Additional
in intellijIdea
Ctrl + w - use for the select current word, after giving second Ctrl + W it will select the second word also. Like that you can select the whole line.
Ctrl + d - you can duplicate current line.

Does a "Find in project..." feature exist in Eclipse IDE?

Does Eclipse have a way to search a whole project for some text like Xcode's "find in project" feature?
1. Ctrl + H
2. Choose File Search for plain text search in workspace/selected projects
For specific expression searches, choose the relevant tab (such as Java Search which allows you to search for specific identifiers)
For whole project search:
3. Scope (in the form section) > Enclosing project (Radio button selection).
Ctrl + Alt + G can be used to find selected text across a workspace in eclipse.
OSX: ⌥ Option + ⌘ Command + G
Press Ctrl + H to bring up the search that includes options to search via project, directory, etc.
Ctrl+H.
Also,
Open any file quickly without browsing for it in the Package
Explorer: Ctrl + Shift + R.
Open a type (e.g.: a class, an interface) without clicking through
interminable list of packages: Ctrl + Shift + T.
Go directly to a member (method, variable) of a huge class file,
especially when a lot of methods are named similarly: Ctrl + O
Go to line number N in the source file: Ctrl + L, enter line number.
Ctrl + H is the best way!
Remember to copy the string before you start searching!
You should check out the new Eclipse 2019-09 4.13 Quick Search feature
The new Quick Search dialog provides a convenient, simple and fast way to run a textual search across your workspace and jump to matches in your code.
The dialog provides a quick overview showing matching lines of text at a glance.
It updates as quickly as you can type and allows for quick navigation using only the keyboard.
A typical workflow starts by pressing the keyboard shortcut Ctrl+Alt+Shift+L
(or Cmd+Alt+Shift+L on Mac).
Typing a few letters updates the search result as you type.
Use Up-Down arrow keys to select a match, then hit Enter to open it in an editor.
CTRL + H is actually the right answer, but the scope in which it was pressed is actually pretty important.
When you have last clicked on file you're working on, you'll get a different search window - Java Search:
Whereas when you select directory on Package Explorer and then press Ctrl + H (or choose Search -> File.. from main menu), you get the desired window - File Search:
yes, but you need to open the global search panel. to do so, press the binoculars icon on the top right corner of the IDE.
you can even filter searches by function identifiers, method scopes an etc...
Choose File Search for plain text search in workspace/selected projects
For specific expression searches, choose the relevant tab (such as Java Search which allows to search for specific identifiers)
First customize your search dialog. Ctrl+H. Click on the Customize button and select inly File Search while deselecting all the others. Close the dialog.
Now you can search by selecting the word and hitting the Ctrl+H and then Enter.
yes, but you need to open the global search panel.
to do so, press the binoculars icon on the top right corner of the IDE.
you can even filter searches by function identifiers, method scopes an etc...
There is no way to do pure text search in whole work workspace/project via a shortcut that I know of (and it is a PITA), but this will find references in the workspace:
Put your cursor on what you want to lookup
Press Ctrl + Shift + g
There is very nice tool "Eclipse Quicksearch" available. Checkout SpringSource Update Site for Eclipse i.e: http://dist.springsource.com/release/TOOLS/update/e4.6/ (you can try other versions replacing last part of URL with i.e. e4.4 or e4.5)
It works well with Neon Release (4.6.0). It gives you nice incremental text search with source file preview. I had no issues with it so far.
Usage:
Alt + s "Quick Search Command" opens "Quick Text Search" dialog. You can select whether search should be case sensitive or not. Really good tool.
Ctrl+H is very handy here. I mostly search in the current project, not the whole workspace. To find all occurences in the whole project of a string that is in your current buffer, just select the string press Ctrl+H and hit enter. Easy as that!
Use Resource Filters!
Eclipse will restrict the search result using the Resource Filters defined for your project (eg. right click on you project name and select Properties -> Resource -> Resource Filters). So if you keep getting search hits from parts of your project that your not interested in you could make Eclipse skip those by adding a Resource Filter for them. This is especially useful if you have build files or logs or other temporary files that are part of your projects directory structure, but you only want to search amongst the source code. You should also be aware of that files/directories matched for exclusion in the Resource Filters will not show up in the Package Explorer either, so you might not always want this.
Search and Replace'
Ctrl + F Open find and replace dialog
Ctrl + F / Ctrl + Shift + K Find previous / find next occurrence of search term (close find window first).
Ctrl + H Search Workspace (Java Search, Task Search, and File Search).
Ctrl + J / Ctrl+Shift +J Incremental search forward / backwards.
Type search term after pressing Ctrl+J, there is now search window
Ctrl+shift+O Open a resource search dialog to find any class
What others have forgotten is Ctrl+Shift+L for easy text search. It searches everywhere and it is fast and efficient. This might be a Sprint tool suit which is an extension of eclipse (and it might be available in newer versions)