How do I create a custom operator that works with motions and text objects?
:set operatorfunc=MyFunc<CR>g@
Vim lets you define custom operators that behave like built-in ones (d, c, y) — they wait for a motion or text object, then act on the selected region.
category:
config
tags:
#config
#normal-mode
#motions
#text-objects
#mapping
How do I create a custom operator that works with any motion in Vim?
:set operatorfunc=MyFunc<CR>g@{motion}
Vim's operatorfunc and g@ let you define custom operators that accept any motion or text object, just like built-in operators d, c, and y.
category:
config
tags:
#config
#mapping
#normal-mode
#editing
How do I indent lines multiple times without reselecting in visual mode?
Normally, pressing > in visual mode indents the selection but exits visual mode, requiring you to press gv to reselect.
category:
visual-mode
tags:
#visual-mode
#indentation
#mapping
#editing
How do I use the expression register in a mapping to insert dynamic values?
:nnoremap <leader>d "=strftime('%Y-%m-%d')<CR>p
The expression register (=) evaluates Vimscript expressions and uses the result as register content.
category:
registers
tags:
#registers
#expression
#mapping
#dynamic
How do I convert a recorded macro into a permanent mapping?
:nnoremap <leader>x :norm! @a<CR>
Once you've perfected a macro by recording and testing it, you can make it permanent by converting it into a mapping in your vimrc.
category:
macros
tags:
#macros
#mapping
#vimrc
#permanent
How do I find which plugin or script defined a specific mapping?
The :verbose prefix on mapping commands shows not just the mapping definition but also the file and line number where it was defined.
category:
command-line
tags:
#command-line
#verbose
#debug
#mapping
How do I add Emacs-style editing shortcuts to Vim's command line?
Vim's command line has limited navigation by default.
category:
command-line
tags:
#command-line
#mapping
#cnoremap
#editing
How do I set up efficient keybindings for cycling through buffers?
Mapping ]b and [b to :bnext and :bprev creates an intuitive bracket-style navigation for buffers, matching the convention used by unimpaired.
category:
buffers-windows
tags:
#buffers-windows
#navigation
#mapping
#buffers
How do you create a quick mapping to toggle between buffers?
nnoremap <leader>b :b#<CR>
Map b to :b# which switches to the alternate buffer.
category:
buffers-windows
tags:
#buffers
#mapping
#toggle
How do you find where a key mapping was defined?
Use :verbose map to see the mapping definition and the file/line where it was set.
category:
command-line
tags:
#command-line
#verbose
#mapping
How do you map function keys to custom commands?
nnoremap <F5> :!python %<CR>
Map function keys with their notation.
category:
config
tags:
#config
#function-key
#mapping
How do you create a custom key mapping in Vim?
nnoremap <leader>s :w<CR>
Use nnoremap for non-recursive normal mode mappings.
category:
config
tags:
#config
#mapping
#nnoremap