
Vim commands I reach for when simple edits get complex
There's a point in most editing sessions where a simple substitution or a quick dd stops being enough. You're mid-refactor, your search history is getting polluted, your macro keeps running past where it should, or you just want to get back to the line you were editing five minutes ago. These are the commands I keep reaching for in those moments. 1) Matching only part of a pattern with \zs and \ze Why it matters The \zs and \ze atoms let you pinpoint which part of a match gets highlighted or replaced — without writing lookaheads or making the regex more complex. The surrounding context still needs to match, but only the portion between \zs and \ze counts as the actual match. " Match the function name only, not the 'function ' keyword before it /\ ( function \s\ + \ ) \zs\ w \ + " Substitute: rename only the value after 'color: ' : %s /color: \zsred/ blue/ g Real scenario You're grepping through a codebase for function definitions and want to rename all functions that follow the pattern
Continue reading on Dev.to
Opens in a new tab


