vim/neovim for DevOps: Your Terminal Editor, Supercharged
Nearly every server you’ll ever SSH into has vi or vim. No GUI, no VS Code tunnel, no escape hatch — just you and the terminal. That’s the survival argument for learning vim. But there’s a stronger one: once it clicks, vim is genuinely the fastest way to edit text. This guide gets you from “how do I exit?” to “I can’t imagine working without this.”
vim vs neovim
vim is the classic, ships everywhere, rock-solid. neovim is a modern fork with a better plugin API (Lua instead of Vimscript), built-in LSP support, and a more active plugin ecosystem. The core editing model is identical — everything in this guide applies to both.
|
|
For daily driving, use neovim. For remote servers, be comfortable with whatever vim is installed.
The Mental Model: Modes
The single concept that unlocks vim is modal editing. Vim has separate modes for navigation and for inserting text. Most editors conflate these. vim does not.
| Mode | How to Enter | Purpose |
|---|---|---|
| Normal | Esc |
Navigation, operations, commands |
| Insert | i, a, o, I, A, O |
Typing text |
| Visual | v, V, Ctrl+v |
Selecting text |
| Command | : |
Ex commands (save, quit, search/replace) |
You start in Normal mode. You return to Normal mode with Esc. Everything else flows from there.
Surviving: The Essential Commands
i Insert before cursor
a Insert after cursor
o Open new line below and insert
O Open new line above and insert
Esc Return to Normal mode
:w Write (save)
:q Quit
:wq Write and quit
:q! Quit without saving
ZZ Write and quit (shorthand)
ZQ Quit without saving (shorthand)
Moving Around
In Normal mode, the keyboard becomes a navigation pad. Learn these and never touch the arrow keys again.
Basic Motion
h j k l Left / Down / Up / Right
w Forward one word (start)
b Backward one word (start)
e Forward to end of word
W B E Same but skip punctuation (WORD)
0 Start of line
^ First non-blank character
$ End of line
gg Top of file
G Bottom of file
5G Go to line 5
Ctrl+d Half-page down
Ctrl+u Half-page up
Ctrl+f Full-page down
Ctrl+b Full-page up
Search Navigation
/pattern Search forward
?pattern Search backward
n Next match
N Previous match
* Search for word under cursor (forward)
# Search for word under cursor (backward)
Jump to Character
f{char} Jump forward to char on current line
F{char} Jump backward to char
t{char} Jump forward to just before char
T{char} Jump backward to just after char
; Repeat last f/F/t/T
, Repeat in opposite direction
Marks and Jumps
ma Set mark 'a' at cursor
'a Jump to line of mark 'a'
`a Jump to exact position of mark 'a'
Ctrl+o Jump back (older position)
Ctrl+i Jump forward (newer position)
'' Jump to last jump position
Operators: The Grammar of vim
vim commands follow a grammar: operator + motion (or operator + text object).
Operators
d Delete
c Change (delete and enter Insert mode)
y Yank (copy)
> Indent right
< Indent left
= Auto-indent
g~ Toggle case
gu Lowercase
gU Uppercase
Text Objects
iw / aw Inner word / A word (including space)
is / as Inner sentence / A sentence
ip / ap Inner paragraph / A paragraph
i" / a" Inner quotes / A quotes (including quotes)
i' / a' Same for single quotes
i( / a( Inner parens / A parens
i{ / a{ Inner braces / A braces
i[ / a[ Inner brackets / A brackets
it / at Inner HTML tag / A tag
Examples
dw Delete word forward
db Delete word backward
diw Delete inner word (cursor anywhere in word)
daw Delete a word (including trailing space)
di" Delete contents of double-quoted string
da" Delete quoted string including quotes
d$ Delete to end of line
d0 Delete to start of line
dd Delete entire line
5dd Delete 5 lines
ciw Change inner word
ci" Change inside quotes
ci( Change inside parens
c$ Change to end of line
cc Change entire line
yiw Yank inner word
yy Yank entire line
5yy Yank 5 lines
>ip Indent paragraph
=G Auto-indent from here to end of file
Counts
Prefix any command with a number to repeat it:
5j Move down 5 lines
3dw Delete 3 words
10dd Delete 10 lines
2>j Indent 2 lines
Registers and Clipboard
vim has named registers for storing yanked/deleted text.
"ayy Yank line into register 'a'
"ap Paste from register 'a'
"byiw Yank word into register 'b'
"+y Yank to system clipboard (requires clipboard support)
"+p Paste from system clipboard
"*y / "*p X11 primary selection (Linux)
:reg Show all register contents
"" Unnamed register (last yank/delete)
"0 Last explicit yank
"1-"9 Delete history (most recent = "1)
"- Small delete register (less than one line)
Macros: Automating Repetitive Edits
Macros record a sequence of Normal mode commands and replay them.
qa Start recording macro into register 'a'
... Do your edits
q Stop recording
@a Replay macro 'a'
@@ Replay last macro
5@a Replay macro 'a' 5 times
Real-World Example
You have a file with lines like:
server1
server2
server3
You want:
"server1",
"server2",
"server3",
Position cursor on server1, then:
qa Start recording
I" Insert quote at start
Esc
A", Append quote-comma at end
Esc
j Move to next line
q Stop recording
2@a Apply to next 2 lines
Search and Replace
:s/old/new/ Replace first match on current line
:s/old/new/g Replace all matches on current line
:%s/old/new/g Replace all matches in file
:%s/old/new/gc Replace all, confirm each
:10,20s/old/new/g Replace in lines 10-20
# Use \1 for capture groups
:%s/\(foo\)/[\1]/g Wrap "foo" in brackets
# Case insensitive
:%s/old/new/gi
# Whole word only
:%s/\bold\b/new/g
Visual selection + :s operates on selected lines automatically:
# Select lines with V, then:
:'<,'>s/old/new/g
Working with Multiple Files
Buffers
:e filename Open file
:ls List open buffers
:b2 Switch to buffer 2
:bn / :bp Next / previous buffer
:bd Close buffer
:bufdo %s/old/new/g Operate on all open buffers
Splits
:sp filename Horizontal split
:vsp filename Vertical split
Ctrl+w h/j/k/l Navigate splits
Ctrl+w H/J/K/L Move split
Ctrl+w = Equalize split sizes
Ctrl+w +/- Resize horizontal
Ctrl+w >/< Resize vertical
Tabs
:tabnew filename Open file in new tab
gt / gT Next / previous tab
:tabclose Close tab
The netrw File Browser
vim ships with netrw, a built-in file browser. No plugin required.
|
|
Inside netrw:
Enter Open file/directory
- Go up one directory
% Create new file
d Create new directory
D Delete file/directory
R Rename
i Cycle view (thin/long/wide/tree)
gh Toggle hidden files
Configuration: ~/.vimrc / ~/.config/nvim/init.vim
A minimal but useful starting config:
|
|
Create the undo directory:
|
|
neovim with Lua: ~/.config/nvim/init.lua
neovim’s native config language is Lua, which is faster and more maintainable than Vimscript:
|
|
Plugin Management
vim-plug (vim and neovim)
|
|
In ~/.vimrc or ~/.config/nvim/init.vim:
|
|
Install: :PlugInstall
lazy.nvim (neovim only — recommended)
|
|
Essential Plugins Explained
vim-surround
Add, change, or delete surrounding characters:
cs"' Change surrounding " to '
cs({ Change surrounding ( to {
ds" Delete surrounding "
ysiw" Surround word with "
yss) Surround entire line with ()
In Visual mode: S" surrounds selection with ".
vim-commentary
gcc Toggle comment on current line
gc{motion} Toggle comment on motion
gcap Comment out paragraph
gc (Visual mode) Toggle comment on selection
vim-fugitive
Full Git integration inside vim:
|
|
fzf.vim / Telescope
Fast fuzzy finding:
|
|
Map these to leader keys:
|
|
LSP in neovim
Language Server Protocol gives you IDE features (autocomplete, go-to-definition, diagnostics) in neovim. The mason.nvim plugin manages server installation.
|
|
Install servers interactively: :Mason
DevOps-Specific Workflows
Editing Config Files on Remote Servers
|
|
Editing Multiple Config Files at Once
|
|
Diffing Files
|
|
Running Shell Commands
|
|
Editing Kubernetes YAML
With yamlls via mason:
|
|
Inline kubectl
|
|
Useful Tips and Tricks
Repeat Last Change
. repeats the last change. This is one of the most powerful features in vim.
# Add semicolons to end of lines
A;<Esc> Move cursor, then: . . .
Jump to Matching Bracket
% jumps between matching (), [], {}, and even if/endif in some filetypes.
Increment/Decrement Numbers
Ctrl+a Increment number under cursor
Ctrl+x Decrement number under cursor
5Ctrl+a Increment by 5
Sort Lines
|
|
Column Editing (Visual Block)
Ctrl+v Enter Visual Block mode
Select rows with j/k
I Insert at start of each selected line
A Append at end of each selected line
d Delete selected block
Folding
zc Close fold
zo Open fold
za Toggle fold
zR Open all folds
zM Close all folds
set foldmethod=indent " Fold by indentation
set foldmethod=syntax " Fold by syntax
Cheat Sheet
MOTION OPERATOR TEXT OBJECT
h j k l d (delete) iw (inner word)
w b e W B E c (change) aw (a word)
0 ^ $ gg G y (yank) i" a" i' a'
f{c} F{c} > < (indent) i( a( i{ a{
/{pat} n N = (format) ip ap (paragraph)
* # g~ gu gU (case) it at (tag)
Ctrl+d/u/f/b
INSERT COMMAND
i I a A o O :w :q :wq :q!
Esc :e :ls :b :bd
:s :%s
:sp :vsp
:! (shell)
:r (read)
USEFUL
. Repeat last change
u Undo
Ctrl+r Redo
% Jump to matching bracket
* Search word under cursor
" Register prefix
@ Macro replay
q Record macro
Learning Path
- Week 1 —
vimtutor(run it in the terminal, takes ~30 min, do it twice) - Week 2 — Use vim for all config file edits on servers. Resist the urge to reach for nano.
- Week 3 — Learn text objects (
ciw,di",ca() and the.repeat command - Week 4 — Set up a
.vimrcwith the settings above, add vim-surround and vim-commentary - Month 2 — Switch to neovim, add Telescope and treesitter
- Month 3 — Add LSP via mason, configure for your primary language
The goal isn’t to memorize everything at once. It’s to incrementally replace mouse actions with keyboard commands until the muscle memory takes over. Each motion you internalize compounds with every other one.
|
|
Comments