Skip to content

Special commands

mg979 edited this page Aug 31, 2019 · 7 revisions

Align

Imgur

You can align regions in three different ways:

  • leader-a: current regions will be collapsed, and realigned based on the line with the highest column number

  • leader-< (Align by characters): similar, but:

    • you will be prompted for a specific character to align
    • cursors don't need to sit on that character (but shouldn't be positioned after them)
    • with [count], you can align more characters (or instances of the same character) at once
  • leader-> (Align by regex): as above, but you're prompted for a regex instead, and [count] isn't allowed


Numbering

Imgur

This command adds numbers before or after each cursor/region. It accepts an expression, that can be made of 1 to 3 terms, separated by /:

The first term is always the starting number, and if [count] is given, it will be set to this number.

The other two terms are optional, and are the step (default 1) and the separator (default none). Both the starting number and the step can be negative.

Mappings are leader-n to add before the cursor/region, leader-N to append the numbers. The separator is placed before the number when appending, after the number in the opposite case.


Text transposition

Mapping leader-t is used for text transposition, of which there are two kinds:

  • synched: it requires an equal number of selections (min 2) in each line

    Imgur

  • unsynched: it requires a minimum of two selections, their position will be cycled

    Imgur


Text shifting

Mappings for this command use meta keys, you can change them by setting:

let g:VM_maps = {}
let g:VM_maps["Move Right"] = '<M-S-Right>'
let g:VM_maps["Move Left"]  = '<M-S-Left>'

Imgur


Case conversion

Imgur

Mapping leader-C calls a menu for case conversion. If called when in cursor mode, it will be run on inner words, and some methods won't work (eg. space -> snake). It uses functions from vim-abolish (it's not necessary to have it installed, though).


Replace pattern in regions

Mapping is R, and it works in extend mode. You'll be asked for a pattern to replace, and its replacement, then the substitution will take place in all selected regions, leaving unselected text untouched.

Note that you can also run an ex command at cursors with an :s command, but that would work on the whole lines where the cursors are placed, not only on the selected regions.


Remove pattern from regions

Mapping is leader-s, and it works in extend mode. You'll be asked for a pattern to remove from each region. You can also split regions with a regex pattern in this way.


Transform regions with expression

Mapping is leader-e, and it works in extend mode.

You can enter a vim expression, that will be run on each region. Regions text will be replaced with the result of the expression. You can use some placeholders:

%t region's text
%i region's index
%n number of regions

Final regions' text will be read as

let r.txt = { your expression }

For example:

%t * 3 will multiply all regions' text by 3
%t." ".%i." / ".%n will append index / total to the region's text
%i%2 ? %t : toupper(%t) will make uppercase all odd regions (1,3,5...)
%i%3-2 ? %t : '' will delete every third region

Filter regions

Mapping is leader-f.

By pressing C-x, you can cycle filtering by:

  • pattern: only accept regions that match the pattern
  • !pattern: remove regions that match the pattern
  • expression: expression matching is the same as described in the section above

Filter lines with regions to a new buffer

It can be accessed from the Tools Menu (leader-`). This command will open a new buffer and paste all lines that contain regions.


Remove every n regions

Mapping is leader-R, for both cursor/extend modes. It lets you remove every n regions from the currently selected ones. It works with count, and a minimum of 2. That is, without count it will remove every other region, with count 3 it will remove every third region, etc.

Imgur


Tools menu

Mapping is leader-`. Options:

key direct key
" leader-" VM registers
p paste regions contents in a new buffer
f filter regions by pattern or expression
l filter lines with regions in a new buffer
L filter lines with regions in a new buffer (and strip indentation)
i regions info (text, positions, ...)

Case conversion menu

Mapping is leader-C. It works better in extend mode.