Skip to content

Instantly share code, notes, and snippets.

@alesf
Last active April 14, 2024 19:25
Show Gist options
  • Save alesf/44e0d35c5996928cdf360e9878713b1b to your computer and use it in GitHub Desktop.
Save alesf/44e0d35c5996928cdf360e9878713b1b to your computer and use it in GitHub Desktop.
Mastering Text Editors

Mastering text editors

0. Basics

It's all about the keyboard. Try to keep your hands off the mouse.

Shortcut cheatsheet:

https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf

https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf

Shortcut cheatsheet (interactive):

https://github.com/Anze/KeyCluCask

Two most important shortcuts in most modern editors are:

  • cmd + shift + P (open command palette)
  • cmd + P (quick open file by name)

1. Navigation and selection

Keyboard shortcut combinations for navigating through text:

  • arrow keys (move cursor one character at a time)
  • option + left/right arrow keys (move cursor one word at a time)
  • cmd + left/right arrow keys (move cursor to the beginning/end of the line)
  • cmd + up/down arrow keys (move cursor to the beginning/end of the file)
  • fn + up/down arrow keys (move cursor one page up/down)

Keyboard shortcut combinations for selecting text (combine shift with the above):

  • shift + arrow keys (select one character at a time)
  • option + shift + arrow keys (select one word at a time)
  • shift + cmd + arrow keys (select to the beginning/end of the line)
  • shift + cmd + up/down arrow keys (select to the beginning/end of the file)
  • cmd + A (select all)

Random useful shortcuts:

  • cmd + / (comment out code)
  • option + up/down arrow keys (move line up/down)

2. Multicursor

Multicursor is a feature that allows you to place multiple cursors in the same file. This is useful for making the same change in multiple places at once. There are several options to create multiple cursors:

  • cmd + shift + L (select all occurrences of a selection)
  • cmd + D (select next occurrences of a selection)
  • cmd + U (undo last selection)
  • option + click (place a cursor at the clicked location)
  • option + cmd + up/down arrow keys (place a cursor above/below the current cursor)

You can combine multicursor with the selection shortcuts above to select multiple occurrences from the same starting point.

3. Find and replace

Keyboard shortcut combinations for finding and replacing text:

  • cmd + F (find)
  • cmd + G (find next)
  • cmd + shift + G (find previous)
  • cmd + option + F (find and replace)
  • cmd + shift + F (find in all files)
  • cmd + shift + H (find in all files)

Find options

  • you can use regular expressions
  • you can match case
  • you can match whole words
  • you can preserve case when replacing

Rename Symbol This is a VSCode feature that allows you to rename a variable, function, class, etc. and have all instances of it renamed automatically. https://code.visualstudio.com/docs/editor/refactoring#_rename-symbol

  • F2 (rename symbol)

4. Code navigation

Quick file navigation:

  • cmd + P (quick open file by name)
  • cmd + T (quick open symbol by name)
  • cmd + shift + O (quick open symbol by category)

Breadcrumb navigation:

  • Click on the breadcrumb at the top of the editor to show a dropdown of other files or symbols in the same file.

Go to definition:

  • cmd + click (go to definition of a symbol)
  • F12 (go to definition of a symbol)
  • shift + F12 (peek definition of a symbol)

Editor navigation:

  • ctrl + ` (go to next window)
  • ctrl + 1 (focus on first open file, ...)

Sticky scroll:

  • Shows nested scopes during scrolling.

Minimap:

  • Shows a preview of the entire file on the right side of the editor.

5. CLI

VSCode has a built-in terminal that you can use to run commands:

  • cmd + shift + T (toggle terminal)

You can forward ports:

  • cmd + shift + P (open command palette) + ports

Command line tool:

  • cmd + shift + P (open command palette) + shell command
  • code ./ (open folder in VSCode from the command line)

6. Extensions

Extensions are plugins that add functionality to VSCode. You can install extensions from the VSCode marketplace.

  • cmd + shift + X (open extensions panel)

Sysadmin extensions:

  • Remote - SSH
  • Remote - SSH: Editing Configuration Files
  • Remote - Tunnels
  • Docker
  • Kubernetes
  • Kubernetes Support
  • Kubernetes Templates
  • File Utils
  • Sensitive Replace
  • Tabnine Autocomplete AI
  • TODO Highlight
  • TODO Tree
  • GitLens
  • Git File History
  • Git Blame
  • GitLab Pipeline Monitor
  • GitLab Workflow

7. AI

Tabnine Extension (free - runs on machine, short completion, 12 USD / month for cloud) https://www.tabnine.com

GitHub Copilot Extension + GitHub Copilot Chat (10 USD / month) https://copilot.github.com

  • cmd + I (Copilot inline chat)
  • cmd + . (Quick Fix - AI suggestions)
  • ctrl + enter (Open completions panel)

Cursor (VSCode clone + ChatGPT) https://www.cursor.so

  • cmd + L (Open chat)
  • cmd + K (Open inline chat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment