I am working with a visual studio 2005 project with several thousand lines of code.
When I am looking at an IF statement in the code is there anyway to jump to the corresponding ELSE part without scrolling through hundreds of lines of code? I can't use goto as the line numbers will change all the time. If I can't automatically jump to the else part of an if statement, can I set up something to allow me to tag the else part and then go to that tag in visual studio?
You can use Ctrl+] to jump to the matching brace or parenthesis. So you can place your cursor on the brace of the if statement and press the shortcut to go to the end of the block and thus directly in front of the else.
Another option would be to set bookmarks with Ctrl+B, T. Those move when the line moves as well and you can jump between them with Ctrl+B, N and Ctrl+B, P.
Related
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
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.
In Visual Studio 2008 I would regularly record a macro to (for example) take a list of class member declarations and turn it into a list of property definitions.
Using Visual Studio 2010, the macro recorder appears to ignore a 2nd press of the Home key (the 1st should take you to the start of the text on the line, the 2nd should take you to the character position 1 on the line).
Putting the cursor at the end of a tabbed line, starting to record and pressing "Home" twice results in the following (it doesn't matter whether the tabs are actual tabs or spaces)...
Sub TemporaryMacro()
DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstText)
End Sub
When what it should really put is...
Sub TemporaryMacro()
DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstText)
DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
End Sub
I know I could just go in and edit it, but as I normally record something and then immediately run it multiple times, that is not appealing. And I'm not aware of any keypress that will take you to the first column.
Can anybody confirm if this is a fault with the macro recorder in VS2010, or am I doing something really stupid?
This does not work for me, either, meaning it does the same thing for me as it does for you, and the macro does not play back correctly.
As a workaround, I use the key combo [end, right, up] to go to the first character position when recording a macro. This translates into:
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.CharRight()
DTE.ActiveDocument.Selection.LineUp()
The only time this doesn't work is when you operate on the last line of the file. If you anticipate that happening you could use [up, end, right] instead:
DTE.ActiveDocument.Selection.LineUp()
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.CharRight()
Of course, this version would not operate correctly on the first line of the file.
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.
When Visual Studio (2005) has Options -> Text Editor -> C/C++ -> Tabs -> Indenting set to Smart it will automatically indent code blocks and line up squiggly brackets, {}, as expected. However, if you hit enter inside a code block, move the cursor to another line, and then move it back, the inserted tabs are gone and the cursor is positioned all the way to the left. Is there a way to set Visual Studio to keep these tabs?
As far as I know, the only way to do that is to enter something (anything) on that line, then delete it. Or hit space and you'll never see it there until you return to that line.
Once VS determines that you've edited a line of text, it won't automatically modify it for you (at least, not in that way that you've described).
This is an annoyance to myself as well. Anytime the code is reformatted the blank lines are de-tabbed.
You might look at this: http://visualstudiogallery.msdn.microsoft.com/ac4d4d6b-b017-4a42-8f72-55f0ffe850d7 it's not exactly a solution but a step in the right direction