Is there such a feature in IDEA, that after renaming certain declared variable or field, I can apply to rename all occurrences of it? Like in VS after renaming something, appears some red, small triangle at bottom right of the word, that pushing it, VS updates all occurrences.
You can use Shift + F6 for an in-place rename.
Yes, you can do it. Set cursor on your variable and then select in menu Refactor -> Rename...
Idea will automaticly detect if it is needed to rename other occurrences.
Related
So, I have some code for a Rect variable mageSection:
And I'd like to copy the same code for a different variable warriorSection. To achieve this:
So I'd like to know if there is a visual studio shortcut for allow you to change variable name in multiple line in visual studio without refactoring the whole variable name.i.e. I don't have to manually change those names from mageSection to warriorSectionfor these 4 lines.
It is a question about shortcut in visual studio rather than writing functions, as I'd like to know the shortcut for this. Many thanks!
Copy and paste the section of code.
Now select the pasted code and hit Ctrl-H to bring up the Quick Replace dialog.
In the top box, type "mageSection".
In the bottom box, type "warriorSection".
Hit Enter and it will find the first occurrence and replace it.
Hit Enter three more times...done.
If I'm understanding your question correctly you should be able to hold down alt while clicking into multiple lines and change them all at once. Then hit ESC to exit multiline editing.
Is there a command/macro/keyboard shortcut that will expand the region where the cursor is and expand all collapsed regions inside it (recursively) ? if not can that be achieved ?
Short answer
As far as I know - No. There isn't a single shortcut that does that.
How to implement it by yourself
It's quite easy to create a plugin for Visual Studio that does exactly that:
Get the cursor location.
Store the 'start' and 'end' line numbers
For each line:
If it contains a region - expand it.
Few examples to begin with:
https://github.com/LeonalaDiantes/RegionsWasher
https://github.com/dnperfors/RegionExpander
https://github.com/fsdsabel/ExpandRegions
https://github.com/pauljmelia/regionsareevil
https://github.com/yasam100/CodeRegionsSnippets-VSExtension
Some of the projects are very close to the thing you have in mind, so you might even fork it and do your changes.
:-)
Another option
you might get the same result by using Macros for Visual Studio Editor/Recorder:
And then, write a macro like this one or maybe even record the steps you like to "run".
IMO, with recording and playing it will be a little harder to achieve.
but I'll be happy to be proved wrong.
I had the same problem, the following worked for me without having to make a macro or a plugin. Note, this is only a partial solution to the problem. I got it to expand recursively underneath a function, but I'm not sure how to reverse it (i.e. recursively collapse everything under the function again). To recursively collapse everything again, I could only figure to use (Ctrl+M, Ctrl+L), which collapses/expands everything in your file, but then you have to drill back down to the function you want.
Firstly, I got everything in a collapsed state by pressing (Ctrl+M, Ctrl+L). You may have to use that combination twice to get everything to collapse. Then I expanded a class and drilled down to the function I wanted to work on.
With the function in its collapsed state, I highlighted the single collapsed row it was on and pressed (Ctrl+M, Ctrl+M).
Doing so recursively expanded everything under the function.
I hope this partial solution helps someone who doesn't want to make a macro or plugin.
I believe ctrl + k followed by ctrl+] should unfold all subregions
replacing the ] with [ should fold all subregions.
This seems like something I would have found hundreds of topics on. Yet I didn't find a single one. I wonder if no one cares or if I just overlooked something obvious.
In Visual Studio when you select a column and want to select the word your cursor is at in each line, when you do CtrlShift+(ARROW KEY), then it doesn't select by word as it SHOULD, but instead it selects a square.
BAD BEHAVIOUR (which VS has):
GOOD BEHAVIOUR (which would be expected, and is in every other IDE):
The Visual Studio ALT select is rendered useless in half the cases, actually in every case where you don't have the "coordinates" precisely the same on every line.
EDIT
I seem to have to explain why the VS behavior is bad, people apparently consider it ok. So the problem is that when you column select in VS, and you have it exactly like in the example, or even without tabs, you'd copy some =, though they won't be everywhere.
If you select a column like VS Code or JetBrains has it, you'll just copy WHAT IS NEEDED and that OBVIOUSLY being just the words in the column.
I have a solution for you, but you may not like it. It's using the new Multi-Caret Support in Visual Studio 2017.
Here is my example code where I want to copy only the property names (sorry for lack of inline images):
Multi-Caret Code Example
Using Ctrl + Alt + Click to click and add a caret to the end of each word. (If you screw up and click somewhere you didn't mean, like I do many times, then reclick to remove that caret and click on the correct spot.)
Multi-Caret End of Line
Now hold Ctrl + Shift and hit the ← Left Arrow. This will select to the beginning of the current word on each line.
Multi-Caret Word Selected
Copy/paste as you wish
There is a command in Visual Studio 2005 called Edit.SelectToLastGoBack (bound to Ctrl + =).
I presume it is supposed to select all the text between the current cursor position and the last 'Go Back' point, but I can't work out the algorithm it's using for deciding what that point is.
Does anyone know how to use this potentially very useful command?
Selects to the last juimp point ...
Try using the navigation bar to jump to another method in class. Then press Ctrl + "="
It will select from the start of method you jumped to all the way back to where you jumped from.
I have yet to find a use for it though TBH,
Kindness,
Dan
I use it for recording macros.
Frequently I want to select everything from this brace to that brace and cut it in a macro. Go to the first brace, hit ctrl-f (ctrl-i doesn't work right in macros), search to the second brace, close search with escape, and hit ctrl-= to get everything between the braces selected. This is much more reliably repeatable in a macro than something like using ctrl arrows to navigate a word at a time while holding down shift, and is similar to the emacs concept of setting a mark point.
I'm not sure what all starts a new 'location in navigation history', but I'm sure starting a search does and that's all I need.
I just discovered this command is available in Visual Studio 2012. I've been looking for it ever since I got VS 2012. I kept thinking it was something like anchor, like select everything between the anchor and point. I was disappointed that macro recording and playing are no longer available. But I am glad this command still exists.
Another useful command is ctrl+k ctrl+a, which is Edit.SwapAnchor. So, you could be someplace in the code, then do a find. Now you have the point and anchor (maybe also known as the cursor and last goback). You can do ctrl+= to select, then ctrl+k ctrl+a then extend from the other end using another find--or something like that.
Is there the way to apply "greedy" behavior to and keys in Visual Studio? By "greedy" I mean such behavior when all whitespace between cursor position and next word bound can be deleted using one keystroke.
Well, I don't think you can change the binding of the delete key or backspace key - but CTRL+DEL & CTRL+Backspace are pretty close to what you want.
You can use Ctrl+Shift+Arrow keys to make the selection and then just hit Delete. You may need to hit the arrow key more than once while still pressing Ctrl+Shift combination but because the fingers are in the same position is very fast. This works also for selecting words incrementally.
Actually, you will need to do this: Ctrl+Shift+Left+Right - this will give you only the space selected, and then you can press delete.
This is assuming that you are coming from the right, and you have to delete the space to the left.
Of course, this is still 5 keystrokes... but it beats pressing backspace again and again....
Just Ctrl+Backspace...
Ctrl+Back Space and Ctrl+Delete are also greedy, they delete the nearest word in their respective direction.
You are looking for:
Edit.DeleteHorizontalWhiteSpace
I have it set to Ctrl+K, Ctrl+\ which I think is the default, but might not be
Sounds like something you could write a macro for and then assign to a keyboard shortcut (like SHIFT+DEL).
If you explore the EnvDTE namespaces you can do a lot to make changes to text in the active document window. I'd start by checking with something like...
Public Sub RemoveWhiteSpace()
DTE.ActiveDocument.Selection.WordRight(True)
DTE.ActiveDocument.Selection.Text = " "
End Sub
That's just a simple example, but you can extend it further pretty easily
As of recent, ReSharper has this as an option. It's on by default, which led to this Q&A: Visual Studio recent "hungry" or "greedy" backspace behavior update?
Perhaps this doesn't qualify as applying the behavior directly in Visual Studio, but it's good to know about.
OK I've got this < Ctrl > thing. And applying this knowledge I've found corresponding VS commands: Edit.WordDeleteToStart and Edit.WordDeleteToEnd.
I've successfully remapped < Delete > and < Backspace > keys using Options->Environment->Keyboard dialog. Unfortunately this commands apply not only to whitespace as I'd wish to, but still, thanks everyone!