Skip to content

Instantly share code, notes, and snippets.

@gbroques
Last active April 15, 2023 00:18
Show Gist options
  • Save gbroques/c6c820e6f07af2e8a4ec59edf7b7488c to your computer and use it in GitHub Desktop.
Save gbroques/c6c820e6f07af2e8a4ec59edf7b7488c to your computer and use it in GitHub Desktop.
My personal cheat-sheet to remember and help me learn vim commands.

Vim Commands

Language

Most editors treat inserting text as the primary action. Vim treats changing text as the primary action.

  • Verb + Noun (e.g. dw - "delete word")

Verbs (Operators)

Act upon Motions or Text Objects.

  • d - delete
  • c - change (delete and enter Insert mode)
  • > - Indent
  • v - visually select
  • y - yank (copy)

Nouns

Motions

  • w - forward by a word
  • b - back by a word
  • 2j - down 2 lines

Text Objects

  • iw - inner word (works from anywhere in a word)
  • it - inner tag (contents of HTML or XML tag)
  • i" - inner quotes
  • ip - inner paragraph
  • as - a sentence

Parameterized Text Objects

  • f, F - find the next character
  • t, T - till the next character
  • / - search
    • :noh - to clear search highlighting.

Tips

  • Try to use Text Objects instead of Motions for maximum repeatability with the dot operator.
  • Visual mode is a smell.
    • Breaks repeatability.

Configuring Vim

:h vimrc

  • Reload vim configuration
    • :so % - % stands for current file name (see :h current-file) and :so is short for :source, which reads the content of the specified file and treats it as Vim code.

Windows

  • Ctrl + W, s - Open horizontal split.
  • Ctrl + W, v - Open vertical split.

Jump List

  • Ctrl + o - Jump out.
  • Ctrl + i - Jump in.
  • :h ju

Editing

Copying & Pasting

  • Paste into vim from system clipboard
    • "+p - " Use register, + the plus register for system clipboard, and paste contents.
  • How to copy ("yank") text into your buffer and paste it over a word
    • viwp - Visual select inner word and paste

Exiting

  • Save and Quit
    • ZZ in command mode

External Resources

Plug-Ins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment