Skip to Content
This project is a work in progress. If you have any questions or suggestions, feel free to contact me.
LinuxText EditorsVi Editor

Introduction to vim

  • vim stands for Vi IMproved
  • It’s a highly configurable, powerful, command-line-based text editor
  • Often pre-installed on most Unix/Linux systems
  • Backward compatible with the original vi editor

Starting Vim

vim filename # Open or create a file with vim

Vim Modes

ModePurpose
NormalDefault mode for navigation and commands
InsertFor editing/inserting text
VisualFor selecting and manipulating blocks of text
CommandFor executing colon (:) commands (save, quit etc)

Mode Switching

  • Esc – Return to Normal mode from Insert/Visual
  • i – Insert before cursor
  • a – Append after cursor
  • o – Open new line below and enter Insert mode
  • v – Enter Visual mode
  • : – Enter Command mode (starts with colon)

Basic Editing

Insert Text

  • i – insert at cursor
  • I – insert at start of line
  • a – append after cursor
  • A – append at end of line
  • o – open new line below
  • O – open new line above

Delete Text

  • x – delete character under cursor
  • dd – delete current line
  • dw – delete word
  • d$ – delete from cursor to end of line
  • u – undo
  • Ctrl + r – redo

Copy/Paste (Yank/Put)

  • yy – yank (copy) current line
  • yw – yank word
  • p – paste after cursor
  • P – paste before cursor

Saving and Exiting

CommandMeaning
:wSave (write) file
:qQuit
:wq or ZZSave and quit
:q!Quit without saving
KeyAction
h, j, k, lMove left, down, up, right
0, ^, $Start, first non-whitespace, end of line
w, b, eMove by word forward/backward/end
gg, GGo to beginning/end of file
:nGo to line n

Searching

/pattern # Search forward ?pattern # Search backward n # Repeat search forward N # Repeat search backward

Summary

Vim is modal, fast, and lightweight. To get comfortable:

  • Practice switching modes
  • Learn movement commands
  • Use :wq to save and quit

To exit without saving: Esc:q!

Last updated on