-
Notifications
You must be signed in to change notification settings - Fork 84
Quick start
- Adding cursors vertically
- Select word or subword under cursor
- Statusline
- Cursor mode vs Extend mode
- Find operator
- Using the mouse
- Working with visual selections
- Undo/Redo
Pay attention: in this page as in others, leader- is your
g:VM_leader
(default \\
). Also, don't trust the pics for mappings.
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.
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.
The basic mapping is C-n, it works from normal mode (selecting a whole word) or visual mode (selecting characters, without word boundaries).
You can also start selecting characters with Shift-Arrows. Note that this doesn't add a pattern yet.
Once VM is active, you can press n to get the next occurrence, N to get the previous one.
You can replace C-n with C-d, if you feel more confortable wtih it.
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
Here I use S-Right to select part of a word, then n to find next occurrences of that pattern, q to skip them, Q to remove a region.
C-n will select a word with word boundaries, unless pressed on an existing selection. 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 searched when pressing n.
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:
- leader-w: toggles whole word search
- leader-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:
Key | Action |
---|---|
n | find next (same as C-n) |
N | find previous |
] | goto next |
[ | goto previous |
q | skip and go to next |
Q | remove region |
C-f | fast forward (go to first region in next page) |
C-b | fast backward (go to first region in previous page) |
The statusline shows the number of regions/selections, and the current index. On the right corner, you see 4 letters with the following meaning:
- M+ / m- : mappings
- V+ / v- : multiline
- B+ / b- : block mode
- S+ / s- : single region mode
In between you can read the current patterns.
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).
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.
You can enable some basic mouse mappings by setting:
let g:VM_mouse_mappings = 1
Or by adding them directly:
nmap <C-LeftMouse> <Plug>(VM-Mouse-Cursor)
nmap <C-RightMouse> <Plug>(VM-Mouse-Word)
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, up to the clicked line.
Using the mouse can be useful in certain cases (eg. quick transpositions).
This page explains how to create cursors or selections from visual mode.
This feature is not yet enabled by default: with it you can undo/redo changes made in VM, and the regions will be restored as well. You have to map the commands to make it work. See Mappings.