Little trick I use to navigate source code better
Here’s something that I use to quickly jump through various places in the code to find the exact place that I need.
I use quite a few comments in my code and in these comments I love to leave a small trace. A way to distinguish between a comment and a jumping point. For me this jumping point is an underscore symbol.
One of the big reasons why I use an underscore symbol for it, is that it is extremely simple for me to insert it. With Karabiner I have made a binding to insert _ by pressing and holding i key and then pressing s. Essentially I can insert this symbol by pressing two keys whilst keeping my hands on the home row the whole time. There are many many neat things you can do with keyboard rebinding and especially Karabiner and I am still uncovering all of its implications but this is one of those things that arises once you start manipulating and hacking your keyboard to fit your own workflow.
It also really helps that I have / symbol binded to i + a. That is I press i key and hold and then quickly press a. The beauty of that is that / is search in vim and all of the vim plugins that exist out there. With these two bindings searching for my jumping points is staggeringly fast. Whilst in normal mode of vim, I press i, then a (to go into search mode), then press s (whilst holding i) and then I type the place I want to jump to.
Searching through the source code in this way is extremely fast as I can essentially mark certain sections in the code and even though the names of these sections can actually be used somewhere else in the file, I know that _ followed by the word will most certainly not be there and thus I don’t have to scroll through results.
Just as example, here is my hammerspoon configuration :
There are certain downsides to this technique though. Mostly since its a very individual style technique, you can’t really use it in the big codebases you will be working with that have their own often enforced style guide. The jumping points will make sense to you, but might often not make sense to other people reading the code. Although in honesty, they don’t really subtract anything from the readability of the source code. It’s just one symbol prepended to certain sections of comments.
With that said, I use this technique very often and it most certainly saved me quite a good chunk of time. The biggest file that I have ever had to work with is currently my configuration for Karabiner which spans 10,000 lines. Thus having these little code checkpoints is very useful for me.