Visual studio Paste without moving cursor to the end - visual-studio

Is it possible to paste some string in visual studio via some shortcut or other extension to keep the cursor where it is after the paste?
This way if I add multiple words of string I will not have to go with the cursor back to the location via ctrl-arrows or home key when I don't want the cursor to go to the end of pasted text.

I actually found a way to do it with resharper - if any better suggestions out there please feel free to answer.
Create a simple template as
$END$$CopiedContent$
and set the CopiedContent variable to clipboard content. Give it a shortcut vc (ctrl-v inverted) - and have fun. It will require an extra left arrow and escape char to get desired effect.
It costs VC[TAB][Left_ARROW][ESCAPE] meaning 5 characters which is more than I originally wanted. Willing to trade for a better answer.

Related

Change variable name in multiple lines in visual studio

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.

Get outside parentheses in Visual Studio 2013

All right, this is stupid, but I have no clue how people deal with this and I'm hoping I'm missing something...
When I write something like this:
if (n == 0)
...The closing parenthesis gets added as soon as I type the opening one. The only way I know of to get out of them now is to reach over and tap the End key or something, which kind of ... Damages my shui, you know? And yet apparently they thought this feature was a cool idea, so...
What do you normally do to tell the IDE that you're done with this bit and you're ready to move on to the next? Same question applies to automatic quotes and stuff in the XAML editor, I guess.
Just keep typing - if you type your own ) when the cursor is just before the automatic one, it should not create another ), but just move the cursor over it.
(Disclaimer: I'm not certain this works on a vanilla Visual Studio - I have a bunch of extensions installed)
You can press Ctrl + Shift + Enter to open a new line below the current one without moving the cursor to the end of the line.
To add to this, Tab is another option and I find it easier:
In your example, type the logic, press Tab to skip passed the end bracket.
If you are inside auto quotes, type your text, then press Tab twice.
Like the other answer, it only applies when first being typed, so if you go back to edit something, you are left using the End and Arrow keys.
In Visual Studio 2015 with Productivity Power Tools installed (probably works earlier as well), when being inside an auto-complete block (quotes or braces):
end goes to line end ( typically slow to type/find)
"/) typing same key as auto-complete already inserted will simply replace the auto-inserted character
tab jumps over end of auto-complete (e. g. braces or quotes)
shift+enter adds ; at end of line, goes to new line (often what you want)
ctrl+shift+enter goes to new line
There is a short key in VS - "Edit.LineEnd" - pressing "End" you get to the end of the current line. I've re-assigned it (for me the best variant was "Alt-Enter") and use it to get outside of parentheses and quotes.
Hit the enter key when you are done typing.

How to automatically keep the smart indent in visual studio

I don't quite know how to phrase this question, but basically what happens is:
if i smart indent in visual studio, then click somewhere else on the page or even on the exact same line that has the smart indent, it then goes away, as if I'd had no indenting at all, not even block indenting.
It just puts the cursor/insertion point at the very beginning of the line.
EDIT: BTW I recently formatted my computer and I'm almost certain this wasn't the case before, I'm guessing it's a setting, but I've been fiddling around with all the settings trying to change this, but I can't.
Open Tools->Options. Navigate to Text Editor on the LHS. Select the source type (C++, VB, etc.). Open the tree view node and select Tabs. There, on the RHS you'll find your option

Use of Edit.SelectToLastGoBack in Visual Studio

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.

How to begin a text selection in a Visual Studio macro

Long ago in a former editor, there was the ability to begin a macro, and then "open" the text selection...such that if your next action was to, say, search for some string - the text selection would then extend to that spot.
This was a great way to do fairly sophisticated operations without having to use wildcards or regular expressions.
Is there a similar facility in Visual Studio 2008?
Ctrl-= is the answer.
It is the 'SelectToLastGoBack' command, officially documented as "Selects from the current location in the editor back to the previous location in the navigation history". So, get the cursor where you want to begin your selection (preferably using something reliably repeatable like a search), start a new search (usually I like ctrl-I better than ctrl-F because I can see what it's doing, but ctrl-I seems to not work right in macros), have the search end where you want to end it (esc to close search box), and hit control equals to select back to where you started.
Unfortunately I can't really find anything that explains in detail how the editor decides what the previous location in navigation history is.

Resources