How can I print only arglist files that still contain trailing whitespace before bulk cleanup?
:argdo if search('\s\+$', 'nw') | echo expand('%') | endif
Before running destructive cleanup across many files, it helps to know which files will actually change.
category:
command-line
tags:
#command-line
#search
#whitespace
#arglist
#refactoring
How do I select a word under the cursor in visual mode?
How it works The command viw selects the word under the cursor in visual mode.
category:
visual-mode
tags:
#visual-mode
#text-objects
#editing
#navigation
How do I jump to the middle of a line in Vim?
The gM command moves the cursor to the horizontal middle of the current line, regardless of how long the line is.
category:
navigation
tags:
#navigation
#motions
#normal-mode
How do I define custom fold boundaries using a Vimscript expression in Vim?
Setting foldmethod=expr tells Vim to call the foldexpr expression for every line to compute its fold level.
category:
config
tags:
#folding
#config
#normal-mode
How do I reopen the current file with a different character encoding in Vim?
When Vim opens a file with the wrong encoding — producing garbled text or incorrect characters — you can reload it with a specific encoding using :e ++enc={
category:
editing
tags:
#editing
#encoding
#command-line
#file-handling
How do I diff two files that are already open in Vim splits?
You often have two files open side by side and want to compare them without leaving Vim or launching vimdiff.
category:
navigation
tags:
#buffers
#windows
#editing
#navigation
How do I create a macro by typing it out instead of recording it interactively?
Recording macros with q works well for simple sequences, but complex macros with special keys can be hard to get right in one take.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I search for a pattern in the current file and navigate results with the quickfix list?
When you need to find all occurrences of a pattern in the current file and jump between them systematically, :vimgrep with % is more powerful than basic / searc
category:
search
tags:
#search
#quickfix
#ex-commands
#navigation
How do I run a command without moving the cursor or changing the scroll position?
:let view=winsaveview() | {cmd} | call winrestview(view)
When writing Vimscript functions or mappings, commands like :substitute, gg, or :%normal will move the cursor and change the scroll position.
category:
command-line
tags:
#ex-commands
#editing
#vimscript
#navigation
How do I prevent accidental edits to a buffer by making it completely read-only?
:set nomodifiable locks a buffer so that no changes can be made at all — not even temporary ones.
category:
buffers-windows
tags:
#buffers
#editing
#normal-mode
#ex-commands
How do I open a file in Vim without triggering any autocmds for faster loading?
When you have heavy autocmds registered for BufRead, BufEnter, or FileType events — such as LSP clients, formatters, or syntax processors — opening a large
category:
command-line
tags:
#command-line
#ex-commands
#buffers-windows
#config
How do I make @ characters count as part of filenames for gf and path motions?
gf is fast until it stops exactly at characters common in modern import paths, especially @ in scoped package names (@org/pkg/file).
category:
navigation
tags:
#navigation
#gf
#config
#paths
How do I open a specific buffer in a new split without navigating away from my current buffer?
:sbuffer {N} opens buffer number N in a new horizontal split, leaving your current window untouched.
category:
buffers-windows
tags:
#buffers-windows
#buffers
#windows
#navigation
How do I search for text that simultaneously matches two different patterns using Vim's AND operator?
Vim's \& operator lets you intersect two patterns so the match must satisfy both simultaneously.
category:
search
tags:
#search
#regex
#normal-mode
How do I programmatically extend or modify a recorded macro without re-recording it?
:let @a = @a . "\<CR>extra"
Vim stores macros as plain text in registers — the same registers used for yanked text.
category:
macros
tags:
#macros
#registers
#vimscript
How do I extract regex capture groups from a string in Vimscript?
matchlist({str}, {pattern}) runs a regex match and returns a list of all captured groups, making it the idiomatic way to extract structured data from strings in
category:
macros
tags:
#vimscript
#macros
#ex-commands
#search
How do I anchor a search or substitution pattern to the current cursor position?
The \%# atom in Vim's regex engine matches the exact position of the cursor — zero-width, between characters.
category:
search
tags:
#search
#normal-mode
#ex-commands
#editing
How do I quickly insert the current file's directory into a command-line prompt without typing the full path?
:cnoremap %% <C-r>=expand('%:h').'/'<CR>
By mapping %% in command-line mode, you can type %% wherever you would normally type a path and have Vim automatically expand it to the directory of the current
category:
config
tags:
#command-line
#ex-commands
#navigation
#config
How do I register custom filetype detection rules in Neovim using Lua without editing filetype.vim?
vim.
category:
config
tags:
#filetype
#neovim
#lua
#config
How do I run a recorded macro across multiple files at once?
Combining :argdo with :norm @a lets you apply a recorded macro to every file in Vim's argument list — a powerful pattern for bulk refactoring across a project
category:
macros
tags:
#macros
#ex-commands
#editing
#buffers