Live data from Hacker News

Ask HN: How Do You Navigate Code?

news.ycombinator.com

11–20 of 39 posts

Re: Ask HN: How Do You Navigate Code?

#12

I would just remember some keywords in either code or the file name and do global search, I barely use splits though bc I think it’s kinda distracting.

Yeah, I also don't really like splits, they just don't feel very scalable. If I just need to open one or two other files they're fine temporarily, but more than that and everything becomes too small. Maybe if there were something that let you zoom in and out, like a Figma canvas, so that you could organize the files spatially in some order that makes sense to you (this is another thing that annoys me about just opening tabs in my editor, they're never really ordered in any meaningful way). If you could do this not just for files but for selected lines / ranges / functions / classes to keep things tightly scoped that would be awesome. I believe this sort of thing was something the original LightTable video explored, but I don't believe it was ever actually implemented.

Re: Ask HN: How Do You Navigate Code?

#13
post #10

I had a similar requirements some time ago - I thought one nice way would be to write a Markdown file to be read inside VSCode with links to the files' lines/positions, but couldn't find an extension that worked like this. Settled for "Bookmarks" at the time. The "Code Tour" extension can also be used for this.

Ha, that's kind of where I'm leaning now, I thought of the same thing in another response in this thread. It seems like it's lightweight enough to stay out of my way but flexible enough that I can have some control over how I organize things, and being able to quickly add some prose to describe why that particular link is relevant would be great.

Re: Ask HN: How Do You Navigate Code?

#14

NeoVim + language servers + global search with rg + a bunch of keyboard shortcuts: - gd = go to definition - gr = open a hovering window filled with references to symbol This is enough to get through every codebase I've yet encountered (Go, Typescript, Python, Java, C++). I also like to use and in vim which allows you to jump between the most recently viewed locations. For keeping context, I just write everything dow…

Are those keyboard shortcuts part of the LSP server?

Re: Ask HN: How Do You Navigate Code?

#15
post #7

Earlier quoted context omitted.

I use these as well, but maybe something I didn't articulate well is that it's often useful to remember where I've been. One thing that I haven't played with in VS Code but that bites me a lot (and sorry, I don't know the proper name for this setting/feature) is that often when you're navigating you're doing so in the same vs code tab. If I remember to double-click the tab it'll hang around, but that's a pretty janky…

Sourcegraph Notebooks PM here. We have a notepad feature you can enable that basically does what you're describing and allows you to create a notebook from the saved content in one click. There's a button to enable the notepad on the notebooks page ( https://sourcegraph.com/notebooks or /notebooks" rel="nofollow">https:// /notebooks ). It follows you around as you navigate search results and files and you can add sea…

I just discovered this feature so I haven't played with it enough yet but it seems to tick all my boxes. One thing that I found confusing about the UX though was that I didn't realize at first I could continue searching around and adding content, so when I added my first bit of content and clicked "Create Notebook" and then subsequently navigated somewhere else and wanted to add content I ended up creating another notebook instead of adding it to a pre-existing one. Or sometimes I come back and want to add more content to an existing notebook, but I don't see how to do that.

Re: Ask HN: How Do You Navigate Code?

#16

I use VSCode and mostly navigate via: F12: Go to definition Shift+F12: Go to usages Ctrl+-: Go back Ctrl+Shift+-: Go forward Once you get used to it, it's as easy as browsing the web. Since I started using VSCode I did not have to work with codebases that were complex enough to make these features valuable but some VSCode language extensions support tree views of call hierarchies and type hierarchies. Here's the docu…

I use these as well, but maybe something I didn't articulate well is that it's often useful to remember where I've been. One thing that I haven't played with in VS Code but that bites me a lot (and sorry, I don't know the proper name for this setting/feature) is that often when you're navigating you're doing so in the same vs code tab. If I remember to double-click the tab it'll hang around, but that's a pretty janky…

I find the Peek windows handy (the default experience for Find All References and the difference between Go to Definition and Peek Definition).

I find VS Code's Outline tool quite handy. By default it's hidden away at the bottom of the main Explorer tab, but you can turn on the Secondary Sidebar (now with a button at the top of the window) and drag it over on to the Secondary Sidebar to really give it room to grow and not fight your file explorer view for space. (Timeline I also like to move into the Secondary Sidebar as a good place for it.)

Outline resembles the Breadcrumbs at the top of an editor and even if you don't have great bookmarks, being able to quickly expand to a specific symbol in a file is handy.

Also Back/Forward mostly work pretty well in VS Code. If you've got the extra mouse buttons that can be used for Back/Forward in a browser those work well, as does the most common browser shortcut Alt+Left and Alt+Right. In very recent versions you can right click the Title Bar and turn on the Command Center and it gives you Back and Forward buttons there in the title bar, even more like a browser.

(ETA: holding Ctrl+Tab gives you a History menu in the order of Back/Forward sort order.)

> One thing that I haven't played with in VS Code but that bites me a lot (and sorry, I don't know the proper name for this setting/feature) is that often when you're navigating you're doing so in the same vs code tab. If I remember to double-click the tab it'll hang around, but that's a pretty janky workflow, and I don't ALWAYS want to do that.

This is called "Preview". If you don't double click to open the file, you can double-click the tab itself later if you decide to want to keep it open. (There's also Keep Open on the context menus and it has a keyboard shortcut of Ctrl+K Enter.)

You can entirely disable Preview with the Settings key "workbench.editor.enablePreview". (Set it to false. Or uncheck it in the UI.) You could make it apply to only a specific workspace while you are trying to navigate it by adding that to a .vscode/settings.json file in the project (though this specific Setting, I probably would try to avoid checking in to your project repo to avoid annoying other users).

Re: Ask HN: How Do You Navigate Code?

#17
I have a weird workflow I think. I use ripgrep in the terminal to find relevant files and then run `subl $FILE` to open the file in Sublime Text in the foreground. Sublime knows to open the file in the window where the directory is already opened as a project.

I should probably use an IDE but I just don't like them. Sublime is insanely fast and lightweight. I don't want to wait for anything to happen and I find my current workflow allows me to navigate codebases quickly anyway.

Re: Ask HN: How Do You Navigate Code?

#18
Depends on what I am trying to achieve.

Most code (especially legacy code) has more branches than typically matter: the majority of branches is error handling or special cases and can be ignored when investigating core functionality. Executing the happy path test case for the functionality I want to extend or bug fix and then stepping through the code with a debugger or manually is my usual mode.

I use IntelliJ myself. Being able to step through with a debugger can be a huge help to show actual implementations used in polymorphic code but few test suites are sophisticated enough to guarantee the possibility. Sometimes I will refactor code simultaneously in order to make it more comprehensible; that obviously requires some tests and experience but if you have the tests take the time to gain the experience and otherwise write the tests! Especially BDD style tests, the kind that survive refactoring.

Re: Ask HN: How Do You Navigate Code?

#20
post #7

Earlier quoted context omitted.

Sourcegraph Notebooks PM here. We have a notepad feature you can enable that basically does what you're describing and allows you to create a notebook from the saved content in one click. There's a button to enable the notepad on the notebooks page ( https://sourcegraph.com/notebooks or /notebooks" rel="nofollow">https:// /notebooks ). It follows you around as you navigate search results and files and you can add sea…

I just discovered this feature so I haven't played with it enough yet but it seems to tick all my boxes. One thing that I found confusing about the UX though was that I didn't realize at first I could continue searching around and adding content, so when I added my first bit of content and clicked "Create Notebook" and then subsequently navigated somewhere else and wanted to add content I ended up creating another no…

That’s great feedback, thanks. We deliberately kept adding to existing notebooks out of scope for the first Notebooks release but had a feeling it would be requested pretty quickly.

It might also be more intuitive to clear out the notepad after a notebook is created but curious what you think.

Thanks again for the feedback, feel free to reply here if you have any other thoughts.

Post reply on HN