6 Visual Studio Tips to Increase Your Productivity | Mosh

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
bookmarks is one of the greatest features of Visual Studio that is unfortunately hardly ever used basically you put bookmarks in various parts of the code to remind you that you need to get back there and do something this is often very useful when you're focusing on a task but you see a problem somewhere else in the code you don't want to get distracted from the original task at hand so you just leave a bookmark there and get back to your original task later you can look at all your bookmarks and get back to do whatever you wanted to do let's see this in action imagine you're in the middle of a task and you spot something here in method one you don't want to get distracted so you leave a bookmark here by pressing ctrl and K twice note this little icon here this represents a bookmark to see all your bookmarks press ctrl + W as in short for window and then B as in short for bookmark note that the bookmark I just created is listed here you can double-click it and change its name to something more meaningful like requires refactoring I know what you're thinking you're probably saying Marsh didn't you advise me not to use the mouse while programming yes I did say that to be honest with you at the time of recording this video I don't know a way to rename a bookmark without using the mouse hopefully one day when I figure it out I'll update this video and teach you and everyone else how to do it note that you can remove a bookmark by selecting it here and then clicking the Delete icon here but you can also remove it in the code position the cursor on the line where you have a bookmark and then press ctrl K twice code snippets are one of the coolest features of Visual Studio that can speed up your coding a lot let's see this in action here I've got a class called code snippet examples let's say we want to create a constructor for this class most developers do it this way here is a faster way of doing that using snippin did you see how faster it is so how does this work there are certain reserved key words that you can use to automatically insert a ready-made code snippet into your code in this case I used the keyword c tour as in short for constructor and then pressed a tab let's try again I didn't have to manually type the name of a class for the constructor method all I typed was seat or it's very easy now let's create an otter implemented property here called first name this is how developers who don't use code snippets do this you can do this faster using a code snippet just type prop and then press the tab note that the type isn't highlighted it's ready for you to specify the data type of this property we type in a string and then press the tab again now the focus is on the name of the property let's give it a name as you see some code snippets require parameters in this case the name and type of a property are the parameters that we have to manually specify but the last example for a constructor we didn't have to specify any parameters when you need to specify parameters you hit the tab to move to the next parameter here is another code snippet if you need to create a property with full get and set methods you type in prop full note that Visual Studio created a private film and a public property here here is another example let's say we want to type console the right line in the constructor here we can do so by typing C W as in short for console duck right line and then press the tab there you go isn't it great here is another one let's say in this class we would like to implement the equals method we can do this by typing equals and pressing the tab there you go Visual Studio created two methods for us equals and get hash code you can go ahead and customize these methods according to your needs here is another useful one to create a try/catch block use try like this or he can use try F if you want to create a try finally block another useful code snippet is for let's try it or we can use for our or a loop that decrements the loop variable after each iteration here is another useful one let's create a list of strings and call it names let's say we want to I trade over this list using a for each block so we type in for each and press tab because I created the for each block near the names variable Visual Studio detected that I may want to iterate over this collection so I don't have to manually specify the name of the collection or the loop variable just press tab to commit the code snippet you can also use while Purdue code snippets for loops let's try it you here I've got a piece of code that is not properly formatted as you see we can go ahead and clean it up a little like this so we select these few lines here and then press the tab key to move them one tap stop to the right I can press shift and tab to move them one tap stop to the left there is also faster and better way to clean up this code you can select everything here using ctrl + a and then press ctrl K and then ctrl F it automatically formats the entire selection it's a very useful shortcut to know and I use it all the time let me show you even a faster and easier way to clean up your code let me revert back the code to its original dirtiest state first note these few namespaces here as you see they're not used that's why they are grayed out also the code is not formatted properly I can fix all of these issues with only one shortcut ctrl + S which is for saving the file see what happened all those unused namespaces are removed and my code is perfectly formatted so how did this happen this is because I've installed an extension to visual studio that is called productivity power tools to get productivity power tools open up your browser and search for productivity power tools in Google you'll find this page on Visual Studio gallery click the download button here this will download a vsi X file which is basically an extension to Visual Studio just double click it and it will install automatically it's very easy to restart visual studio after installation once you got the productivity power tools and go to tools and then options here's select productivity power tools and then our commands general note these two checkboxes here format document unsaved and remove and sortie usings unsafe labeling these options your code is automatically cleaned up every time you save it I think they're enabled by default anyway but it's worth double-checking here I've got a few tabs open as you see program that CS is the active tab let's say we want to open sample that CS tab I've seen a lot of developers use the mouse to change tabs here but again as a programmer you should rely on your keyboard the less you switch between the keyboard and the mouse the faster you'll be at coding so how can we switch to sample that CS tab here without touching the mouse just press ctrl + tab to cycle through the open windows like this or you can press ctrl shift and tap to go backward here is another way to do this you can press ctrl + f6 to go to the next half control shift and f6 to go to the previous staff isn't it great it's much easier and faster than using the mouse now let's look at some ways to close tabs if you want to close the current tab press ctrl + f4 it's gone see let me share another two take with you that's going to increase your productivity significantly when I work I always focus on only one task at a time each task is a small piece of work that I can finish within 40 minutes or less that usually requires very few files or taps to have open and visual studio there are a couple of great benefits to this first it helps you get focus by reducing distractions you should only have the files open that you really need to work on the second benefit is that it makes it easier to switch between tabs imagine if you had 10 or more tabs open here every time you press ctrl + tab you see lots of items to cycle through this wastes a lot of time and energy so I highly recommend you to have only very few tabs open that you really need after you finish each task clean up your workspace by closing all the open tabs a fast way to do this is to press Alt W&L now you may ask how can I open files for my next task without going to solution Explorer the answer is to press control and coma this brings up the navigate dialog which is extremely helpful with this dialogue you can type the name of a file a class or even a method and quickly open that in Visual Studio there's no need to grab the mouse and open the file by a solution Explorer let me type method to here as you see it shows all the places where I have a method by the name of method two now we can hit the tab key to move focus to the results and then use up-and-down arrows to select an item then we press ENTER and there you go Visual Studio open the file and even put the cursor right at the beginning of the method let's open the navigate dialog again so I press control and coma a type program as you see we have two items in the results the first one represents the class while the second one represents the actual file isn't it great imagine how much time you would waste if you had to use the mouse to expand and collapse folders in the solution Explorer to find a file especially the larger your project the harder it gets to find a file in solution Explorer as you saw if you know the name of a file is much faster to look it up here so next time you switch the mouse to open a file very solution Explorer or close a tab remember that you can do the same with keyboard and save yourself lots of time and here's one more trick for this lecture you're gonna love this press shift alt and enter this takes you to the full screen view of the current tab it's much easier to focus on this tab without any distractions to exit the full screen view just use the same shortcut shift alt and enter sometimes when you are dealing with long blocks of code it's better to collapse the blocks you are not interested in so you can focus on a small part of the code take a look at this code let's say we want to work on method 1 as you see method 2 is long method and is distracting we can put our cursor anywhere in the method or on the declaration line and press ctrl + M twice see what happened it's much easier to focus on method 1 now later if you want to expand method 2 you can use the same shortcut to expand it like this note that you can apply this shortcut at any level for example we can put the cursor here near the Declaration of the class and collapse the entire class or even the namespace let's say in this class we would like to create a private field of type code inspector and initialize it from the constructor typically this is how most developers write this code without using resharper you okay now let's see the resharper me so we just declared the private field first okay now notice blue underlined here whenever resharper's sees something in your code that can be improved it underlines it like that if you put the cursor here where the underline is we also get this icon on the left side a yellow bulb is like a warning in this case because we declared this private field but never used it or initialize it resharper is wondering why when it is in the first place maybe something is missing so so at this point we can activate resharper's commands using alt and enter this is what I call a golden shortcut you're gonna see me using this shortcut over and over and over all right so now let's take a look at what we can do with this resharper is suggesting three things we can do to improve this code we can initialize it from the constructor we can remove it because it's not used anywhere or we can comment it out in this case we want to initialize this from the constructor so let's select the first item there you go so our private field is initialized from the constructor this is much faster than manually writing this code we could also write this code by starting from the constructor first and then having resharper create and initialize a private feel for us let me show you how it works first we create a constructor using the seat or code snippet remember this I told you this in the code snippets lecture okay now we define an argument for this constructor we just type CI as in short for cone inspector this is the camel humps that I told you earlier then ctrl + space for resharper to suggest the name and now alton enter to activate the refactoring commands and select the first one when you do this a few times you're gonna get really fast at it and you'll do it without even thinking about it let me show you how I do this you
Info
Channel: Programming with Mosh
Views: 504,222
Rating: undefined out of 5
Keywords: visual studio, visual studio tips, c#, .net, code snippets, resharper, Microsoft Visual Studio (Software), code with mosh, programming with mosh
Id: JhxC-K-Eehg
Channel Id: undefined
Length: 18min 18sec (1098 seconds)
Published: Mon Oct 06 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.