Skip to content

YouDontKnowVimModePlus

t9md edited this page Nov 24, 2016 · 7 revisions

This document quickly introduces notable vim-mode-plus's features which tend to be unnoticed.

Pure Vim moves the cursor as a side effect of operator, vim-mode-plus doesn't.

In pure Vim, each time an operator finished, cursor is moved to start of target. I wanted to change this behavior, I wanted the cursor position to remain unchanged after the operator finished.

In pure-Vim

  • After you yank, cursor position is set at start position of target.
  • So y i p moves cursor to start position of paragraph. y in visual-mode moves cursor to start position of visual area.
  • After you d d, your cursor position is set at start of non-empty-char of next line of deleted line.
  • Like this way, basically when you execute some operator, cursor position automatically moved.

In vim-mode-plus user can disable this unwanted-side-effect(at least for me) by enabling following configuration.

  • stayOnTransformString: Affects all string transformation operator such as surround, g U
  • stayOnYank: Cursor remains at same position after y.
  • stayOnDelete: Cursor remains at same position after d.

The one good effects of moving cursor to start of target area after operation finished is that user can understand that operator was successfully executed.
Without moving cursor, user have less confident whether their keystroke is handled or not.

So vim-mode-plus adds flashOnOperate configuration, which is enabled by default.
This feature adds short-time-blinking-highlight to the target range of operator. For example, y i p flashes, inner-paragraph in short duration. So user can understand what area is yanked visually without depending on movement happened as an side effect of operator.

Maximize current pane

  • vim-mode-plus:maximize-pane: cmd-enter in macOS. Other OS have no default keymap.

IncrementalSearch

  • Enable it from setting-view. The / and ? become incremental-search.
  • tab, shift-tab allow you visit matching keyword without confirming.
  • ctrl-r ctrl-w to insert cursor-word to search-input.
  • Your input is treated as regular expression. By starting space( ), you can match input as-is(no regex match).
  • Following special feature relating to OccurrenceModifier is available.
    • ctrl-cmd-c: change matching pattern in-bulk.
    • cmd-d: select matching keyword at once.
    • cmd-o: add preset-occurrence for matching keyword.

Smooth Scroll for scroll motion

  • Enable it from setting-view.
  • Can enable/disable for full-scroll(ctrl-f, ctrl-b) or half-scroll(ctrl-d, ctrl-u) independently.

Per operation granular keymap scope

  • When some operation is waiting for user input, typically in operator-pending.
  • You can have specific keymap only effective in this condition(specific operator is waiting for user input).
  • If using general operator-pending scope conflicts other keymap, use this granular, narrower scope.
# yank/delete paragraph by `y p`, `d p`
'atom-text-editor.vim-mode-plus.yank-pending, atom-text-editor.vim-mode-plus.delete-pending':
  'p': 'vim-mode-plus:inner-paragraph'
  '/': 'vim-mode-plus:inner-comment'

# So that Ican toggle comment for paragraph by `g / /`
'atom-text-editor.vim-mode-plus.toggle-line-comments-pending':
  '/': 'vim-mode-plus:inner-paragraph'

making I and A is available in all visual mode

vmp bundled great vim-niceblock like feature. Not fully compatible with vim-niceblock though, I intentionally choose current vmp's behavior.

In visual-block mode(vB), I and A is already useful you know.
Why not making I and A in other visual-mode(vC, vL) also useful.
So this enhancement change behavior of g I, I, A in mode vC, vL.

g I

Insert at first column in all mode.

mode action
n first column of cursor line
vC first column of each selected lines (cursor multiplied)
vL first column of each selected lines (cursor multiplied)
vB first column of each selected lines

I

Insert at first-character-of-line(FCOL) in n and vL. Insert at start-of-selection-column in vC and vB.

mode action
n insert-at-FCOL of cursor line
vL insert-at-FCOL for each selected lines (cursor multiplied)
vC Shorthand of ctrl-v I(vB in this table) (cursor multiplied)
vB insert-at-start-of-selection-column for each selected lines

A

Insert at EOL in n and vL. Insert at end-of-selection-column in vC and vB.

mode action
n insert-at-EOL of cursor line
vL insert-at-EOL for each selected lines (cursor multiplied)
vC Shorthand of ctrl-v A(vB in this table) (cursor multiplied)
vB insert-at-end-of-selection-column for each selected lines

Motions

  • MoveUpToEdge, MoveDownToEdge: [, ] is mapped by default (aggressive decision).

Operator

  • ctrl-a, ctrl-x: To increment/decrement number.
  • g ctrl-a, g ctrl-x: In visual-mode, all number occurrence in visual-area is treated as group and re-number it by incrementing or decrementing from first number. In pure Vim first number is also incremented, but in vim-mode-plus first number is always treated as base number. You can specify a count to indicate steps of each increment. So 3 g ctrl-a increments 3 on each increment steps.

Operator TransformString

  • URLencode, CamelCase, DashCase etc etc etc.. Many common string transformation is already bundled in vim-mode-plus.

  • TransformString: is parent of many string transformation operator

  • Some don't have default keymap, and remembering all keymap is impossible?

  • TransformWordBySelectList: is for you. it allows transformation operator from select-list(No default keymap, I map ctrl-s to to it).

    1. Place cursor to camel-case.
    2. ctrl-s(in-my-case) show menu, choose string transformation operator like Camelize.
    3. i w: to target inner-word
    4. inner-word is transformed to CamelCase
  • Surround: is bundled. No default keymap.

    • ChangeSurround
    • ChangeSurroundAnyPair: Auto detect pair char. In most case, this is better than ChangeSurround which manually specify pair char.
    • DeleteSurround
    • DeleteSurroundAnyPair: Auto detect pair char. In most case, this is better than DeleteSurround which manually specify pair char.
  • ReplaceWithRegister: No default keymap. but I use very-very frequently.

    • With combination of preset-occurrence and persistent-selection. You can intuitively replace keyword with text in register.
  • Sort: No default keymap. I map it g s

  • Reverse: No default keymap. I map it g r

  • ToggleLineComments:

    • g / is default keymap.
    • g / i p to comment out paragraph.
    • You can remove comment by g / i / regardless of cursor position. The i / is comment text-object, which selects only commented rows.

TextObject

  • Function: i f(body only exclude parameters part) and a f(whole function).
  • Indentation: i i(same-or-deeper indent level) and a i(blank-row or same-or-deeper).
  • CurrentLine: i l(line text exclude trailing/reading white space), a l(whole line).
  • VisibleArea: i v(visible screen area), a v(same as i v).
  • Entire: i e(Whole buffer), a e(same as i e).
  • Fold: i z(fold body excluding fold start row), a z(include start row of fold).
  • Comment: i /(commented area), a /(same as i /).

Persistent Selection

  • In visual-mode, enter make current selection persistent-selection
  • escape to clear persistent-selection
  • By default persistent-selection is treated as part of selection.
  • So all operator apply it's mutation to persistent-selection if it exists.
  • Use autoSelectPersistentSelectionOnOperate config option to disable this.
  • Since Atom's cmd-d is not good at skipping multiple instances, making selection persistent by enter is easier.

Narrow mode in visual-mode

  • When selection was multi-lines is-narrowed is automatically set.
  • In this mode some special shortcut is available
  • cmd-d: to select cursor word intersecting selection.
  • ctrl-cmd-c: to change cursor-word intersecting selection in-bulk.
  • In is-narrowed selection state g o add preset-occurrence at cursor position, then user can continue extending visual-area.
  • When selection was not multi-line, it is NOT is-narrowed, g o add preset-occurrence for keyword which is currently selected.