How do I trim trailing whitespace in a file without polluting jumplist or search history?
:keepjumps keeppatterns %s/\s\+$//e<CR>
Bulk whitespace cleanup is common, but a plain substitution can leave side effects: your last search pattern changes and jump navigation gets noisy.
category:
editing
tags:
#editing
#command-line
#search
#formatting
How do I run a normal-mode append on only matching lines inside a visual selection?
:'<,'>g/let /normal! A;<CR>
When you need a structural edit in part of a file, Visual mode ranges combine well with :global and :normal!.
category:
visual-mode
tags:
#visual-mode
#command-line
#ex-commands
#editing
How do I delete through the end of the next search match from the cursor?
When you need to remove text up to a known marker, a plain search motion is often almost right but stops at the start of the match.
category:
navigation
tags:
#navigation
#search
#motions
#editing
How do I tune Vim diff so moved code blocks align more accurately?
:set diffopt+=internal,algorithm:histogram,indent-heuristic
Default diff settings are fine for small edits, but they can produce noisy hunks when code is moved or indentation shifts.
category:
config
tags:
#config
#buffers
#windows
#editing
How do I reselect the previous visual area and convert it to linewise selection?
gv is well known for reselecting the previous visual area, but pairing it with V is a practical upgrade when your next action needs linewise semantics.
category:
visual-mode
tags:
#visual-mode
#navigation
#editing
How do I replace the next word with a yanked word without clobbering the unnamed register?
When you are doing repetitive refactors, cw is fast but it overwrites the unnamed register with the replaced text.
category:
registers
tags:
#registers
#editing
#normal-mode
#insert-mode
How do I append a semicolon to every non-blank line with one Vim command?
:g/[^[:space:]]/normal! A;\<CR>
When you need to patch many lines at once, :g with :normal! is often faster and safer than recording a macro.
category:
command-line
tags:
#command-line
#ex-commands
#editing
#normal-mode
How do I allow block selections past end-of-line while still permitting one-char past EOL cursor movement?
:set virtualedit=block,onemore
virtualedit controls whether the cursor can move to positions that do not yet contain text.
category:
config
tags:
#config
#visual-mode
#blockwise
#editing
#cursor
How do I copy a register to another register while preserving its character/line/block type?
:call setreg('q', getreg('a'), getregtype('a'))
Simple register copies can silently change behavior when register type is lost.
category:
registers
tags:
#registers
#macros
#command-line
#editing
How do I run a full-buffer substitution without disturbing marks, jumplist, or search history?
:lockmarks keepjumps keeppatterns %s/foo/bar/ge
Large substitutions are efficient, but they often leave side effects: your last search changes, your jumplist gets noisy, and marks can shift in ways that break
category:
command-line
tags:
#command-line
#editing
#substitution
#navigation
How do I run a quickfix-wide replace without changing jumps or search history?
:cdo keepjumps keeppatterns %s/\<OldSymbol\>/NewSymbol/ge | update
When you run :cdo over a large quickfix list, Vim can leave your jump list noisy and your last search pattern overwritten.
category:
command-line
tags:
#quickfix
#ex-commands
#search
#editing
#refactoring
How do I replace matches one-by-one using cgn and dot-repeat?
Global substitution is fast, but sometimes you need selective control over each occurrence.
category:
search
tags:
#search
#editing
#normal-mode
#repeat
How do I prepend // to every line using one Vim command?
When you need to comment a whole block quickly, :global combined with :normal is faster than recording a macro or entering Visual Block mode.
category:
editing
tags:
#editing
#ex-commands
#global
#normal-mode
How do I copy one register to another while preserving its exact register type?
:call setreg('b', getreg('a'), getregtype('a'))
Plain register copies like :let @b = @a move text, but they can lose important metadata about register type.
category:
registers
tags:
#registers
#advanced
#vimscript
#editing
How do I convert all hexadecimal numbers to decimal in Vim?
:%s/0x\x\+/\=str2nr(submatch(0), 16)/g
When cleaning logs, protocol dumps, or generated code, you may need to normalize 0x.
category:
editing
tags:
#editing
#ex-commands
#formatting
#search
How do I append the same suffix to every selected line in Visual mode?
Visual selections are not just for direct operators; they also define an Ex range.
category:
visual-mode
tags:
#visual-mode
#normal-mode
#editing
#ex-commands
#automation
How do I execute a command without changing '[ and '] marks in Vim?
Many batch edits in Vim update special marks like '[ and '], which can disrupt follow-up motions or tooling that depends on those positions.
category:
navigation
tags:
#navigation
#marks
#command-line
#refactoring
#editing
How do I store the current file path in a named Vim register?
Named registers are not only for yanked text.
category:
registers
tags:
#registers
#command-line
#filename-modifiers
#editing
How do I repeat the last f/t/F/T motion in the opposite direction?
After using f, t, F, or T for single-character motion on a line, Vim lets you repeat that character search without retyping the target.
category:
navigation
tags:
#navigation
#motions
#normal-mode
#editing
How do I ROT13 only the word under the cursor for quick anonymization?
g? is Vim’s built-in ROT13 operator.
category:
editing
tags:
#editing
#operators
#text-objects
#normal-mode