Syntax Video
MAXIMUM VS Code Productivity β Navigating Codebases Quickly
- 0:00 Intro
- 0:47 Navigate based on Cursor Position
- 2:11 Jump to Last Edit Location
- 2:42 Navigate based on Recent Locations
- 3:35 Goto Line and Columns
- 4:06 Fuzzy Search Files
- 4:38 Goto Symbols
- 4:53 Goto Symbol in Workspace
- 6:19 Quick Text Search
- 6:57 Goto Definition
- 7:20 View References
- 8:08 Line Bubbling
- 8:58 Move + Select by Word
- 9:39 Select by Word camelCase
- 10:52 Expand to Scope
- 10:55 Expand to Quotes
- 11:52 Toggle Quotes
- 11:54 Toggle Quotes
- 12:17 Breadcrumbs
- 13:12 Goodbye
Intro
one of the biggest productivity gains you can have as a web developer is getting very good at navigating through your editor I'm talking about being able to find the function that it is you're trying to work on be able to open up the file that it is that you need being able to navigate between two different parts of the codebase that you're working on or uh be able to select and highlight and cut and paste and edit the parts of your codebase without having to spend too much time on it if you can get really fast and efficient at those things you can have a lot more time to actually work on solving hard problems in your codebase so this is 15 or so of my favorite techniques for doing it some of them are just little tips and tricks and other ones are reframing sort of how you think about navigating through your codebase you have here is called go back and if you need to know what the keyboard shortcuts are I'll throw them up on the screen but you can always open up your command pallet with the command shift p and just type in the name of the command that we're doing you're going to
Navigate based on Cursor Position
want and do this because it will also tell you the keyboard shortcut for what it is that you're working on um and for things you don't use frequently you can't remember the keyboard shortcut it's still worth knowing about these commands so you can run them in the command pallet so go back will sort of track where your mouse cursor is so if I open up this social stats. TS and I click on this get action word here and then I scroll down and I click here and then I'll scroll up and click there if I hit control minus it will allow me to jump back to where my cursor last was and if I throw shift into the mix it will will go forward and I really like that because you can stop thinking about oh where was I or or you're hitting like sometimes people will undo redo just to get their cursor to jump back to that position um so jumping back between cursor and it also works on on multiple lines right here I'm just going to open
this file and now I'm going to open up this file and if I hit control minus I it just will open up the files a lot of people don't even keep tabs open they're simply just jumping between the locations of where they last were next one is being able to jump back to where your last edit location was so if I make an edit right here and I give a save and I'll go paw through a couple of my other files here and I'm looking around at what I want now I say okay well I want to go back to where I just actually edited you hit command K command q and that will jump you right back to your last edit location if you just uh type in go to last edit location it will show you the shortcut for that next one we have here is being able to switch tabs based on the recency of their navigation so if you hold down control tab shows you a list of all of your open tabs and the most recent ones being at the top right so if you somebody just hit that
Jump to Last Edit Location
Navigate based on Recent Locations
really quickly command tab command tab you're going to just toggle back between your most recent two values and that's really handy if you're working on templating in CSS at the same time now if you hold it down you can of course cycle through all of them and then you can go even further if you just search nav location in your command pallet you'll see that there are commands to move forward and back inside of that actual stack you'll notice I don't have keyboard shortcuts assigned to them because I find myself just being able to use command tab or control tab uh just cycle between my most recent ones it's very similar to how applications work in Mac OS go to line number and go to column this one's not all that handy but if you have a stack Trace that tells you have an error on line 22 simply open up your command pallet colon 22 that brings you to line 22 you can also put a colon 10 on the on the end of that and that will bring you to the column 10 I don't use the column all that often except
Goto Line and Columns
when I have a minified JavaScript bundle and I it's tells me something like line one of course it's all on one line but you want to go to character 3000 to be able to see what actually went wrong you're probably aware that you can open up files as well so if you hit command p and you search something like tb. TS you can open up the file by that specific name and and you're you're up and running right there right I often use that with fuzzy search as well because things like nextjs have everything named page. TSX um so if I'm looking for the tips page I'll just type in like tips and Page there and now it will fuzzy search it based on the contents of that search now going to a specific file is good but going to a specific symbol is even better so in vs code a symbol is something like a function or a variable or a CSS selector or a markdown heading so if you open up your command pallet
Fuzzy Search Files
Goto Symbols
and then type in at this will show you a listing of all of the symbols in that specific file and if you put a colon on the end it's actually going to group them based on the type of symbol that you want so you see I have two functions in this file and six different variables that searches in the current file but you can also search on a workspace level so if you hit command t or if you open up your command pallet and put a pound in there it's going to give you every single symbol in the entire project and you can then quickly search for what it is that you're looking for so here I'm looking for something related to the database and it's showing me all of the DB symbols that are in my whole project that's great because if you can move from thinking in terms of your project as a bunch of files to I just need to jump to
Goto Symbol in Workspace
either where I last edited this thing or where I was last looking at it with my cursor or I need to move to this spefic specific function I don't know where it is I might not even care where it is a lot of people just hide their tabs because they don't care about it I just want to go to wherever that function has been defined and being able to open up that symbol right like this let's go to get DB boom immediately brings it right to me so open up your command pallet we've talked about using at we talked about using pound to go to symbols but you can also just use the command pallet to do a search in your files with the percentage sign so if you type in percentage sign in something like DB that will search your entire project for the word DB and you can just kind of go through it all and it will preview them in real time this is much better than the sidebar search um for when you're quickly just trying to find something in your project I'm big fan of it you can click on this button right here to open
Quick Text Search
up the sidebar search if you do need a bit more features but I always reach for the quick Tech search before opening up my sidebar next what we have here is being able to go to definition and go to references so you working on some code you say oh this function get DB where is that defined right don't go and open up your search and search for the name of that function you can simply just hold on control and click it and that will click through to where the actual function is defined if you want to manually do it you can rightclick go to definition and that does the same thing now the opposite of that is where is this function being used that is references so uh you can either just click it via your sidebar or I will just hit F12 and that opens up this little peer which will show you both where the function is defined as well as where else in your codebase is it both imported as well as being used I find this a really great way to Traverse a
Goto Definition
View References
code base that you are unfamiliar with because you don't know where where anything is you can simply just click through to all the pieces vs code knows about your application knows about your Imports and your ports knows about all of your symbols so rather than doing everything based on text search use the references and symbols on how they're all connected to each other all right let's talk about editing lines of code uh rather than moving from file to file first one is copying a line up or down so I have this file here and this line needs to be duplicated so I'll hit my option shift Arrow key and down and that will duplicate the line and put me on that line if you want to stay on the line you can use the other arrow keys you go up and that will duplicate it underneath it but keep your cursor on that current line now I also really like to use what's called line bubbling which is I want to move this line up in this array so what I'll simply do is hold my option key and use my arrows and this
Line Bubbling
will bubble it up and down it works with multiple lines as well so you can move them up and down I use that all day long to rearrange items that are inside of it next we have have the ability to move and select and move your cursor by line by word by file by letter so this is really important for being able to move around quickly without having to use your mouse so of course you know how to move letter by letter you just use your arrow keys um but most importantly I find myself just almost always just moving through word by word so if you throw your option or alt into the mix and use your arrow keys now all of a sudden we're jumping word by word right and you'll notice that this post table right here by the way if you hold you throw in shift that will allow you to select word by word or letter by letter depending on what you're you're doing um but you see I have this post table here and it assumes that post table is is one word now under using underscore gang won't care about this but if you're
Move + Select by Word
Select by Word camelCase
using camel case you want to be able to select word by word you can throw in uh control into the mix and what that will do is now you're jumping word by word but it's taking the capital into account so I have this post table here and I want to select the actual just the word posts right I could like a sucker hit my mouse five times um but you can hit option control shift and right arrow and now that just selects just the word posts and then I'm going to hit my command D two more times to select the other instances that I have and I can just go ahead and rename it to the values that I'm looking for so jumping word by word is really good being able to jump to the beginning and the end of the line is really key so that's just holding command um and using my arrow keys to jump back in fourth if a line is wrapped you'll see that this line right here is wrapped around the thing you hit it once to get to the end
of the line uh the visual line and then you hit it a second time and that's going to get you to the actual end of the line now once you do have something selected sometimes you want to expand the amount that you are selected so if you open up your command pette and just type in expand to this expand selection to scope is really handy because what it will do is it will sort of just creep out scope by scope um and allow you to do it so sometimes you got to do it a couple times to get exactly what you want oh there we go the whole object that I'm passing to this argument now I have that selected I can go ahead and cut it and put that into a value here and then go ahead and pass the query in there now I love that but it doesn't work with strings and almost always I'm finding myself needing to select everything inside of a string so I have this plugin called quick and simple text selection and what it does you can hit command K and then just a semicolon and
Expand to Scope
Expand to Quotes
it will expand your selection to the stuff that is inside of the quotes works with backck single and double quotes you can also use the same plugin to toggle quotes which I find really handy so if I have a string right here and his name of web almost always have use pretty or something like that it'll just fix the quotes but if you do need to explicitly toggle what the quotes are guess if we just hit our Command quote and it will cycle your string through the three different kinds of quotes that you use in JavaScript or two different kinds of quotes that you're using in um whatever other weird language you're using last little tip I have here is turn on breadcrumbs this little bar right here in vs code shows you your breadcrumbs and it shows you um kind of where you're at and nested inside of your code base um but it can be really handy if you want to uh be able to switch between symbols that are in your project see like look at this we've got all the different symbols there and you can quickly find one if you want to be able
Toggle Quotes
Toggle Quotes
Breadcrumbs
to click through them but what I find it really handy is if I want to switch files and I know that something is like a sibling of it but I don't know what the file name is called I don't know what the function is called so you just click on the name of the file and look it oh there's all my sibling files right you can click on one of those of course you can go up much higher and see all the different folders that are in there again I find that much better than opening up the sidebar uh to be able to hunt around for it that's all tips I have for you if I missed anything if you have any tips on how to move around what are your favorite ones please leave them down in the comments below cuz I'd love to hear
Goodbye
Quote it with credit and a link. Quoting Syntax