This question already has answers here:
Closed 12 years ago.
Similar Post:
Hidden Features of Visual Studio (2005-2008)?
What are some shortcut keys you know of that make programming faster, easier, or all around more enjoyable?
One of my favorite items is CTRL + . to add an imports/using statement to the top of the code file.
Of course there is Intelli-Sense, it opens automatically or when you hit Ctrl + Space. Select the variable / class / function or whatever it shows you and hit Enter or Tab to insert it.
Code snippets, also provided by the Intelli-Sense list insert code so you do not need to type everything again. Etc. type "prop" and double hit Tab.
Ctrl + K, Ctrl + D to format your total file so it looks cleaner.
#region / #endregion to group your code and allow you to hide the whole region
I like CTRL + K + D, which formats the code in a file.
And although it's not a Visual Studio feature, I highly recommend Resharper.
Couple of my favorites:
CTRL + TAB -- moves you between open code pages
SHIFT + CTRL + F -- allows you to do a search across the entire solution (as sometimes find all references does not work when your solutions get huge)
SHIFT + DELETE -- allows you to remove an entire line from your code without highlighting it.
Related
I am removing a property from a class in c# code. I want all the references of that property should be removed, else it is throwing build errors while building the solution.
Is there any short cut in visual studio to remove all the references while removing a field/property or I need to do it manually one by one?
I would Ctrl + R refactor it as "asdfgh" and then do Ctrl + Shift + F and review each instance.
But if I'm really confident, Ctrl + Shift + H for Replace All on ".asdfgh".
Ctrl K + D in a Visual Studio 2010 Sharepoint project is not working in some files as they contain paths to some resources (masterpageurl/images/js/css classnames) that get generated at runtime.
How do I make VS to "ignore" checking if these resources exist or not?
Code formatting doesn't work in multi-line arrays :
int[] ok={ 1 , 2, 3 };
int[] ko={
1 ,
2,
3
};
use Ctrl K + D
int[] ok = { 1, 2, 3 }; // nice formatting
int[] ko ={
1 ,
2,
3
}; // nothing changed :(
Check for other errors in the same file. If there are errors, it will not format the document until they are fixed. In order to help you during design time, you can create dummy resources, point to those, then change the references at runtime to the dynamically generated content.
Well mine was Shift+Alt+F and I was also upset
Here how to change it
Update your Keyboard shortcuts to reflect this. Currently it is assigned to "Move last selection to next find match", but you can easily assign it for formatting code.
File > Preferences > Keyboard shortcuts (or CTRL + K, CTRL, + S
Search for "Format Document", or "editor.action.formatDocument" and re assign the keyboard shortcut to CTRL + K, CTRL + D
You can choose from the following menus:
Tools -> Options -> Text Editor -> <Pick your language>
or use
"All Languages" -> Tabs -> Indenting -> Smart
Also, my own preference is to change the tab section to "Insert Spaces". this way, when you open the visual studio files in a different editor, such as notepad, the formatting will be the same.
CTRL-K-D will always format.
I left out a semicolon and because of an error as specified in the above posts the formatting didn't work.
Make sure that there are no errors and the formatting will always work.
An easy way to spot an error is to look on the right hand sidebar for any red dots.
I often find myself writing something daft like:
String.Format("{1}: {0}", reason, message);
or something similar but with far more string placeholders.
Is there an automated refactoring in ReSharper to change the order of the placeholders and the arguments? I have a tendency to mess up the mapping if I try to change the order by hand.
Obviously, the example above is trivial. What I am doing in reality is often writing something like:
String.Format("{0}.{2} = {1}.{3} AND {0}.{4} = {1}.{5} AND {6}.{7} = {1}.{8}",
table1Alias, table2Alias, col1A, col2A, col1B, col2B, table3Alias, col3C, col2C);
and thinking to myself that it would be great if I could move table3Alias up to the front next to the other aliases.
(ReSharper 7.1.3)
For C# 6+ (ReSharper 10+ / 2016+):
Place your cursor at string.Format
Press Alt + Enter
Select Use string interpolation
Press Alt + Enter again
Select Convert to string.Format
No, there is no such functionality.
Just place your cursor in table3Alias, then press Ctrl + Alt + Shift + Left/Right arrow. This changes the parameter order in a function call.
There's also an option for removing one when you press Ctrl + Shift + R
There's also a shortcut to add a format item. You may be able to do what you want with combining these. The exact functionality you ask is not implemented.
When navigating to declaration or implementation, I also want to know how to jump back and forth between the last file I viewed.
Is this possible in resharper?
Ctrl+- and Ctrl+Shift+- will navigate forwards and backwards between places you've seen. I think they're standard Visual Studio (rather than ReSharper) keybindings.
Ctrl+Shift+Backspace will take you the last edit location.
Last few edits for resharper
http://www.jetbrains.com/resharper/webhelp/Navigation_and_Search__Navigating_to_Recent_Edits.html
Lat few files visited
http://www.jetbrains.com/resharper/webhelp/Navigation_and_Search__Navigating_to_Recent_Files.html
You can try with
CTRL + SHIFT + - => BACK
CTRL + - => NEXT
You can read this article about configuring
Link : http://www.jetbrains.com/resharper/webhelp/Configuring_ReSharper__Configuring_Keyboard_Shortcuts.html
I am a bit lazy when it comes to formatting code in Visual Studio and almost rely solely on the magic of Ctrl + K, Ctrl + D (or F depending on what I’m doing). However I loathe having to use my right mouse button to Remove and Sort my using statements and am constantly forgetting.
Assuming that I’m not using Re-Sharper is there any way to extend the Ctrl + K, Ctrl + D keyboard shortcut to format my code and sort my using statements?
Would writing a macro to do both tasks and assigning it the same key combination the only way to do it?
It's not extending the current key combo as such, but there's a Edit.RemoveAndSort command to which you can assign a key binding in Tools -> Options -> Keyboard.
Here's a blog post detailing just that.
From the lack of response I can only assume that I'll need to create a macro and assign it the same keyboard shortcuts... oh well
Sub LazyFormatAndSortUsingMacro()
DTE.ExecuteCommand("Edit.FormatDocument")
DTE.ExecuteCommand("Edit.RemoveAndSort")
End Sub