15 Useful Shortcuts to Code Faster with Visual Studio

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so who of us out there doesn't want to code or program faster means we can do more and less time means our game project can get done quicker so in this video i'm going to take a quick look at some of my favorite and most commonly used shortcuts in visual studio do you have your own favorite shortcuts that i haven't put in this video make sure to add them in a comment down below i'd love to learn something new because there are a poop ton of shortcuts for visual studio so everybody out there knows how copy and paste works if you don't it's probably the wrong video for you but a whole bunch of my students didn't know how cut works in an ide in particular visual studio or visual code what my students would do is they would highlight the entire line and then cut it out of there or press delete and that works totally fine but a much faster way to do that just put your cursor on that line hit control x the entire line is gone so another shortcut that's really valuable is commenting and uncommenting code once again you can highlight stuff right click and you come down here somewhere in here there's a commenting or what you can do is highlight the code ctrl k hit ctrl c and it comments out that entire block of code pretty quick pretty easy and if you want to undo that just press ctrl k ctrl u and it's going to undo that commenting so while we're on the topic of basic editing adding a new line is something we have to do all the time and sure you just move your cursor to the right spot and press enter but what if you're in the middle of the line you can press up you can press down sometimes you can use enter and home and kind of navigate your way there but an easier way to do this if you want to add a line up above the current line hit control and enter and you automatically get a line above where your cursor is doesn't matter where your cursor is on the line likewise if you're once again in the middle of a line and you hit ctrl shift enter it's going to add a line below it not going to break the line that you're currently on small but helpful shortcuts i love using the cut trick to delete an entire line but this next one this is one i love even more so let's say you're refactoring your code and you need to rename a variable or maybe a function or a class well the way a lot of my students do that is they just manually get in here they're like okay i don't want this to be resource i want it to be something else and then they've got this new thing and now they've got all these errors and they're copying and pasting and that works but it's slow and if that variable that function or class is used elsewhere in your project you also have to go rename it all over and all throughout the project which again it works but it's pretty tedious and pretty hard so what we can do instead is we can select our variable we just need to have our cursor on there and again this works for functions or classes i'm going to press control r control r and it's going to let me rename it and you'll notice that every instance of that variable is getting renamed at the same time and when i'm done i simply press enter or return and i've renamed everything nice easy and best of all when i go back into unity i'm not going to have a whole bunch of errors yelling at me because i've renamed something in my project a couple more really useful ones so let's say we've got this thing resource amount where it's a class defined somewhere what does it look like what does it do maybe we need to edit it well how do we find that well one way to do that is to right click go to definition and you'll notice that there's a shortcut there so i don't have to use my mouse at all i'm a mouse over that press f12 and it's going to take me immediately to the definition of that in this case it's a struct i can now edit it it's open here good to go so let's imagine that you have a function like the one here the request pickup and it's public meaning it can get called outside of this class now there's a lot of reasons why you might want to know where that's getting called maybe you're working with a teammate they've called the wrong function they've called something they shouldn't have who knows or maybe there's just some old class buried deep in your project and you've forgotten about it and it's calling this particular function so if i mouse over that and then press shift f12 it's going to show me here everywhere in my project where this function is getting called i can click on that it'll take me to both the class you can see it's opened up here and the line where it's being used likewise i can click on the other one it's in a different class here we go once again that's where that function is getting called so let's imagine you're working on a function like the one i've got here the complete request and it just grows and grows and grows it gets bigger and bigger and bigger and now that might be okay but if you're trying to follow good coding practices you want to try to keep your functions relatively small and doing just one thing so what you can do and what you should do is take that code and break it up into smaller functions now again you can do that manually or with visual studio we get a shortcut to do exactly that so let's imagine i want to take this for each loop i'm going to highlight it and i'm going to press ctrl r ctrl m that's going to give me a little warning here i'm not going to worry about this too much it's just about the return value and when i do that i get a new method i'm just going to name it some for each loop so i now have a reference to that new function with all the correct inputs and if i scroll down here i've got my new function so control r control m refactors a bunch of code into a new method all right how about this one you've got two lines or maybe more lines of code that are in the wrong place you just need to move them up well we can do that really nice and really easy let's imagine i have this line here and i want to put it up above and now sure i can copy and paste it and move it that's great but what i can also do is hold alt and the up arrow and it's going to move that line of code up through my code and i can put it wherever i want this also works if i highlight a chunk of code i can move it down line by line and i can reorder my code very quickly very easily a whole lot less key prices then copy and paste all right let's imagine you have been working a long time and the formatting is off you can look at the code here it looks horrible it's hard to follow along the spacing the indenting is all wrong now again you can manually fix this but visual studio gives us a nice shortcut to do this if we hit ctrl k ctrl d it's going to reformat our entire class with proper formatting and spacing really nice really easy on those occasions where visual studio doesn't do it for you automatically or maybe you are a partner messed up somehow you ever been working and you realize the code you just wrote needs to go inside of an if statement or maybe a while statement or something like that well of course you can manually do that or you can highlight your code press ctrl k ctrl s and it's going to bring up the surround width option and there's a whole bunch here there's ifs four eaches whiles try any of them that you like let's try an if i add an if in there it surrounds the code that i highlighted in the curly braces creates my if statement and highlights the condition for that to be true setting me up to create that if statement nice and quickly so if you've got a big class like i've got here i've got some 400 lines of code it might be hard to find the function that you're looking for and of course there's other ways to do it but maybe you just want to squish everything down and you're just tired of clicking one by one and shrinking them down well visual studio if you press ctrl m control o it'll shrink everything down or collapse everything down to its definition like so and your class becomes far more manageable when you find the function that you're looking for you can just open it up and do the work that you need to do you've got a bunch of using statements like i do up here at the top of your class now unity adds in some of those all by itself sometimes you need them sometimes you don't and if you like things to be nice and organized generally they just get put in there in the order that you put them in we can make it a little bit better so if i press ctrl r ctrl g it's going to do two things to my using statements it's going to remove any that i'm not using and it's going to organize the ones that i do have there again pretty niche but pretty nice and handy saves you a few key strokes while you're cleaning up your code all right let's imagine you're setting up some new class like i've got here and we've got a new interface up here that we're implementing and we're trying to tie into this uh delegate here and you've got these red squiggles and the reason that's showing up is because for the interface we haven't implemented all the required functions for the event we just don't have that function or we don't have a function with the correct signature that matches that delegate so we can solve this pretty quickly and easily if i come up here to the interface i can press control period it's going to bring up my quick fixes here and the first one here is the implement interface so i can click on it or just press enter and it's going to add in the function or method with the correct signature to match that interface that interface requires more than one method it's going to add them all in there nice and easy make sure that you get it right the first time spend less time going back and forth and trying to spell check or make sure you got the right signature same thing down here with our delegate we're expecting some function that's going to match the signature of this delegate now of course i could go look at the definition of the delegate figure out what the signature is and come back and create that function or once again i can hit control period and i can generate the method i get that i keep the name and i make sure that i get the correct signature for that delegate nice and happy super quick and easy to do the last two shortcuts help us with something that we've all been guilty of pretty common especially for beginning developers when you're working on something in visual studio and you want to open up a new class we go back into unity we go over here to our project folders and we find it and we open it up and that works but it's not the fastest workflow especially if you have saved work and when you go back into unity it's got to recompile and you've got to wait for that to find the file that you want to edit next so instead of doing that what we can do is press ctrl alt l and it's going to open up our solution editor here and you can notice right away you've got our assets and we've got a whole bunch of stuff here that i don't really care too much about and it's definitely a lot going on here but what i can do instead is open up maybe i wanted to look for my cargo shuttle behavior type that in there and there it is i just use my down arrow key to get to it here's my class it's ready to work on it's just a preview if i want it to stay open i can press this little button here keep tab open or if i just start editing it it will also open itself pretty useful pretty handy great way to browse your unity project without having to go back into unity now connected to that is the shift alt e which brings up the unity project explorer now this one's a whole lot more friendly it's got a lot less going on it's just the folder structure of the project that you have in unity and this is great we can find stuff here but the problem that i have with this is there's no search bar i if there is let me know i can't find it i would love for there to be a search bar here i can right click all day long i can't find one but you can do the same thing here and find your class and open it up here so if you're more comfortable with the unity folder structure you can use it here you can explore it just like you would with unity don't have to go back into unity wait for it to compile or do anything like that end of the day i hope that was interesting and better yet useful for you and your project if it was think about hitting a thumbs up or leave a comment and until next time happy game designing you
Info
Channel: One Wheel Studio
Views: 30,331
Rating: undefined out of 5
Keywords: Unity3d, Indie Game, Game Development
Id: My0o3k5hjyI
Channel Id: undefined
Length: 12min 0sec (720 seconds)
Published: Mon May 23 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.