MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

VI/Vim Command Reference for DevOps Engineers: Modes, Search, Replace, Files, and Shell

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.

VI and Vim editor commands cheat sheet

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

TaskCommandWhen to use
Quit (only if no unsaved changes):qSafe exit when buffer is clean
Force quit without saving:q! or ZQDiscard local edits
Write and quit:wq or ZZStandard 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]wqPartial 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 nu and :set list when editing YAML, Makefiles, or whitespace-sensitive files.
  • Prefer :%s/.../.../gc over 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.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

Best & Most Popular 5 Code Editor for Ruby programming Language

In this tutorial im going to share Top 5 code editor for Ruby Programming language. It’s very helpfull for programmers. Top 5 Code editor for Ruby Programming…

Read More

Top 10 free open source Text editors for software engineers

 🔸 vi – is one of the most common text editors on Unix.  🔸 vim – is a highly configurable text editor.  🔸 emacs – is an extensible, customizable, free/libre text editor, and more.  🔸 micro – is…

Read More

How to stop warnings when opening a file that has a .swp file Linux?

Deepak Kumar MotoShare.in is your go-to platform for adventure and exploration. Rent premium bikes for epic journeys or simple scooters for your daily errands—all with the MotoShare.in…

Read More

In Laravel, how can I clear laravel.log?

In my Laravel project i want to clear my laravel.log file but i have no idea how to do it. so i found a solution on it….

Read More

Ubuntu, Linux, Unix vi error: swap file .swp already exists

Command that gave me error:vi .env or vi <any file name that starts with a “.” that means it’s a hidden file> Error: Swap file .env.swp already…

Read More

Linux Interview Questions and Answer – Part 4

What is MAC address? can we change the physical address? How to check system uptime? How to check memory information? What is SWAP? What is the exact…

Read More
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
1 month ago

Learning a few core vi and Vim commands can make editing files on remote servers much faster. Commands for searching text, saving changes, and undoing mistakes are especially useful during system maintenance. It is also worth learning how to exit safely, since beginners often get stuck between insert and command modes. Practising on a sample file helps build confidence before editing important configuration files. These basics make terminal-based work smoother and reduce avoidable errors.

Jason Mitchell
Jason Mitchell
4 months ago

In production environments, the biggest challenge with command-line editors is not learning shortcuts but preventing configuration drift. Engineers often make quick changes during incidents, and those temporary fixes can remain unnoticed and create future problems. A good practice is to capture emergency changes, review them later, and move validated updates into version-controlled configuration management. This approach keeps the speed advantage of tools like Vim while ensuring systems remain reproducible and easier to troubleshoot over time.

2
0
Would love your thoughts, please comment.x
()
x