Skip to content

Quick start

mg979 edited this page Jan 4, 2019 · 7 revisions

Adding cursors vertically

Imgur

You can use keys C-Down / C-Up to add cursors vertically, then use motions to move cursors. Pressing tab will switch to extend mode. Adding cursors vertically will skip shorter lines. Note that you can add cursors on empty lines when starting at column 1, but the highlight won't be showed in this case (it's a vim limitation as far as I know). You can use arrow keys in insert mode to move all cursors.

To make things easier, since hjkl move all cursors, you can still use arrows and ctrl-arrows to move around, without moving the cursors as well.


Imgur

Here I'm adding cursors, then use x to delete a character, k to move up all cursors, J to join lines. If you started from the beginning of the line, you would have typed f\ to reposition cursors on the backslash.


Select word or subword under cursor

The basic mapping is C-n, it works from normal mode (selecting a whole word) or visual mode (selecting a subword, without word boundaries).

To create selections as in other editors, you could enable Shift-Arrows mappings, or replace C-n with C-d.

let g:VM_maps = {}
let g:VM_maps['Find Under']         = '<C-d>'           " replace C-n
let g:VM_maps['Find Subword Under'] = '<C-d>'           " replace visual C-n
let g:VM_maps["Select l"]           = '<S-Right>'       " start selecting left
let g:VM_maps["Select h"]           = '<S-Left>'        " start selecting right

Imgur

Here I use S-Right to select part of a word, then C-n to find next occurrences of that pattern, C-s to skip them, Q to remove a region. You can also use ] and q, instead of C-n/C-s.

C-n will select a word with word boundaries, unless pressed on an existing selection as in the case shown in the picture. Also note that if you move to a different word with arrow keys and press C-n again, a new pattern will be added, and all of them will be selected.

C-n can also be used in cursor mode, and it will expand all words under all cursors (as by using the select operator by typing siw).

After you selected something, you can press:

  • C-w: toggles whole word search
  • C-c: cycle case setting (case sensitive -> ignorecase -> smartcase)

Starting case setting is your default one.

You can also use these mappings, after VM has started:

Action Equivalent
] find next C-n
[ find previous
} goto next
{ goto previous
q skip and go to next C-s
Q remove region
<C-f> fast forward
<C-b> fast backward

This page explains the difference between the two main modes in VM: cursors (as when creating cursors vertically) and selections (as when selecting words with C-n).


Imgur

Here I use C-n to select a word, then 8mj to select all occurrences in the 8 lines below. VM must be started, m is the operator. It works with motions/text objects, for example mip, selects all occurrences inside a paragraph, mas around a sentence, etc.


Using the mouse

You can enable some basic mouse mappings by setting:

let g:VM_mouse_mappings = 1

Or by adding them directly:

nmap   <C-LeftMouse>         <LeftMouse>g<Space>
nmap   <C-RightMouse>        <LeftMouse><C-n>
nmap   <M-C-RightMouse>      <Plug>(VM-Mouse-Column)

The first one will create a cursor at the clicked position. The second one will select the clicked word.
The last one will create a column of cursors, keeping the initial vertical column, until the clicked line.

Imgur

Using the mouse can be useful in certain cases (eg. quick transpositions).


This page explains how to create cursors or selections from visual mode.

Clone this wiki locally