DevOps
Linux
Vim Basics

Vim Basics

Vim (Vi IMproved) is a highly configurable text editor built to enable efficient text editing. It is almost always pre-installed on Linux servers, making it the "Go-To" tool for quick configuration changes.

The Three Main Modes

Vim is unique because it is a modal editor.

  1. Normal Mode: Used for navigation and running commands. This is the default mode when you open Vim.
  2. Insert Mode: Used for typing text. (Press i to enter).
  3. Command Mode: Used for saving and quitting. (Press : from Normal mode).

Essential Vim Cheat Sheet

Saving & Quitting

  • :w: Save the file (write).
  • :q: Quit Vim.
  • :wq: Save and quit.
  • :q!: Quit without saving changes.

Navigation (Normal Mode)

  • h, j, k, l: Left, Down, Up, Right.
  • gg: Go to the first line.
  • G: Go to the last line.
  • w: Jump to the next word.

Editing

  • dd: Delete (cut) a line.
  • yy: Copy (yank) a line.
  • p: Paste after circular buffer.
  • u: Undo last action.

[!TIP] How to exit if you're stuck? If you're lost, press Esc multiple times to get back to Normal Mode, then type :q! and press Enter to exit without saving.