Security article
another lesson of VIM
another lesson of VIM: Capture compact, ready-to-use Vim notes for shells where no fancy editor is available. Focus on movement, search/replace, splits, and visual/yank/paste so you can edit files quickly during engagements. • Knowledge • vim
🎯 Objective
Capture compact, ready-to-use Vim notes for shells where no fancy editor is available. Focus on movement, search/replace, splits, and visual/yank/paste so you can edit files quickly during engagements.
⚡ TL;DR Cheatsheet
- Modes:
Esc= Normal ·i= Insert ·v= Visual ·:= Command-line - Move:
h j k l·w/Wnext word ·b/Bback a word ·0line start ·$line end - GoTo:
ggfile start ·Gfile end ·{n}ggor:{n}go to line{n} - Search:
/textforward ·?textbackward ·n/Nnext/prev match ·*word under cursor - Replace:
:%s/old/new/g(all) ·:%s/old/new/gc(confirm) - Copy/Paste:
yyank ·ppaste after ·Ppaste before ·yyyank line ·dddelete line - Visual:
v(char) ·V(line) ·Ctrl+v(block) → theny/d/>/< - Splits:
:split {file}(horizontal) ·:vsplit {file}(vertical) · Move:Ctrl-w h/j/k/l - Undo/Redo:
u/Ctrl-r - Write/Quit:
:wsave ·:qquit ·:wqsave & quit ·:q!force quit
🧭 Movement (Normal mode)
hleft ·jdown ·kup ·lrightggtop of file ·Gbottom of file{n}gggo to line n (e.g.,42gg) ·:{n}works too- Bonus:
^first non-blank char ·0true line start ·$line end
🔎 Search & Find
- Forward:
/{pattern}thenn(next) /N(previous) - Backward:
?{pattern}thenn/N - Word under cursor:
*(forward) /#(backward)
Replace (substitute)
- All file, no prompt:
:%s/findText/replaceText/g - All file, confirm each:
:%s/findText/replaceText/gc - Current line only:
:s/find/replace/g
Tip: Use very magic to reduce escaping:
:%s/(foo|bar)/baz/g
🪟 Windows / Splits
- Horizontal split:
:split {filename} - Vertical split:
:vsplit {filename} - Move between splits:
Ctrl-w h/j/k/l - Resize:
Ctrl-w =(equalize) ·:res +5/:vertical res +10
✂️ Visual Mode, Yank & Paste
- Enter visual:
v(chars),V(lines),Ctrl-v(block) - Then action:
y(yank),d(delete/cut),>indent,<outdent - Paste:
pafter cursor,Pbefore cursor - System clipboard (when available):
"+yyank to,"+ppaste from
🧰 Small but Mighty
- Repeat last command:
. - Join lines:
J - Indent block: select then
>(or<) — repeat with. - File explorer:
:Ex/:E(or usenetrwwith:Vexfor vertical)
🧪 Micro Drills (2–5 minutes)
- Open any long file: jump to lines
1,50,endusinggg,50gg,G. - Find all occurrences of a word (
/term,n,N). Replace with:%s/term/new/gc. - Split the window:
:vsplit /etc/passwd, move withCtrl-wand practiceyy,pacross panes. - Use visual block (
Ctrl-v) to insert#at the start of 5 lines. - Recover from mistakes: try
u, thenCtrl-r.
📝 The exact notes I used
From a recent session where I only had Vim on the target host:
- Move:
j(down),k(up),h(left),l(right) - GoTo:
gg(top),G(bottom),{number}gg(specific line) - Search:
/searchTerm(forward),?searchTerm(backward),n(next),*(word under cursor) - Replace:
:%s/findText/replaceText(all),:%s/findText/replaceText/c(confirm) - Splits:
:split {file},:vsplit {file}, move viaCtrl-w j/k/h/l - Visual:
v(enter); theny(yank);:put(paste after line);p(paste at cursor)
🧯 Panic Buttons
- Stuck in insert? Press
Esc(maybe twice). - Editor beeping? You’re in the wrong mode;
Escthen retry. - Unsaved changes but want out:
:q! - Swap file warning? Use
:e!to reload or:w!to force write.
✅ Quick Reference (copy/paste)
" Movement
h j k l " left/down/up/right
gg / G " file start / end
42gg " go to line 42
0 / ^ / $ " line start / first non-blank / line end
" Search
/word " forward search
?word " backward search
n / N " next / previous hit
* " search word under cursor
" Replace
:%s/old/new/g " replace all
:%s/old/new/gc " replace all with confirm
:s/old/new/g " current line
" Splits
:split file " horizontal split
:vsplit file " vertical split
Ctrl-w h/j/k/l " move between windows
" Visual + Yank/Paste
v / V / Ctrl-v " char / line / block select
y / d " yank / delete (cut)
p / P " paste after / before