VSCode indentation navigation made simple.

Dec 20, 2023 | Accessibility, Powershell, Python, Scripting and programming, Server administration, Technology | 0 comments

It could be PowerShell, Python or Yaml. It doesn’t really matter too much. Some languages obviously require indents for code structures where others require brackets but coding in any kind of collaborative environment requires that your code is readable therefore indents are required regardless. So navigating through code based on indentation level is particularly important and useful.

I was trying to find a way of making my prefered screen reader notify me when indentation levels changed when I stumbled on a handy extension for VSCode called “Indent Nav“.

I’ll explain why I love it with a very relatable example:

I’ve written some code but I’ve decided eventually that this code should be contained within an if block or I might even want to move it into it’s own function.

I move to the first line of the block of code. As it happens, I’m checking for a condition so it’s an if block. I press F9 to start selection. Then I hit alt end to move to the end of that block and I press alt f10 to mark the end of the selection. Job done! I hit control C, type my new if block or create the function and I paste. This is a simple example but it saves vital time.

Or the other example is I’m using splatting. The splat is long. I could arrow through every line while reading the code but I don’t need to. I press alt and down to move to the next line at the same indent level and I skip it all.

Yes, I could use code folding to skip code blocks that I don’t need to read but sometimes out of sight out of mind is not a good thing. I like to have the code there on screen without using folding unless it’s at the function level as it’s very easy to miss vital clues when debugging if your cursor automatically skips over blocks of code. That’s probably jsust me though.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.