4. Reading Code
VS Code offers several features to quickly skim the high-level structure of a code file. It also supports standard screen reader commands that you may be familiar with to nnavigate text. In this chapter, we will go through some basic commands and dive deaper into VS Code specific functionality. ## List of Basic commands - arrow keys move by line and character. - tab and shift+tab increase and decrease indentation. - control+up and down arrow move through units of code.
VS Code specific commands
VS Code offers several commands to read code. - F12: jump to definition. This is handy when you are trying to go to a function definition - F8: go to next error or warning. - shift+F8: go to previous error or warning. - control+k, control+q: go to last edit location.
Code Folding
VS Code, like most editors, supports the concept of code folding. In simple terms, code folding hides sections of code to show only the structure you want to see. The ability to fold code could be incredibly helpful to skim or glance through code files with many levels of nesting, or code files with a large number of lines.
When you fold code, it collapses everything under that particular indentation level. Let me explain this with an example. Consider the following Python function:
def add_numbers(a, b):
"""Add two numbers together and return the result."""
= a + b
result return result
when you move the cursor to the def add_numbers and invoke The toggle fold on that line, the entire function definition collapses into one line. You will only see the def line when you move up/down with a screen reader. VS Code indicates that the line containing the def is a folded line through an audio cue. You can unfold the folded block to read the full function definition again, by invoking the toggle fold command.
Try it yourself
- open the read_exampleCode.py file in VS Code.
- fold all by pressing control+k, control+0, or by invoking the fold all command from the command pallett.
- explore the code structure and gradually unfold each block.
VS Code also offers several other commands to fold code up to specific levels, or recursively fold code from the cursor position.