Skip to content

VS Code shortcuts for Python developers

Beginner-friendly · 10 min · Windows & macOS

You don't need to learn 100 shortcuts. The 25 below cover almost everything you do while writing Python — learn one group a week and you'll stop reaching for the mouse.

The only shortcut you must remember

Command Palette — Ctrl+Shift+P (Windows) / Cmd+Shift+P (macOS). Type what you want ("format", "select interpreter", "toggle word wrap") and VS Code finds it — and shows its shortcut next to it.


1. Move around fast

Action Windows macOS
Open any file by name Ctrl+P Cmd+P
Go to a function/class in this file Ctrl+Shift+O Cmd+Shift+O
Go to line number Ctrl+G Ctrl+G
Search in all files Ctrl+Shift+F Cmd+Shift+F
Show / hide the sidebar Ctrl+B Cmd+B
Reopen the tab you just closed Ctrl+Shift+T Cmd+Shift+T
Split the editor side by side Ctrl+\ Cmd+\

2. Understand code you didn't write

These are the shortcuts that make reading a big codebase — or a library like openai — easy.

Action Windows macOS
Go to definition (jump to where it's written) F12 or Ctrl+click F12 or Cmd+click
Peek definition (without leaving the file) Alt+F12 Option+F12
Go back to where you were Alt+← Ctrl+-
Find every place it's used Shift+F12 Shift+F12
Show the function's parameters Ctrl+Shift+Space Cmd+Shift+Space
Jump to the next error F8 F8

Hovering over any function also shows its docstring and type hints.

3. Edit many lines at once (multi-cursor)

Action Windows macOS
Select the next match of the selected word Ctrl+D (repeat) Cmd+D (repeat)
Select all matches Ctrl+Shift+L Cmd+Shift+L
Add a cursor where you click Alt+click Option+click
Add a cursor above / below Ctrl+Alt+↑/↓ Option+Cmd+↑/↓
Undo the last cursor Ctrl+U Cmd+U

Try it: select "role" in a list of messages, press Ctrl/Cmd+D three times, and type — all four change together. Press Esc to go back to one cursor.

4. Move and change lines

Action Windows macOS
Move the line up / down Alt+↑/↓ Option+↑/↓
Copy the line up / down Shift+Alt+↑/↓ Shift+Option+↑/↓
Delete the line Ctrl+Shift+K Cmd+Shift+K
Comment / uncomment Ctrl+/ Cmd+/
Indent / un-indent Tab / Shift+Tab Tab / Shift+Tab

5. Let VS Code fix and refactor

Action Windows macOS
Rename everywhere (variable, function, class) F2 F2
Quick fix (add missing import, etc.) Ctrl+. Cmd+.
Format the file Shift+Alt+F Shift+Option+F
Show suggestions Ctrl+Space Ctrl+Space

Rename with F2, not Find & Replace

F2 understands Python: renaming chunk won't touch chunks or the word "chunk" inside a string. Find & Replace changes every match of the text.

6. Terminal and running code

Action Windows macOS
Show / hide the terminal Ctrl+` Ctrl+`
New terminal Ctrl+Shift+` Ctrl+Shift+`
Run the selected lines in the Python terminal Shift+Enter Shift+Enter
Run the whole file ▶ button (top right) ▶ button (top right)

Pick the right Python — open the Command Palette → Python: Select Interpreter → choose the one inside .venv. This fixes most "module not found" errors in VS Code.

7. Debugging

Action Windows / macOS
Add / remove a breakpoint on this line F9 (or click left of the line number)
Start debugging F5
Run the next line F10 (step over)
Go into the function on this line F11 (step into)
Finish this function and return Shift+F11 (step out)
Stop Shift+F5

While paused, hover over any variable to see its value, or type expressions in the Debug Console. Much faster than adding print() everywhere — see Read a Python error message.


Extension Why
Python + Pylance (Microsoft) Run, debug, autocomplete and type checking
Ruff Formats and lints your code on save (replaces Black, isort and Flake8)
Jupyter Run notebooks inside VS Code
Error Lens Shows errors right on the line, not just as a squiggle
DotENV Syntax colours for .env files

Settings worth turning on

Command Palette → Preferences: Open User Settings (JSON), then add:

settings.json
{
  "[python]": {
    "editor.defaultFormatter": "charliermarsh.ruff",
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.organizeImports": "explicit",
      "source.fixAll": "explicit"
    }
  },
  "files.autoSave": "onFocusChange",
  "editor.rulers": [100],
  "python.terminal.activateEnvironment": true
}
Setting What it does
Format on save + Ruff Every save tidies spacing, quotes and imports automatically
files.autoSave Saves when you switch to the terminal — no more running the old version
editor.rulers A faint line at 100 characters, so long lines are easy to spot
activateEnvironment New terminals activate your .venv automatically

See every shortcut

Ctrl+K Ctrl+S (Windows) / Cmd+K Cmd+S (macOS) opens the full list — search it, or change any key to one you prefer.

Next: Python one-liners worth knowing →