How do I move all lines matching a pattern to the end of the file in Vim?
The :g (global) command combined with :m (move) lets you collect all lines matching a pattern and relocate them to a specific position in the file.
category:
command-line
tags:
#ex-commands
#editing
#global
#search
#formatting
How do I insert the result of a Vim expression or calculation directly into text?
The expression register ("=) lets you evaluate any Vim expression and insert its result as text.
category:
registers
tags:
#registers
#insert-mode
#editing
#ex-commands
How do I create a mapping that applies only in visual mode but not in select mode?
:vmap applies to both visual mode and select mode, which can silently break snippet plugins (like UltiSnips, LuaSnip) that use select mode to position the curso
category:
config
tags:
#visual-mode
#normal-mode
#macros
How do I jump between merge conflict markers in a file?
During a git merge, Vim can navigate directly between conflict markers (>>>>>>) using ]n and [n.
category:
navigation
tags:
#navigation
#diff
#merge
#conflicts
How do I search only files in the argument list and inspect results in a location list?
:lvimgrep /{pattern}/j ## | lopen
When you need to run focused searches across a curated set of files, the argument list is a strong scope boundary.
category:
search
tags:
#search
#ex-commands
#location-list
#workflow
How do I jump directly to a specific line number in Vim?
When you know the exact line number you want to navigate to, the colon command is the quickest way to get there.
category:
navigation
tags:
#navigation
#motions
#ex-commands
How do I edit a recorded macro without re-recording it from scratch?
Macros are stored as plain text in named registers.
category:
macros
tags:
#macros
#registers
#editing
How do I count the number of pattern matches in a file without making substitutions?
The :s///gn command counts how many times a pattern appears in the file without actually replacing anything.
category:
command-line
tags:
#search
#ex-commands
#substitution
#command-line
How do I use gn as a text object to delete or yank the next search match?
The gn motion is a versatile text object that selects the next occurrence of the last search pattern.
category:
editing
tags:
#editing
#search
#text-objects
#normal-mode
#motions
How do I change text in a visual block selection?
In visual block mode, pressing c changes (replaces) all the text in the selected rectangle.
category:
visual-mode
tags:
#visual-mode
#editing
How do I center-align text within a specific width in Vim?
The :center command pads a line with leading spaces so the text is centered within a given width.
category:
editing
tags:
#formatting
#ex-commands
#editing
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 create a custom operator that works with motions and text objects?
:set operatorfunc=MyFunc<CR>g@
Vim lets you define custom operators that behave like built-in ones (d, c, y) — they wait for a motion or text object, then act on the selected region.
category:
config
tags:
#config
#normal-mode
#motions
#text-objects
#mapping
How do I create a dynamic abbreviation that inserts live content like the current date?
:iabbrev <expr> {trigger} {expression}
The flag on :iabbrev turns the right-hand side into a Vimscript expression that is evaluated at expansion time rather than stored as a literal string.
category:
config
tags:
#config
#insert-mode
#abbreviations
#ex-commands
How do I autocomplete words from a dictionary file while typing in insert mode?
Vim's insert-mode completion system includes dictionary lookup via .
category:
editing
tags:
#completion
#insert-mode
#editing
How do I embed Vim settings directly in a file so they apply automatically when it is opened?
# vim: set tabstop=2 shiftwidth=2 expandtab :
A modeline is a specially formatted comment that Vim reads when it opens a file and applies as local settings — no plugin or project-level vimrc required.
category:
config
tags:
#config
#modeline
#settings
#filetype
How do I run a substitution across the arglist and write only modified files?
:argdo %s/foo/bar/ge | update
Bulk replacements across many files are risky when every buffer gets written unconditionally.
category:
command-line
tags:
#command-line
#arglist
#refactor
#ex-commands
How do I replace a single character without entering insert mode?
The r{char} command replaces the character under the cursor with {char} without ever entering insert mode.
category:
editing
tags:
#editing
#normal-mode
How do I create a custom operator that works with any motion in Vim?
:set operatorfunc=MyFunc<CR>g@{motion}
Vim's operatorfunc and g@ let you define custom operators that accept any motion or text object, just like built-in operators d, c, and y.
category:
config
tags:
#config
#mapping
#normal-mode
#editing
How do I scroll up half a page in Vim?
The (Ctrl+u) command scrolls the window up by half a screen, moving the cursor along with it.
category:
navigation
tags:
#navigation
#motions
#normal-mode