How do I run a window-local setting command in every open window?
:windo setlocal colorcolumn=+1
When a setting is window-local, changing it once does not affect your other splits.
:windo setlocal colorcolumn=+1
When a setting is window-local, changing it once does not affect your other splits.
/\%>80v\S
When you enforce line-length limits, visual guides show where the boundary is, but they do not help you jump directly to violations.
gv=gv
When you are iterating on indentation, repeating selection steps is wasted motion.
visual-mode #visual-mode #indentation #editing #formatting #workflow
:s/\v(\S+)\s*=\s*(.*)/\=printf('%-20s = %s', submatch(1), submatch(2))/
When a line contains uneven key = value spacing, quick manual fixes are easy to get wrong.
:argdo %s/\s\+$//e | update
When you need to clean up many files at once, :argdo lets you run the same command on every buffer in your argument list.
:%s/\d\+/\=printf('%04d', submatch(0))/g
When you need fixed-width numeric fields, manually editing each number is slow and error-prone.
:'<,'>s/^/\=line('.')-line("'<")+1 . '. '/
When you need quick numbered steps, logs, or checklist entries, this pattern adds numbers only to the lines you selected, not the whole buffer.
gUip
gUip is a compact operator-plus-text-object pattern that uppercases exactly the paragraph your cursor is in.
:keepjumps normal! gg=G<CR>
Whole-buffer reindent is common, but doing it naively can pollute your jumplist and break navigation flow during review.
:set listchars=
The listchars option controls exactly which invisible characters Vim highlights when list mode is active.
:set noexpandtab | retab!
When you inherit space-indented code and need to switch to tabs, :retab! (with the bang) converts groups of spaces into tabs throughout the file.
:set breakindentopt=shift:2
When breakindent is enabled, wrapped continuation lines are indented to match the start of their logical line.
# vim: set ts=4 sw=4 et:
Vim's modeline feature lets you embed editor settings directly into a file.
:g/^./,/^$/join
The :g/^.
command-line #command-line #editing #global #formatting #paragraphs
gwap
The gw operator reformats text to fit within 'textwidth' — identical in effect to gq, but with one key difference: the cursor returns to its original position
:w ++ff=unix
The ++ff modifier on :w forces the file format used for writing, independently of the buffer's 'fileformat' option.
command-line #ex-commands #formatting #command-line #editing
:%!python -m json.tool
When editing JSON files in Vim, you can pipe the entire buffer through Python's built-in json.
:%s/\v(\w+)/\u\L\1/g
Vim's substitution engine supports case-modifier sequences in the replacement string, making it possible to convert text to title case in a single command.
search #search #substitution #regex #editing #case #formatting
:%retab!
The :retab command converts leading whitespace according to the current tabstop and expandtab settings, but it only touches indentation at the start of lines.
:set colorcolumn=80,120
colorcolumn highlights one or more screen columns to serve as a visual ruler.