How do I make Vim automatically reformat paragraphs as I type so lines stay within the textwidth?
:set formatoptions+=a
Vim's formatoptions setting controls how automatic text formatting works.
:set formatoptions+=a
Vim's formatoptions setting controls how automatic text formatting works.
:e %:h/
Vim expands % to the current file's path in Ex commands, and the :h modifier strips the last filename component to give you just the directory.
:%s/\w\+/\u&/g
Vim's substitute command supports case-conversion modifiers in the replacement string.
:set nofixendofline
By default, Vim enforces POSIX compliance by appending a final newline to any file that lacks one.
m<
Vim's ' marks record the start and end of the last visual selection and power the ' range used by Ex commands.
:vertical {cmd}
The :vertical command modifier forces any window-opening Ex command to create a vertical split instead of the default horizontal split.
buffers-windows #windows #buffers #command-line #splits #ex-commands
:e ++ff=unix
The ++ff modifier forces Vim to re-read the current file from disk using a specific fileformat — unix (LF), dos (CRLF), or mac (CR).
:[range]right [width]
Vim's :right command right-aligns text by padding lines with leading spaces up to a given width.
ZZ
ZZ is a normal mode shorthand that saves and quits only if the buffer has been modified.
:5t.
The :t ex command (also spelled :copy) copies a range of lines to a target address without touching any register.
:let @/ = @a
Vim's search register (@/) holds the current search pattern — the same one used by n, N, *, and hlsearch highlighting.
:g/pattern/Commentary
vim-commentary exposes Commentary as an Ex command that toggles comments on the current line, making it composable with Vim's :global command.
:doautocmd FileType
When you change a buffer's filetype mid-session — say with :set filetype=python — Vim updates the filetype option but does not automatically re-run the File
:[range]center {width}
Vim has a built-in :center command that pads lines with leading spaces to visually center them within a given column width.
command-line #formatting #text-alignment #ex-commands #editing
:[range]luado {lua-expr}
Neovim's :luado command runs a Lua expression on each line of a range, allowing you to transform text using the full power of Lua's string library.
:sort! n
The :sort! n command sorts the lines of a buffer (or a range) by their numeric value in descending order.
:put =strftime('%Y-%m-%d')
The :put = command inserts the result of a Vimscript expression directly into the buffer as a new line.
:[range]center
Vim provides three Ex commands for aligning text within a specified column width: :[range]left, :[range]center, and :[range]right.
command-line #ex-commands #formatting #editing #command-line
:normal! {cmd}
When you use :normal {cmd} in a Vimscript function, macro, or Ex command, Vim expands any keys through the user's current mappings first.
:lgrep {pattern} {files}
The location list is a per-window counterpart to the global quickfix list.
buffers-windows #buffers-windows #ex-commands #search #navigation