It's always interesting to see how other people work. We all have our particular routines and work styles, but there's always something to learn by shadowing another developer.
Much of my working day is spent inside Visual Studio 2015 doing full-stack web development. With Visual Studio 2017 soon upon us I'm sure there will be some fancy new productivity features to talk about, but for now I thought I'd cover off what I use right now every day. Not necessarily the headline features you try out once and never use again, but the shortcuts, settings and tools that have become essential to my workflow.
The Core Basics
Here's some general windows shortcuts that work in VS, they're all pretty common knowledge but I'll list them anyway:
- Ctrl+X or Ctrl+C or Ctrl+V: Cut, Copy and Paste
- Ctrl+Z or Ctrl+Y: Undo and Redo
- Ctrl+Left/Right: Move the text caret between words, hold shift at the same time to select text by word.
- Ctrl+S or Ctrl+Shift+S: Save/Save All. I use this mostly out of habit really because building a project should save all files anyway.
- Double-click word: Select a word
- Ctrl+F: Bring up the find tool, do this when text is selected to auto-populate the find text.
- F2: Rename file
- Ctrl-N: Bring up the New Item window
- Esc: Dismiss stuff like modals without leaving your keyboard
Text Selection & Editing
- Cut/copy/paste with no text selection: Copy/cut/paste the whole line. I use this quite often, even as a quick way to remove multiple lines of code by hitting Ctrl+X several times.
- Ctrl+K, Ctrl+C and Ctrl+K, Ctrl+U: Comment and un-comment selection. As above, you can do this with no selection to toggle comments on a whole line or lazily highlight part of a block of text (i.e. not complete lines) and it will still comment the whole block.
- Alt+mouse drag selection: Box selection. I don't use this too frequently but it can be really useful for specific tasks. You can even make a zero-length vertical selection if you just want to add text on multiple lines.
- Ctrl+space: Brings up intellisense options or auto-completes the text if there's only a single option.
- Ctrl+. Brings up the smart tag options, i.e. refactoring and quick options.
- Quick snippets: To use a snippet type the snippet text and then hit tab twice to stub out the code. I only use the ctor (constructor) and prop (property) snippets, but researching this I found a bunch more I might try out like foreach, #region and using. Full list here.
- Ctrl+;: Activates Solution Search. I find this invaluable for finding code files. Simply hit the shortcut type your query and hit enter. Navigate multiple files with the arrow keys and hit enter to open it.
- Solution Explorer – Remove class expansions: I find the integrated class expansions are unnecessary noise so I've removed them using these instructions.
- Solution Explorer – Track active item: Often I find it useful for the solution explorer to track the file I'm working on which makes it easier to find files in a similar location. Setting this option needs to be done in Tools > Options > Projects and Solutions > General.
- F12: Go to definition. Peek definition is a cool feature but It hasn't yet found itself into my workflow; F12 and a quick Alt-tab to get me back does me just fine.
- Ctrl+M, Ctrl+O: Collapse to definitions. Quickly collapse all regions and method blocks to show just the definitions. Handy for making a code file easy to scan.
- Ctrl+tab Quickly switch to the last active file
- Tab pinning: Toggle the pin button in the file tab to keep it pinned in the top left corner of the file tab collection. This is occasionally useful if there's one main file your working on but you end up diving through several others.
- Shift-Alt-C: Creates a new class file.
- Theme selector: I often switch between a dark and light theme depending on whether I'm in a bright or lower-light environment. I used to use an extension for this in VS 2013, but in 2015 its integrated, just go to Tools > Change Color Theme.
- Ctrl+Shift+B: Build solution
- F5 or Ctrl+F5: Run with/without debugging.
- Ctrl+Mouse+Wheel: Increase/decrease text size of the current document, additionally you can hold shift to apply the change globally.
- Turn off code lens: I don't find code lens useful and it adds too much noise. You can turn it off in Tools > Options > Text Editor > All Language > CodeLens.
It's also worth mentioning that I don't use ReSharper. It's a popular tool and I know many love it but I've never been convinced to give it a try. Visual Studio seems to provide more than enough features to keep me productive and it's a pretty heavy IDE as it is so I'm not too eager to add a ton of new features I'd rarely use. I haven't actually used it myself though so don't put too much weight on those comments.
Visual Studio Code
Anything I've missed?
One that I haven't managed to integrate into my workflow yet are the shortcuts for navigating back and forth (Ctrl+– and Ctrl+Shift+–). I think it's a useful one but I never remember to use it.
Got any essential tips I've missed? Let me know!