Navigation5:41 with Dean Davidson
Learn how to easily navigate projects and files, remap keyboard shortcuts to suit your personal preferences and use Outlining to make large classes easily readable.
[SOUND]. 0:00 Hi, I'm Dean, and I'm a software engineer. 0:05 Writing software is a rewarding but difficult job. 0:08 Luckily, we have tools like Visual Studio to help us along the way. 0:11 Like any other tool, 0:15 your level of efficiency will be determined by how you use it. 0:16 In this workshop, we're going to go over some tips and tricks that will save you 0:19 time and put you on the path to becoming a Visual Studio power user. 0:22 Let's get started with something that you'll spend a lot of your career doing, 0:27 navigating projects and code. 0:31 If you're anything like me, you'll probably find yourself in a state 0:34 where you have quite a few tabs open in Visual Studio at any given time. 0:36 The ability to manage these tabs efficiently will help you immensely when, 0:40 for example, you're switching between an HTML file and a CSS file that affects it. 0:44 Keyboard shortcuts are a quick and 0:49 natural way to manage your tabs without taking your hands off your keyboard. 0:51 If I hold the control key down and 0:55 press tab once, I'll see a list of currently open tabs and tool windows. 0:56 My current tab shows up at the top of the list followed by my 1:01 other open tabs in the order in which they most recently had focus. 1:04 When I release the control key, the highlighted tab will gain focus. 1:08 Since my previously focused tab is now position two, 1:12 I can quickly switch back to it by pressing Ctrl+Tab again. 1:16 To close a tab, press Ctrl+F4. 1:20 If your tabs become too cluttered, you can close all but 1:22 one by right clicking on the tab you wish to keep, and selecting close all but this. 1:26 If you want to get rid of all of your tabs, right click on a tab and 1:31 select close all documents. 1:34 Next we're going to check out navigate backward and navigate forward. 1:38 You can use these buttons if you prefer them over keyboard shortcuts. 1:42 I like keyboard shortcuts, so I'm going to use those. 1:46 I'm curious about this method, so I'm going to navigate to definition and 1:53 check it out. 1:57 With my curiosity satisfied, I want to go back to exactly where I was previously at. 1:59 Navigate backward control hyphen, will bring my cursor back to where I left off. 2:04 Navigate forward control shift hyphen, 2:10 will bring my cursor forward to history again. 2:13 Visual Studio tries to only remember interesting changes, which means that if I 2:17 only move my cursor one line away, it won't create a new history entry. 2:21 Sometimes we have to deal with extremely large files. 2:28 Outlining is designed to make this task more manageable by collapsing and 2:31 expanding text. 2:34 Take this large class for instance, just scrolling through it is time consuming. 2:36 Let's see what happens when I collapse to definitions by holding the control key and 2:41 pressing M then O. 2:46 Now I can easily scroll through and look at the method definitions. 2:50 When I want to expand text that has been collapsed, I can press the plus icon to 2:55 the left of the text, or put my cursor on the hidden text and 2:59 use the keyboard shortcut, Ctrl+M, to toggle outlining expansion. 3:02 When developers talk to each other about code, 3:09 an easy way to reference specific lines of code is by line number. 3:11 Let's say somebody has a question about AccountController.cs line 315. 3:15 We can navigate to line 315 using the shortcut go to line. 3:20 Press Ctrl+G, input the line number you want to go to, and 3:25 press Enter to go there. 3:28 Another handy trick is scrolling a document using your keyboard. 3:30 If you press the up or down arrow it will move your cursor, but won't scroll 3:33 the document unless your cursor is at the top or bottom of the screen. 3:36 If you hold the control key, 3:43 the up and down arrows immediately scroll the document. 3:44 Note that Visual Studio will automatically move the cursor before allowing it to go 3:49 off screen. 3:53 Find matching brace allows you to navigate between opening and 3:58 closing braces or tags. 4:01 On this method, I am at the opening brace and I can find the matching, in this case, 4:03 closing brace by pressing Ctrl ]. 4:07 Note that Visual Studio also highlights the matching brace visually. 4:12 The same method can be used to find opening and closing tags in HTML. 4:16 This can be really handy with larger HTML files. 4:20 Now that you have a feeling for how powerful keyboard shortcuts can be for 4:23 navigation, I'm going to show you how to remap your keyboard shortcuts. 4:26 Some commands aren't mapped to anything by default, and 4:31 others you might want to remap because you don't like their default mapping. 4:33 Lets say, I want to map find matching brace to control fb, for find brace. 4:37 Go to tools, options, environment, keyboard and search for brace. 4:43 We see at the command is named edit.gotobrace. 4:51 Put your focus in the press short cut keys text box and 4:55 press the shortcut keys you want to assign. 4:58 After they show up press assign. 5:01 We can now use control F, B, for find matching brace. 5:07 Watch out for accidental keyboard shortcut collisions. 5:12 If I try to assign control B to this shortcut, 5:15 Visual Studio will show me that is already in use. 5:17 Assigning control B to find matching brace will remove it from debug.function 5:20 breakpoint. 5:25 That's it. 5:27 With these shortcuts, you should be able to quickly navigate projects and 5:28 files with ease. 5:31 You're already on your way to becoming a Visual Studio power user, and 5:32 we're just getting started. 5:35 In the next video, I'll show you how Visual Studio can edit your code for you. 5:36
You need to sign up for Treehouse in order to download course files.Sign up