Vim Mastery

Vim Mastery

Attribute Value

Goal

Expert-level Vim proficiency

Interest Link

Systems Tools > Vim/Neovim

Status

In Progress

Editor

Neovim (instrumentum-nvim config)

Philosophy

Text as data, composable commands

Documentation

Principia/02_Assets/LRN-VIM/, domus-captures codex

Skill Areas

Area Description Status

Motions

Efficient cursor movement (w, W, f, t, %, etc.)

[x] Proficient

Text Objects

iw, aw, ip, ap, i", a", custom objects

[x] Proficient

Operators

d, c, y, > with motions

[x] Proficient

Registers

Named registers, clipboard, expression register

[ ] In Progress

Macros

Recording, editing, running across files

[ ] In Progress

Substitution

:s, :g, regex patterns

[x] Proficient

Ex Commands

:norm, :g, :v, ranges, patterns

[ ] In Progress

Plugins

LSP, Telescope, mini.nvim ecosystem

[ ] In Progress

Vimscript/Lua

Custom functions and configurations

[ ] In Progress

Resources

Books:

  • Practical Vim - Drew Neil

  • Modern Vim - Drew Neil

  • Learn Vimscript the Hard Way

Practice:

  • Codex vim section

  • Daily editing consciousness

  • vimgolf.com exercises

Configuration:

  • instrumentum-nvim (personal config)

  • mini.nvim ecosystem

  • LSP integration

Quick Reference

" ESSENTIAL MOTIONS CHEATSHEET

" HORIZONTAL
0 ^ $ g_                                     " Line start/end variants
w b e                                        " Word movement
W B E                                        " WORD movement
f F t T                                      " Character find
; ,                                          " Repeat character find

" VERTICAL
j k                                          " Line up/down
{ }                                          " Paragraph
( )                                          " Sentence
H M L                                        " Screen position
gg G {n}G                                    " File position

" SEARCH
/ ?                                          " Pattern search
n N                                          " Next/prev match
* #                                          " Word search
%                                            " Matching bracket

" JUMPS
<Ctrl+O> <Ctrl+I>                            " Jump list
g; g,                                        " Change list
'' ``                                        " Previous position
'\{mark} `\{mark}                              " To mark

" SCROLL
<Ctrl+F> <Ctrl+B>                            " Page
<Ctrl+D> <Ctrl+U>                            " Half page
<Ctrl+E> <Ctrl+Y>                            " Line
zt zz zb                                     " Reposition screen

Quick Reference

" ESSENTIAL MACRO COMMANDS
qa                                           " Record to 'a'
q                                            " Stop recording
@a                                           " Play 'a'
@@                                           " Repeat last macro
5@a                                          " Play 5 times

" MACRO EDITING
"ap                                          " Paste macro (to edit)
"ay$                                         " Yank line to macro
:let @a = "..."                              " Set macro directly
qA                                           " Append to macro 'a'

" WITH :global
:g/pattern/normal @a                         " Apply to matches
:v/pattern/normal @a                         " Apply to non-matches
:'<,'>g/./normal @a                          " Apply to visual selection

" ROBUST MACRO PATTERN
0                                            " 1. Known start position
f\{char}                                      " 2. Find target
c\{motion}text<Esc>                           " 3. Make change
j                                            " 4. Position for next
@a                                           " 5. (Optional) recurse

" SPECIAL KEY SEQUENCES (:let)
\<Esc>                                       " Escape
\<CR>                                        " Enter
\<Tab>                                       " Tab
\<C-R>                                       " Ctrl+R

Infrastructure Automation Macros

" CONVERT CSV TO YAML
" Input:  hostname,10.50.1.60,vault
" Output: - name: hostname
"           ip: 10.50.1.60
"           role: vault

qa
0                                            " Start of line
i- name: <Esc>                               " Insert prefix
f,                                           " Find comma
s<CR>  ip: <Esc>                             " Replace with newline + ip:
f,                                           " Find comma
s<CR>  role: <Esc>                           " Replace with newline + role:
jo<Esc>                                      " Add blank line, move down
q

" GENERATE HOST ENTRIES
" Input:  vault-01
" Output: 10.50.1.60 vault-01 vault-01.inside.domusdigitalis.dev

qa
0                                            " Start
I10.50.1.<Esc>                               " Add IP prefix
A <Esc>                                      " Add space at end
yiw                                          " Yank hostname
$p                                           " Paste at end
a.inside.domusdigitalis.dev<Esc>            " Add domain
j                                            " Next line
q

" FIX SSH CONFIG INDENTATION
" Input:  HostName value (wrong indent)
" Output:     HostName value (4 spaces)

qa
^                                            " First non-blank
d0                                           " Delete leading space
I    <Esc>                                   " Insert 4 spaces
j                                            " Next line
q

" WRAP YAML VALUES IN QUOTES
qa
f:w                                          " Find colon, move to value
i"<Esc>                                      " Insert opening quote
$a"<Esc>                                     " Append closing quote
j                                            " Next line
q

" ADD ATTRIBUTE MARKERS
" Input:  server: 10.50.1.60
" Output: server: {vault-ip}

qa
f:w                                          " Move to value
ciw{vault-ip}<Esc>                          " Replace with attribute
j
q

Motion Gotchas

" WRONG: j/k skip wrapped lines
" Long line that wraps...
j                                            " Goes to next actual line, not visual

" CORRECT: Use gj/gk for wrapped lines
gj                                           " Move within wrapped display line
gk                                           " Same, upward

" WRONG: w/W confusion with punctuation
" hello-world.example
w                                            " hello → - → world → . → example
W                                            " hello-world.example (one move)

" CORRECT: Understand word vs WORD
" word = alphanumeric sequences
" WORD = non-blank sequences

" WRONG: f doesn't cross lines
f)                                           " Only searches current line!

" CORRECT: Use /pattern for multi-line
/)                                           " Searches entire buffer

" WRONG: Forgetting search is a motion
d/pattern                                    " Deletes up to pattern (exclusive)

" CORRECT: Use operator + search
d/pattern<CR>                                " Delete to match (exclusive)
dn                                           " Delete to next match

" WRONG: % on non-matching brackets
" (unbalanced (parens)
%                                            " Behavior is undefined

" CORRECT: Ensure balanced delimiters before using %

" WRONG: Expecting { } to work like other editors
" Vim { } = blank line, not brace

" CORRECT: Use [{, ]} for brace pairs
[{                                           " Previous unmatched {
]}                                           " Next unmatched }

" WRONG: Marks disappear
ma                                           " Local mark
:edit other_file
'a                                           " Mark 'a' not here!

" CORRECT: Use uppercase for global marks
mA                                           " Global mark
:edit other_file
'A                                           " Works across files