Skip to main content

Vim

General

Concepts

  • vim is an editor than comes preinstalled on just about every computer you’ll ever use
  • it exists in the command line, so you get to it by opening a terminal and typing vim <your-file-name-here>
  • once you’re in the vim editor, your keystrokes now work differently depending on what mode vim is in
  • vim has four modes: normal, insert, command line, visual
  • in insert mode, typing “j” will insert a “j” into the document at your cursor position (as any other editor would)
  • in normal mode, though, “j” will move your cursor down a line and not insert text
  • keeping track of what mode you’re in is a key concept in understanding how to use vim (and why your keystrokes are doing weird things)
  • vim assumes you’ll spend more time editing and moving around your document than you’ll spend inputting new text, so rather than making insert mode the default, vim defaults to normal mode. You’ll spend most of your time in normal mode and just hop out of it now and then to insert text, etc.
  • tip: get in the habit of switching back to normal mode as soon as you’re done inserting text (don’t sit in insert mode); you’ll almost always want to enter a command that only works in normal mode next, so save yourself the hassle of seeing your command inserted as text you don’t want by jumping back to normal mode by default every time you pause
  • don’t try to memorize everything! you can go far with just a few memorized keystrokes (e.g. “d” means delete, “w” means word)
  • thinking of vim as a language, makes it much easier to learn than thinking of it as a long list of commands to memorize
  • by learning the general grammar, you can memorize a small number of keystrokes and then compose them into thousands of specific commands
  • start gradually: first use VSCode plugin and just start moving the cursor in normal mode instead of using the mouse or arrow keys; gradually build up to editing text with normal mode commands, etc; eventually move to using vim in the terminal and customizing your vim settings and plugins using your .vimrc file; no need to jump straight in, though!
  • really useful screencasts and courses that helped me get started: …
  • useful cheatsheets: …
  • these blog posts also act as my personal evergreen cheatsheets and group things in the way that makes the most sense to me (hope it helps you too)
  • get help with :h {what you’re wondering about}

Settings

  • How to DEAL with Vim Swapfiles • Swapfiles are important backups that prevent data from being lost if your system crashes or you accidentally edit the same file in two vim instances at once. This short video demonstrates how to parse their error messages and why disabling them is risky • DevOps Toolbox 📺

Vim vs Neovim

Neovim updates

Inbox