Visual Studio Code: How to actually search and replace a word in all files? - visual-studio-code

Env
Ubuntu 16.04
Visual Studio Code v 1.2.1
Problem
I can search occurrences in all files by Ctrl + Shift + F
However, I can't find a way to search and replace occurrences in all files.
Is this a missing(or hidden) feature in Visual Studio Code.

Visual Studio Code v 1.3.0++ has this feature:
Replace functionality can be accessed:
In the Search View by expanding the Search textbox
Using Ctrl + Shift + H, from the Edit | Replace in Files menu
Using Replace in Files command in the Command Palette

VS Code also supports capturing groups when using regex, captured groups (using parenthesis) can be referenced with $1 for the first match, $2 the second etc. $0 returns the complete match.
Reversing "abc"
Appending "def"

It's currently not possible to replace in all files. The good news is it's part of the June Iteration Plan. The feature has already passed a couple of tests. So it will be probably released in July 2016.

As an enhancement, VSCode 1.70 supports search and replace in all selected files, solving the 2018 issue 47166 "Make search tree context menu multiselect-aware".
See PR 154847 (available today in VSCode insiders)
Make search tree context menu multiselect-aware
When multiple entries are selected, if someone removes/replaces on one selected item, it happens to everything.
Note: if a whole file (uses Replace All) and entry (just uses Replace) are both selected at once and either Replace or Replace All is used, whatever replace action is valid for all selected item will run.
For example, if a file and entry are all selected and the Replace button is selected on the entry, then Replace All will be run on the file and Replace will be run on the entry.
Example:

All File:
Search = Ctrl + Shift + F
Replace = Ctrl + Shift + H
One File:
Search = Ctrl + F
Replace = Ctrl + H

Related

Automate find/replace in .md files in VS code [duplicate]

I was wondering if there was any way to repalce multiple line in multiple files at the same time?
I know under edit->Find in Files
this will show all the desires lines in all the files, however you have to raeplce them one by one, anyone way to just like REPLACE ALL?
Open the folder containing the files wished to be edited via Visual
Studio Code. If not exist, create a folder and fill up it with the files.
At the top-menu bar Edit - Replace in Files or (On Windows Ctrl + ⇧ + H, On Mac, ⌘ + ⇧ + H).
You can also Search and Replace across files. Expand the Search widget to display the Replace text box.
When you type text into the Replace text box, you will see a diff display of the pending changes. You can replace across all files from the Replace text box, replace all in one file or replace a single change.
https://code.visualstudio.com/Docs/editor/codebasics#_search-across-files
At the current time this is not supported (read in the link at Common Questions)
https://code.visualstudio.com/Docs/editor/codebasics#_common-questions
I suggest you to try with Notepad++
Replace in multiple files is supported in latest version of vscode 1.3.

Select matching element/rename HTML tag in Visual Studio Code

Let's say I've got the following code
<div class="footer">
<div>Foo</div>
</div>
How can I change .footer from a div element to a footer element?
That is, if I have the cursor in div I'm looking for a keyboard shortcut that selects the opening and closing tags of an element. I believe I've used emmet to do this before in Sublime, but I can't seem to find similar functionality in Code. (Ideally this would work in JSX files too...)
Do you want to rename the paired tags? If yes, there is a much easier way: you just need to install the Auto Rename Tag extension. When you rename one HTML tag, it will automatically rename the paired HTML tag.
V1.41 is adding this functionality, see https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_41.md#html-rename-tags
HTML rename tags
You can now use F2 to rename the opening/closing tag pairs in HTML.
F2 when the cursor is over one of the tags and you will get a little input box with the cursor to input the new tag name and the start/end tags will be replaced with whatever you type upon .
See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_42.md#html-mirror-cursor-off-by-default
Also of interest might be the "mirror tags" functionality just added in v1.41 as well (https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_41.md#html-mirror-cursor):
Clicking inside a tag will create another cursor in the matching start or end tag.
VS Code now adds a "mirror cursor" when you are editing HTML tags.
This behavior is controlled by the setting
html.mirrorCursorOnMatchingTag, which is on by default.
---------- v1.42 is changing the default status of the mirror cursor:
HTML Mirror Cursor off by default
We have made Mirror Cursor an opt-in feature. In the upcoming
iteration, we'll continue to improve its implementation to make this
feature more easily understandable and available to more languages.
You can still use this feature by turning on
html.mirrorCursorOnMatchingTag.
Thanks to JerryGoyal's answer below (I have upvoted it) - I have continued with this ongoing answer.
Because I have been tracking this for over half a year now, v1.44 has renamed this once again. From Synced Regions:
Synced Regions
We have improved the mirror cursor feature introduced last November
with a new implementation called Synced Regions. Currently this
feature is available for HTML and you can try it out by one of the
following ways:
Running the command On Type Rename Symbol on an HTML tag (bound to
Ctrl+Shift+F2 by default).
Turning on the editor.renameOnType setting and move the cursor to an HTML tag.
The red regions are Synced Regions. As their name suggests, any change
in one region will be synced to other regions. You can exit this mode
by either moving your cursor out of the regions or pressing ESC.
Additionally, typing or pasting any content leading with a whitespace
in any region exits this mode.
We look forward to providing an API that could make this
rename-on-type experience available to other languages such as JSX,
XML, or even local variables in TypeScript.
As that last part notes, it works in html out of the box but other languages need to implement themselves. As of June 2020 by my testing it still does not work in jsx files on embedded html tags.
You must enable this in your settings, it is off by default.
You can do this without an extension using Emmet Update Tag
Place your cursor in the opening tag
Press CTRL+SHIFT+P to open the command palette
Search for "Emmet: Update Tag" by typing something such as "em up t", and/or find it in the list
Press enter to select "Emmet: Update Tag"
Enter the new tag
Press enter
The opening and closing tag are updated to the new one.
Update Mar 2021:
No need for extension, this is now cooked into VSCode.
"editor.linkedEditing": true
Read more here: https://code.visualstudio.com/Docs/languages/html#_auto-update-tags
CTRL + D on windows. As mentioned by #tataata, CMD + D on Mac OS. Not limited to tag renaming. Very useful.
You can use a key shortcut cmd + D (Mac OS) for adding to the selection the next matching element and then there is a possibility to edit open and closing tags simultaneously.
I'm using tag-rename. Press F2 on the tag and it renames the start and close tags.
https://marketplace.visualstudio.com/items?itemName=krizzdewizz.tag-rename
Quick and Simple Select tool works fine too but though it is not perfect.
it has over 40k downloads
https://marketplace.visualstudio.com/items?itemName=dbankier.vscode-quick-select
it allows you to select tools
Ctrl + K ' select everything between single quotes
Ctrl + K " select everything between double quotes
Ctrl + K ` select everything between backticks
Ctrl + K ( select everything inside the parenthesis
Ctrl + K ) select everything inside parenthesis and include them
Ctrl + K [ or ] select everything between square brackets and include them
Ctrl + K { or } select everything between curly braces and include them
Ctrl + K < or > select everything between angle brackets and include
No need to write config codes, just enable it from settings page.

eclipse multiple text selection like sublime text 2

is there an option or plugin for eclipse which would enable multiple simultaneous selections in the same editor.
In sublime text, selecting some text and then pressing Ctrl+d will add next instance of the same text to the selection if possible. After selecting the instances needed the editor has multiple carrets (not necessarily on the same or adjacent columns and rows). In this mode it is possible to move all cursors forward or back simultaneously and to edit all instances of text simuntaneously.
I find this feature very usefull and miss it sorely in eclipse..
This Eclipse plugin attempts to provide this feature: https://github.com/caspark/eclipse-multicursor. From the README:
What is this?
A work-in-progress attempt to provide Sublime-Text-like
multi cursor support for text editors in the Eclipse IDE.
What works?
Multiple identical lines can be edited simultaneously using Eclipse
linked mode editing (similar to existing "rename in file"
functionality)
Next steps
"select next" functionality + associated editing using Eclipse linked
mode
"find next" + associated editing
editing of non-identical text / editing without using linked mode
split selection to lines
regexp support for find next
This feature is available in LiClipse.
See it in action (more towards the end of the video).
It supports linking with Ctrl+K, unlink with Shift+Alt+K, Ctrl+Alt+mouse double click to select words or Ctrl+Alt+Mouse to make a selection of a region (or just end lines).
Preferences>General>keys>Rename - refactoring
I changed the binding to command + shift + R when > Editing Text.
Sorry for bringing up an old question, stumbled upon it after searching google for the problem
Alt + Shift + A, then you can hold shift and use the cursor in multiple lines.
Like Ctrl+D I could not find, but like Alt+F3 in sublime (multiselects all matches), you can do by pressing Alt+Shift+R, or select text > right click > refactor > rename.
Must say that this does not work with any kind of text. It works with names of variables, functions, classes etc.
Tested on Eclipse 3.8.1
ALT + SHIFT + F worked for me.
You can see shortcuts for all here:
Goto -> Window -> Preferences -> General -> Keys and search for replace then you will see binding for Find and replace. In the bottom of that window, you can add your key to Binding text box. There you can add or edit any keys as shortcut.
If you want to replace selected word's matching words or find selected words, use below keys because you do not need to select all words in eclipse:
Ctrl+F gives me Find/Replace dialog box.
Or you can,
First Alt+A
Next Alt+F
Then press on Replace or Search button occurding to your need.

Eclipse : search for only a particular word under Eclipse IDE

Is it possible to search for only a particular word under Eclipse IDE .
For example i need to search for a word "sub" .
But the problem is that , when i did ctr l + H and typed the word "sub" , it producing all matching results such as
submit ----etc , but i want the exact word "sub" in my Search .
Please let me know if its possible ??
Thanks in advance .
Try using regular expressions in the File Search Dialogue (Ctrl + H). You can use the word boundaries modifier \b like so :
\bsub\b asks eclipse to search for all matches in which sub is both followed and preceded by a word boundary. Read more about word boundaries here.
Here is a sample snapshot of the Search Results using the above:
If you want to restrict the search to the current project then try selecting 'Enclosing Projects' radio option. This option will be disabled if you don't already have a file from the Project opened. To get past this annoyance, I would recommend creating a Working Set with just the project(s) of interest and then restricting the search on that Working Set.
You can do it from Find/Replace menu (CTRL+F) and flagging the Whole word option :
Otherwise from the standard Search menu(CTRL+H) you can achieve the same result using an appropriate regular expression, in your case you just need to append a space after(or/and before) the sub text and you will get only the whole word.
Select the word and then press Ctrl+Alt+letter(G) it will search the word where it is used.

Code completion based on snippets in Eclipse

I would like to accomplish two tasks at once.
First, to move my snippets of code from .txt files and be able to tag them/organize better.
Second, assign shortcuts to those snippets that will allow me to type "p" + TAB which will render assigned snippet (I don't care of cursor position etc)
Quick Importing - resources
You can do a brief CTRL + SHIFT + R. This will enable you to display any kind of file from inside your projects directory.
To open any resource type * . *
To select resource to open type ?
To open all text files type *.txt
Snippets - templates
Eclipse has auto fill property. You can enhance it using templates. There are many ready-to-use templates, and you can even create your own.
Templates are used by typing the first character and pressing CTRL + SPACE.
Organize code - formating & tags
If you want to organize you code even more, you can use existing tags like TODO or create your own tags. Use them to sort or prioritize the code snippets you want to import into another project.
You can use CTRL + SHIFT + F to reformat your code.