Skip to main content
XsiSec.com
HomeReposBlogProjectsPortfolio
© 2026 XsiSec.com
Security rules |security.txt
Updated 2026-08-15 · v1.0.0+2026-08-14.82f92cb · 82f92cb
← Back to overview
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

2019-04-181 tag
Tags

🎯 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/W next word · b/B back a word · 0 line start · $ line end
  • GoTo: gg file start · G file end · {n}gg or :{n} go to line {n}
  • Search: /text forward · ?text backward · n/N next/prev match · * word under cursor
  • Replace: :%s/old/new/g (all) · :%s/old/new/gc (confirm)
  • Copy/Paste: y yank · p paste after · P paste before · yy yank line · dd delete line
  • Visual: v (char) · V (line) · Ctrl+v (block) → then y/d/>/<
  • Splits: :split {file} (horizontal) · :vsplit {file} (vertical) · Move: Ctrl-w h/j/k/l
  • Undo/Redo: u / Ctrl-r
  • Write/Quit: :w save · :q quit · :wq save & quit · :q! force quit

🧭 Movement (Normal mode)

  • h left · j down · k up · l right
  • gg top of file · G bottom of file
  • {n}gg go to line n (e.g., 42gg) · :{n} works too
  • Bonus: ^ first non-blank char · 0 true line start · $ line end

🔎 Search & Find

  • Forward: /{pattern} then n (next) / N (previous)
  • Backward: ?{pattern} then n / 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: p after cursor, P before cursor
  • System clipboard (when available): "+y yank to, "+p paste from

🧰 Small but Mighty

  • Repeat last command: .
  • Join lines: J
  • Indent block: select then > (or <) — repeat with .
  • File explorer: :Ex / :E (or use netrw with :Vex for vertical)

🧪 Micro Drills (2–5 minutes)

  1. Open any long file: jump to lines 1, 50, end using gg, 50gg, G.
  2. Find all occurrences of a word (/term, n, N). Replace with :%s/term/new/gc.
  3. Split the window: :vsplit /etc/passwd, move with Ctrl-w and practice yy, p across panes.
  4. Use visual block (Ctrl-v) to insert # at the start of 5 lines.
  5. Recover from mistakes: try u, then Ctrl-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 via Ctrl-w j/k/h/l
  • Visual: v (enter); then y (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; Esc then retry.
  • Unsaved changes but want out: :q!
  • Swap file warning? Use :e! to reload or :w! to force write.

✅ Quick Reference (copy/paste)

vim
" 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

Navigate

In this post

  1. 01🎯 Objective
  2. 02⚡ TL;DR Cheatsheet
  3. 03🧭 Movement (Normal mode)
  4. 04🔎 Search & Find
  5. 05Replace (substitute)
  6. 06🪟 Windows / Splits
  7. 07✂️ Visual Mode, Yank & Paste
  8. 08🧰 Small but Mighty
  9. 09🧪 Micro Drills (2–5 minutes)
  10. 10📝 The exact notes I used
  11. 11🧯 Panic Buttons
  12. 12✅ Quick Reference (copy/paste)
Search
Explore

Popular tags

Browse all 30 tags

Comments

0 comments

No comments yet — be the first to comment.