How do I create custom text objects for my own operator-pending motions?
onoremap ih :<C-u>execute "normal! ?^==\+$\r:noh\rkvg_"<CR>
Vim lets you define custom text objects using operator-pending mode mappings (onoremap) and visual mode mappings (vnoremap).
category:
config
tags:
#config
#text-objects
#mappings
#vimrc
#advanced
How do I change text from the cursor to the end of the line?
The C command deletes everything from the cursor position to the end of the line and places you in insert mode.
category:
editing
tags:
#editing
#normal-mode
#insert-mode
How do I enter a mode where I select text and then typing immediately replaces the selection, like in most graphical editors?
Vim's Select mode behaves like the familiar selection model in most GUI editors: after selecting text, any printable character you type replaces the selection a
category:
visual-mode
tags:
#visual-mode
#select-mode
#editing
#normal-mode
How do I make Vim preserve the cursor column when jumping between lines?
By default, many Vim movement commands — gg, G, Ctrl-d, Ctrl-u, Ctrl-f, Ctrl-b, and others — snap the cursor to the first non-blank character of the destina
category:
config
tags:
#navigation
#config
#motions
#normal-mode
How do I jump to the next section or function definition in Vim?
The ]] motion jumps forward to the next line that starts with { in the first column, which is typically the beginning of a C-style function or section.
category:
navigation
tags:
#navigation
#motions
#normal-mode
How do I incrementally expand or shrink a selection based on syntax tree nodes using nvim-treesitter?
nvim-treesitter's incremental selection module lets you grow and shrink your visual selection one syntax node at a time.
category:
plugins
tags:
#visual-mode
#plugins
#text-objects
#editing
How do I invert the case of an entire paragraph with one operator command?
g~ap is a fast way to invert letter case across a full paragraph without entering Visual mode.
category:
editing
tags:
#editing
#operators
#text-objects
#case
#normal-mode
How do the numbered delete registers work and why does deleted text rotate through registers 1 through 9?
Vim maintains a rotating history of deleted text across registers "1 through "9.
category:
registers
tags:
#registers
#editing
#normal-mode
How do I execute a single normal mode command without leaving insert mode?
Pressing in insert mode lets you execute one normal mode command and then automatically returns you to insert mode.
category:
editing
tags:
#editing
#insert-mode
#normal-mode
#productivity
How do I jump to any location on screen using a two-character search in Vim?
The vim-sneak plugin by Justin Keyes provides a motion that lets you jump to any visible location by typing just two characters.
category:
plugins
tags:
#plugins
#sneak
#navigation
#motions
#search
How do I visually select from the cursor to the matching bracket or parenthesis?
How it works The % motion jumps to the matching bracket, parenthesis, or brace.
category:
visual-mode
tags:
#visual-mode
#navigation
#motions
#editing
How do I interactively browse and set all Vim options in a single window?
:options opens a special Vim buffer that lists every available option, grouped by category (appearance, editing, search, etc.
category:
config
tags:
#config
#ex-commands
How do I jump to the start of the previous method or function in code?
The [m motion jumps backward to the start of the nearest enclosing or preceding method definition.
category:
navigation
tags:
#navigation
#motions
#code
#normal-mode
How do I visually select an entire code block to the matching closing brace?
Pressing V]} in normal mode enters visual line mode and immediately extends the selection to the next unmatched closing brace }.
category:
visual-mode
tags:
#visual-mode
#navigation
#text-objects
#editing
#motions
How do I jump to the opening or closing brace of the block surrounding my cursor?
The [{ motion jumps to the previous unmatched { — the opening brace of the block enclosing your cursor.
category:
navigation
tags:
#navigation
#motions
#editing
#normal-mode
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 use a count with a text object to operate on multiple words, sentences, or paragraphs at once?
Most Vim users know you can put a count before an operator (3dw) or use a text object once (daw).
category:
editing
tags:
#text-objects
#editing
#delete
#normal-mode
#motions
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 set a bookmark that persists across different files and Vim sessions?
Vim has two tiers of marks.
category:
navigation
tags:
#marks
#navigation
#normal-mode
How do I run a single normal mode command without fully leaving insert mode?
Pressing while in insert mode lets you execute exactly one normal mode command and then automatically returns you to insert mode.
category:
editing
tags:
#insert-mode
#editing
#normal-mode