Published on

Vim KeyShort


Background

In the past, we used Vim primarily for basic text editing, without taking advantage of its powerful features. To boost our productivity, we now aim to learn advanced Vim techniques and embrace a more mouse-less workflow.

Since we use the Vim extension in VSCode, we follow the roadmap to learn and utilize Vim commands within VSCode.

Some Useful Commands

here we only list some useful commands, for more details please refer to the Vim Cheat Sheet

Motion: How to Move

  • f & t - Find and Jump.
  • ;& , - Repeat and Undo for f and t.

Text Object Move

  • ( & ) - Move to the beginning and end of a sentence.
  • { & } - Move to the beginning and end of a paragraph.

Position Jump

  • ctrl + o - Jump to the previous position.
  • ctrl + i - Jump to the next position.

Scrolling

  • zz - Center the current line in the window.
  • zt - Move the current line to the top of the window.
  • zb - Move the current line to the bottom of the window.
  • / ? - Search forward or backward, then press n to repeat the search.
  • * # - Search for the word under the cursor.

Editor Text

  • p y - Paste and Yank.
  • r R - Replace and Replace All.
  • c{motion} - Change text within a motion.
  • >> << - Indent and Unindent.
  • . - Repeat last action.
  • q{a-z} - Record a macro.
  • @{a-z} - Execute a macro.

Ctrl Commands

  • ctrl + d / ctrl + u - Scroll down/up half a page.
  • ctrl + o / ctrl + i - Jump to previous/next position in jump list.
  • ctrl + r - Redo.

Note: On Windows, ctrl + c and ctrl + v are commonly used for copy and paste in most applications. In Vim, ctrl + c is similar to Esc (cancel/interrupt), and ctrl + v enters Visual Block mode. To avoid confusion on the keyboard, here we to close the ctrl+ANY commands by the "vim.useCtrlKeys": false setting in settings.json.