Skip to content

5. Operators

mg979 edited this page Dec 9, 2018 · 5 revisions

Find Operator

Its purpose is to find all matches inside a visual selection, or a text object. It can be started in 3 ways:

  • C-f from visual mode
  • g/ from visual mode, to start a regex search inside of it
  • m + text object: from normal mode ('m' stands for 'matches')

If run from visual mode with C-f, and VM hasn't started yet, it will look for patterns matching the current search register. Otherwise it will look for the current patterns. Method 3. can only work after VM has started.

Example from visual mode, using vim-indent-object: press C-n, then vii and C-f to select all occurrences inside the indentation level.

Imgur

Example from normal mode, using vim-textobj-function: press C-n, then maf to select all occurrences inside the function.

Imgur


Select Operator

The Select Operator is activated with gs or s (after VM has started). gs creates selections from nothing, while s creates them from existing regions.

They're different because:

  • gs always creates a new region, and never touches existing regions.
  • s acts on all regions at the same time, and will remove the regions/cursors that have been used as 'jump-points'.

That is, s creates regions from cursors: from a cursor, a new region is made, but the old cursor is removed.

You can use the Select Operator in the same way you would use the v key in vim. While v starts Visual Mode and creates a visual selection, the Select Operator starts extend mode (if it's not started already) and creates selections for every region, similarly to how v would create them.

Imgur

gs s
VM not started? creates selection mapping not set
cursor mode? creates selection and turns on extend mode removes cursors and creates selections out of them
extend mode? creates selection removes selections and creates new selections out of them

The Select Operator is basically a yank motion, so it supports all custom operators from plugins you may have installed, eg:

wellle/targets
kana/vim-textobj-indent kana/vim-textobj-function


Cursor Operators

In cursor mode, several operations are allowed, with some limited plugin support. All default yank, delete and change operations are supported, with registers and count, for example "zdw, c2b, etc.

vim-surround is explicitely supported, while others are implicitely supported if they replace default vim motions/text objects.

operator special example
y s,S ysiW]
d s ds(
c s,S cs(]

kana/vim-textobj-function and kana/vim-textobj-indent are also supported, so that change operations will work correctly. An example using cii and kana/vim-textobj-indent:

Imgur

Clone this wiki locally