How do I prevent a count prefix or visual range from corrupting an Ex command in a Vim mapping?
When writing nnoremap or vnoremap mappings that call Ex commands, Vim may silently prepend a count or a visual range (') to your command before it runs.
category:
config
tags:
#config
#ex-commands
#normal-mode
#visual-mode
How do I swap two words in Vim using visual paste without any plugins?
When you paste over a visual selection in Vim, the displaced text is moved into the unnamed register "".
category:
registers
tags:
#registers
#visual-mode
#editing
#text-objects
#normal-mode
How do you select to end of line for multiple lines in block mode?
In visual block mode, press $ to extend each line's selection to its end, even if lines have different lengths.
category:
visual-mode
tags:
#visual
#block
#end-of-line
How do I select text character by character in Vim?
The v command enters character-wise visual mode, letting you select text one character at a time.
category:
visual-mode
tags:
#visual-mode
#normal-mode
How do I create a Visual selection for the previous search match instead of the next one?
Most users know gn for selecting the next search match, but its counterpart gN is the real power move when you need to work backward through matches.
category:
visual-mode
tags:
#visual-mode
#search
#motions
#editing
#normal-mode
How do I auto-indent a block of code using visual mode?
Pressing = in visual mode auto-indents the selected lines according to Vim's built-in indentation rules.
category:
visual-mode
tags:
#editing
#visual-mode
#indentation
#formatting
#productivity
How do I run a macro on every line in a visual selection?
The :'normal @a command executes the macro stored in register a on every line within the current visual selection.
category:
macros
tags:
#macros
#visual-mode
#ex-commands
#editing
How do I append text to the end of multiple lines at once using visual block mode?
Visual block mode combined with $A lets you append text to the end of multiple lines simultaneously, even when those lines have different lengths.
category:
visual-mode
tags:
#editing
#visual-mode
#block-mode
#productivity
#insert-mode
How do I reformat a paragraph or visual selection to fit a specific line width?
The gq operator reformats text to fit within your configured textwidth.
category:
visual-mode
tags:
#visual-mode
#formatting
#editing
#text-objects
How do I apply ROT13 encoding to the current line in Vim without using a motion or visual selection?
Vim has a built-in ROT13 operator g? that encodes text by rotating each letter 13 positions in the alphabet.
category:
editing
tags:
#editing
#normal-mode
#encoding
How do I write a visual selection to a separate file in Vim?
How it works Vim's :w command can take a range, and when used with a visual selection, it writes only the selected lines to a file.
category:
visual-mode
tags:
#visual-mode
#ex-commands
#buffers
#editing
How do I expand or shrink a visual selection based on the syntax tree using Treesitter?
Neovim's nvim-treesitter plugin provides incremental selection based on the abstract syntax tree (AST) of your code.
category:
plugins
tags:
#visual-mode
#plugins
#editing
#navigation
How do I uppercase just the current paragraph without visual selection?
gUip is a compact operator-plus-text-object pattern that uppercases exactly the paragraph your cursor is in.
category:
editing
tags:
#editing
#text-objects
#normal-mode
#formatting
How do I move the current line or a visual selection up or down without cutting and pasting?
The [e and ]e mappings from Tim Pope's vim-unimpaired plugin exchange the current line (or a visual selection of lines) with the line above or below.
category:
plugins
tags:
#plugins
#editing
#motions
How do I swap a word with the contents of a register using visual mode?
The viwp command visually selects the word under the cursor and replaces it with the contents of the unnamed register (your last yank or delete).
category:
visual-mode
tags:
#editing
#visual-mode
#registers
#paste
#productivity
How do I run a search and replace only within a visually selected region?
:'<,'>s/pattern/replacement/g
When you make a visual selection and then type :, Vim automatically inserts ' as the range — the marks for the start and end of the last visual selection.
category:
visual-mode
tags:
#visual-mode
#search
#editing
How do I replace exactly N consecutive characters with the same character without entering visual mode?
The {count}r{char} command replaces a precise number of characters starting at the cursor position with a single repeated character.
category:
editing
tags:
#editing
#normal-mode
#replace
#motions
How do I save just the visually selected lines to a new file?
After making a visual selection, you can write only those lines to a new file using :'w {filename}.
category:
visual-mode
tags:
#visual-mode
#editing
#ex-commands
How do I search for visually selected text?
To search for the exact text you have selected in visual mode, yank it and paste it into the search prompt.
category:
search
tags:
#search
#visual-mode
#registers
How do I get the current Vim mode as a string for use in expression mappings or the statusline?
The mode() function returns a short string identifying the current editing mode — 'n' for Normal, 'i' for Insert, 'v' for Visual character-wise, 'V' for Visua
category:
macros
tags:
#macros
#normal-mode
#visual-mode
#insert-mode
#editing