The best Visual Studio shortcuts

It is found that you could be more efficient and appear smarter if you use shortcut keys rather than doing things with the mouse. Sometimes I used to wonder how the system administrators are very fast in setting up things, restarting a crashed network, etc.

They do all with their precious keystrokes combined with Shift, Ctrl, and Alt,  Is’nt it? And who wouldn’t like shortcuts after all?

For those people who use Visual Studio to write code, behold I present you few of my favorite and best shortcuts that can be used while writing and managing code.

  • Collapse/Expand selection Ctrl+M+H/Ctrl+M+U
    Sometimes you would want to hide the annoying code that is blocking your view or distracting you, use this then.
  • Comment/Uncomment block of code Ctrl+K+C/Ctrl+K+U
    //bored of adding ‘// ‘on every line??
    //You can bulk comment and uncomment by using this shortcut.
  • Navigate Forward/Backward Ctrl+โ€“/Ctrl+Shift+โ€“
    Forgot the previous location of your cursor? Don’t worry. This is the hotkey for the back and forward buttons
  • Full Screen without losing the panels Alt+Shift+Enter
    Searching for the menubar and the panels while on Full Screen? This is here to rescue
  • Simple search Ctrl+I
    A simple search box is opened you can start typing after pressing this hotkey and press again to go to next result
  • The TAB key for “snippets”
    Best of the shortcuts. Bored of writing if-conditions and making sure that they are surrounded by braces?
    Type if and then press the tab key twice. Baam! the if-condition is completed for you. VS offers many snippets like try-catch, for, class, foreach etc
  • Surround with snippets CTRL+K+S
    Want a piece of code within an if-condition or a for-loop. Don’t  worry, select the code and press these keys. Select any snippet from the context menu shown and consider it done.
  • Find Matching braces Ctrl+]
    A conversation with the Open brace “{“
    Me: Hey you!! Where is your pair??
    Open Brace: I dunno ๐Ÿ˜”
    Me: Okay let me find it!
    After a while
    Got you!! You cant hide from me, You dumb closing brace!
    -To find the matching brace of a function/class use this shortcut.
    -To select the code between the braces, add shift key to the combination.
  • Ctrl+C+V to duplicate the current line
    This is a well-known legend yet in the form of a simple shortcut key.
  • Create/Remove a bookmark Ctrl+K+K
    Bookmarks, they are cousins to the breakpoints. They are not hit by the debugger but can still help you remember where a bug that you discovered yesterday is present.
    -Open BookMark window -Ctrl+K+W
    -Go to the next bookmark -Ctrl+K, Ctrl+N
  • Cycle through the list of clipboard contents Ctrl+Shift+V 
    This is also a well-known shortcut. Tired of copy-scroll-paste, copy-scroll-paste? You can replace it with copy-copy-scroll-paste-paste by using this shortcut
  • Collapse all functions Ctrl+M+O
    Too large code base? Minimize the code and find it easy to navigate through the code.
  • Format Selection Ctrl+K+F
    When the code is shabby and does not have proper spacing and indents, use this shortcut and see the Magic.
Buy Me a Coffee at ko-fi.com

There are yet many more amazing shortcuts but these are my favorite, hope these are helpful in your programming career. You can take the shortcut keys to a whole new level using Auto Hot Keys, read it here.

Click here, for more detailed cheat sheet on various tools and technique.

Happy Coding ๐Ÿ™‚

Auto Hot Key – One key for all

Heard of Hot Keys? Ahh! They are the keys that are really hot ๐Ÿ™‚ Just kidding, Hot Keys are the key combinations that are used to perform some specific operations quickly. Remember the legends? Ctrl+C, Ctrl+V, Ctrl+X.

Does your job require these shortcuts often? Then you must be a programmer (Again Kidding!). It must be a pain to keep stretching your fingers often to use these hotkeys. I just came across an interesting open source scripting language known as Auto Hot Key. AHK is so cool that it provides a lot of cool stuff that you could do with your keyboard. Programs like Visual Studio offers shortcut keys with two or three combinations like Ctrl+K+F(Format text), Ctrl+C+U (Un-comment), etc.

Ouch! My fingers start hurting if I keep on using these shortcut keys right from the morning like Ctrl+X, Ctrl+V (Oh no!! Copied the wrong code), Ctrl+Zย (Undo), Ctrl+Cย (Copy again), Ctrl+Vย (Paste again). Next, I have to format the code, Oh come on, I’m Mister Fantastic, the elastic man in the Fantastic 4, let me make my fingers reach Ctrl+K+F. Phew! somehow completed the job! Imagine repeating this scenario 50 times a day. Difficult right, here comes the AHK scripts to help you.

“AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts for all kinds of tasks such as form fillers, auto-clicking, macros, etc.”ย  This sentence was stolen from the AHK site ๐Ÿ™‚

Fine, let me break things down and explain. With AHK you can create substitutes for complex shortcut key combinations like Ctrl+K+F. For instance, you could replace Ctrl+C with a single key like ‘c’, so after executing the AHK script (which doesn’t disturb you and silently runs in the background), if you press ‘c’, Bang!! the selected text is copied. No more two keys for copying, pasting, cutting, saving, etc; The AHK script for the previous functionality goes like this, enter the following text into a text editor and save it with an extension .ahk ๐Ÿ™‚

x::Send, ^x

c::Send, ^c

v::Send, ^v

Now you can cut, copy and paste by just using the keys ‘x’, ‘c’ and ‘v’ ๐Ÿ™‚ Cool right, No pain, more gain.

This is just a sample of what AHK can do. You could do almost any kind of automation with AHK. In order to execute AHK scripts firstly you need to install AHK in your machine by downloading it from their website, it’s just 3017KB. Install it and then you can run any file that has an extension .ahk.

Awww! I just now read your mind, you were thinking, “What?!! Blindly run some random script just because you told me? Is it safe? What if I’m hacked?” Do not panic, since AHK is open source millions of people will be watching its code and contributing to it if somethings not right it would be removed or informed. Also, there is a large community support for AHK and ready-made scripts for basic tasks. Enjoy using AHK. For more technical posts, follow efficientuser and for funny posts on life skills visit my blog.