This guide is for DevOps engineers who edit configuration, scripts, and manifests directly on remote systems. It gives you a practical VI/Vim command reference organized by real tasks, so you can move faster in terminal-only environments.
Originally published on 2009-04-06; fully revised and updated.

Quick terminal tip: exporting a man page to a text file
The original post mentions man ls | col -b > .... In practice, provide an output filename. This writes a plain-text version of the man page (without backspace formatting characters):
man ls | col -b > ls-manpage.txt
How Vim editing typically flows
Vim is modal. Most production editing follows a repeatable cycle: open, navigate, edit, search/replace, save, and quit.
- Normal mode: navigation and commands
- Insert mode: typing text
- Command-line mode: commands like
:w,:q, and substitutions - Visual mode: selecting text ranges
flowchart TD
A[Open file in Vim] --> B[Navigate in normal mode]
B --> C[Search or jump to target]
C --> D[Enter insert mode and edit]
D --> E[Run substitute or format commands]
E --> F{Need shell command}
F -- yes --> G[Run :!cmd or :sh]
G --> H[Return to Vim]
H --> I[Write file]
F -- no --> I[Write file]
I --> J[Quit editor]
Save and quit commands compared
| Task | Command | When to use |
|---|---|---|
| Quit (only if no unsaved changes) | :q | Safe exit when buffer is clean |
| Force quit without saving | :q! or ZQ | Discard local edits |
| Write and quit | :wq or ZZ | Standard save-and-exit flow |
| Write to another file and exit | :wq {file} | Save as a new path, then leave |
| Write selected range and quit | :[range]wq | Partial write workflows |
Essential Vim commands by task
Open, read, and write files
:e filename
:e!
:w
:w newfile
:1,10 w outfile
:1,10 w >> outfile
:r infile
:23r infile
gfCode language: CSS (css)
Insert and edit text
a
A
i
I
o
O
Ctrl+a
Ctrl+x
Search patterns
/word
?word
/jo[ha]n
/\<fred\>
/\d\{4}
/^\n\{3}
:bufdo /searchstr/Code language: HTML, XML (xml)
Replace and bulk edits
:%s/old/new/g
:%s/old/new/gc
:2,35s/old/new/g
:5,$s/old/new/g
:%s/^/hello/g
:%s/$/Harry/g
:%s/ *$//g
:g/string/d
:v/string/d
:%s/\r//gCode language: JavaScript (javascript)
Buffers, splits, tabs, and explorer
:ls
:b 2
:e .
:Sex
:split filename
:vsplit filename
:hide
:only
:tabnew
gt
:tabfirst
:tablast
:tabm 2
:tabdo %s/foo/bar/g
:tab ball
:args
:args *.php
:grep expression *.php
Run Unix commands from inside Vim
:!pwd
:!ls
!!pwd
:r !date
:sh
exitCode language: CSS (css)
Useful options and syntax settings
:set all
:set
:set ai
:set noai
:set nu
:set nonu
:set list
:set nolist
:set showmode
:set noshowmode
:set ts=4
:set ic
:set noic
:set smartcase
:set autoindent
:set smartindent
:set shiftwidth=4
:syntax on
:syntax off
:set syntax=perlCode language: JavaScript (javascript)
Best practices and common pitfalls
- Use
:set nuand:set listwhen editing YAML, Makefiles, or whitespace-sensitive files. - Prefer
:%s/.../.../gcover blind global replacement for production config changes. - Remember that some commands are Vim-specific (tabs, netrw explorer) and may not exist in minimal vi.
- When you run shell commands via
:!or:sh, verify your working directory and environment before writing changes. - If you suspect external file changes, reload with
:e!before continuing edits.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals