Skip to content

4. Motions and Modes

mg979 edited this page Apr 27, 2019 · 3 revisions

Once you have some regions, and mappings are enabled (M+ in the infoline), you can use motions to move cursors/extend selections.

Supported motions are all 'movement' motions (w,e,W,b...), 'find' motions (f,F,t,T) and some symbols (0,^,$,%,|).

Note about |: in vim this can be used with [count] to move to the chosen column. In VM, it will move all cursors, but without [count] it will reposition all cursors to the current column.

Insert mode can be entered from both modes and supports: i, I, a, A, c, C. Only c behaves differently in cursor/extend mode.

Note about o, O: they are started respectively with leader-o and leader-O, since o is used by extend mode to invert regions facing (as o in visual mode).


Cursor mode

Imgur

Motions in cursor mode will move the cursors. All cursors are automatically merged after each motion, so it can't happen that there are more cursors than you can see.

The following commands work in cursor mode as they would in normal mode:

~, r, x, X, D, C, Y, d, c, y, p, P, cc, yy, dd

Commands like d, c, y will expect a motion to be completed. You can use p/P to paste after/before cursors. Command Y acts as y$, rather than yy.

Imgur

You can use commands from vim-surround at cursors (cs, cS, ds, ys, yS).


Extend mode

Imgur

Motions in extend mode will extend the selections. Selections aren't automatically merged after each motion, so it can happen that there will be overlapping regions. You can force region merging pressing <leader>m.

Work in extend mode as they would in visual mode:

~, r, c, y, d, p

As in visual mode, you can press o to invert the facing of the selected regions. This will allow you to:

  • extend/reduce the regions from the opposite side
  • invert the anchor of the selections

Additionally, M-Left/M-Right will let you resize the current region only (by one character), as if the 'Only' option were activated.


If starting insert mode from extend mode, pressing i will start inserting before each region, a starts appending to each region.

c will work as in visual mode, deleting the regions first, then starting insert mode.

x and X commands shouldn't be used from extend mode, unless the width is 1. Selections are collapsed to cursors before executing the commands. Use 'd' instead.

You can use A, I, C, D, Y, but again, selections will be collapsed before executing the commands.

Imgur

You can use S command from vim-surround.


Multiline mode

Multiline mode is toggled with key M.

By default, VM starts with this mode disabled, unless a motion with the select operator that results in a multiline selection.

Imgur

When this mode is disabled, motions cannot cross line boundaries. I think this is the desired behaviour in most cases. You cannot select the endline mark either. You must be in multiline mode to do that.

When switching from multiline mode, all regions that span over multiple lines will be split, as shown below.

Imgur


Block mode

Block mode is a special mode that can be toggled with backspace. Current implementation can probably be improved. Block mode and Multiline are mutually exclusive, and it only works in extend mode (currently).

Moving the cursor in any way that isn't an allowed action for block mode, terminates the block mode itself. Allowed actions are: forward/backwards motions, adding cursors up/down.

Its purpose is to make it easier to create block-like selections, similarly to Visual-Block mode, but retaining the possibility to have regions with different widths.

The main differences with the regular mode are:

  • while adding cursors below or above, instead of adding a region with width=1, the width of the previous region will be mantained
  • with backwards motions, you cannot go behind the anchor (the starting point of the selection)
  • if moving forward and then backwards, the regions will try to keep a block-like shape: shorter regions will 'wait' for longer regions to be of the same size

These pictures can help you understand.

Not in block mode:

Imgur

In block mode:

Imgur

Clone this wiki locally