Last modified 2023-07-25.
Time to read: 4 minutes.
Opening A File
To open a file, simply provide the file name on the command line.
For example, to open
$ code abd/xyz/my_func.c
If VSCode has at least one window open, the top-most window will open a new tab containing the desired file. Otherwise, VSCode will launch, with the desired file displayed in an editor pane.
This works with relative and absolute file names.
You can type the incantation into any command console, such as
You can also use the console built into VSCode,
which can be toggled with Ctrl-~,
or you can use an external console such as
Opening A File At a Line
To open a file at a given line number, use the
-g option on the command line,
and follow the file name with a colon and the line number.
For example, to open
abd/xyz/my_func.c at line 123, type:
$ code -g abd/xyz/my_func.c:123
Useful Default Key Bindings
- Toggle visibility of the current Terminal pane in the lower panel.
- Toggle visibility of the Explorer view, which contains the files and directories for the VSCode project.
- Toggle visibility of the lower panel, containing Problems, Output, Debug Console, Terminal, GitLens and Watch.
- Ctrl+K M
- Set the language mode for the file displayed in the editor.
- Ctrl+K Ctrl+S
Display / edit the Keyboard Shortcuts definitions.
You can filter the keybindings by pressing Alt+K or clicking the icon of the little keyboard at the top right of the Keyboard Shortcut page, then press the keys that you want to see the key binding for. \ The keyboard icon starts keystroke recording mode. Recording mode is sticky; each time you revisit the Keyboard Shortcuts tab you can just press the keys you are interested in to see their bindings. Step by step:
When you press the Ctrl key you will see
"ctrl"displayed, and recording mode continues to listen to what you type. Don't do this right now, but FYI, if you toggle keystroke recording mode now, and then remove the quotes around
"ctrl", you will see a sorted list of all the key chords bound to Ctrl.
Next, when you add the Shift key to the key chord, you then see
"ctrl+shift"displayed. Don't do this right now, but FYI, if you toggle keystroke recording mode now, and then remove the quotes, you will see a sorted list of all the key chords bound to Ctrl+Shift.
- Finally, adding the = key to the key chord shows all the commands bound to Ctrl+Shift+=.
- When you press the Ctrl key you will see
- Ctrl+K+0 (zero)
- Completely fold the active editor contents.
- Ctrl+K+1 (one)
- Fold level 1 the active editor contents.
- Fold level 2 the active editor contents.
- Toggle side bar visibility.
- Show names of recently opened tabs, which might contain files to edit, or might be VSCode settings, or VSCode key bindings, etc. Click on a tab name to open it. This key binding is bound to Go to File, which is somewhat logical but not the most descriptive name.
- Open the Command Palette.
- Ctrl+L G
- Open the active (currently edited) file on GitHub in the default web browser. Requires the Open in GitHub extension.
- Ctrl+, (comma)
- Open the Settings tab.
- Reopen the most recently closed editor tab.
- Format the current file.
Annoying Side Bar Auto Reveal
When editing a file, if you Ctrl+click on a function, method or class name defined in a dependency, the dependency's folder will be expanded in the side bar. Some dependencies are deeply nested, which means that the side bar expands quite a lot. In order to close the folders in the side bar it is necessary to go all the way back to the top of that folder, which is annoying and wastes time.
In settings, look for Explorer: Auto Reveal, which controls whether the explorer should automatically reveal and select files when opening them.
To do that, bring up settings with Ctrl+, (comma),
and then type
reveal ex into the filter.
The default value is
Change the value to
Bonus: Reveal Active File in Side Bar
To scroll to a file that you are editing in the list of files in the side bar, right-click on the file's tab, then select Reveal in side bar.
Even better, define a keyboard shortcut to do this:
- Bring up the Keyboard Shortcuts definitions by typing Ctrl+K Ctrl+S.
reveal sideinto the search bar.
- Double-click on File: Reveal Active File in Side Bar.
- For my desired key shortcut, I pressed Ctrl+Shift+Alt+R, then pressed Enter.
User settings are stored in
%AppData%\Code\User\ on Windows, in files called
Project settings are stored in
.vscode/ on all platforms, in files called
Workspace settings are stored in files with a
They can be painful to work with because paths in them are OS-dependent.
Extensions are stored in