How do I tune diffopt so diffs align moved code and produce cleaner hunks?
:set diffopt+=algorithm:patience,indent-heuristic,linematch:60
Default diff settings can produce noisy hunks when code is moved, re-indented, or lightly refactored.
2125 results for "i' a'"
:set diffopt+=algorithm:patience,indent-heuristic,linematch:60
Default diff settings can produce noisy hunks when code is moved, re-indented, or lightly refactored.
:'<,'>sort n /\d\+/
Plain :sort n is useful, but it only works when the numeric key starts at the beginning of each line.
visual-mode #visual-mode #sorting #ex-commands #text-processing
cin)
The targets.
crs / crc / crm / cru
The vim-abolish plugin adds coercion operators that instantly convert the word under the cursor between common naming conventions.
plugins #editing #text-objects #plugins #normal-mode #formatting
]# and [#
Vim provides the ]# and [# motions specifically for navigating C preprocessor conditionals.
:%d
The % range address in Ex commands stands for the entire file — it is shorthand for 1,$ (first line to last line).
]q and [q
The vim-unimpaired plugin by Tim Pope provides pairs of bracket mappings for common navigation and toggling tasks.
:set formatoptions+=j
Adding the j flag to formatoptions causes Vim to strip the comment leader from the second line when two comment lines are joined with J.
:%!python -m json.tool
When editing JSON files in Vim, you can pipe the entire buffer through Python's built-in json.
]m / [m
When you're reviewing or refactoring C-style code, jumping by words or paragraphs is too coarse, and search can become noisy.
navigation #navigation #motions #code-navigation #normal-mode
:g/BEGIN/+1,/END/-1 delete
By combining the :global command with a relative address range, you can delete the content between repeating delimiter pairs while leaving the delimiters intact
auto-pairs plugin
auto-pairs automatically inserts closing brackets, parentheses, and quotes when you type the opening one.
]s
When spell checking is enabled with :set spell, Vim underlines misspelled words in the buffer.
:%s/[“”]/"/ge<CR>:%s/[‘’]/'/ge<CR>
When text comes from docs, email, or CMS exports, it often contains typographic quotes (“”‘’) that break code snippets, Markdown tooling, or shell comma
:set shada='200,<1000,s100,h
Default ShaDa settings are conservative, which can make long-running workflows lose useful context between sessions.
vi{
The vi{ command visually selects everything inside the nearest pair of curly braces {}, without selecting the braces themselves.
visual-mode #visual-mode #text-objects #editing #normal-mode
vi[
The vi[ command selects the text inside square brackets without including the brackets themselves.
[z and ]z
The [z and ]z commands jump the cursor to the start and end of the innermost open fold containing the cursor.
:windo diffthis<CR>
If you already have several related files open in splits, enabling diff mode one window at a time is slow and error-prone.
buffers-windows #buffers-windows #diff #windows #ex-commands
/TODO/e
Most users know /pattern, but fewer use search offsets to control where the cursor lands after the match.