-
Notifications
You must be signed in to change notification settings - Fork 108
OccurrenceModifier
v0.55.0 is big feature enhancement.
So I will quickly explain part of it to encourage user to use these new feature.
Most of the new features introduced in v0.55.0 are somewhat related or based on occurrence operator-modifier.
So reading this test spec will also help to understand these features.
- Occurrence operator-modifier
- [Experimental] Keystroke sugar introduced from v0.57.0, v0.58.0
- Select/change occurrence have special support in visual-mode and in incremental-search-input
When you type o in operator-pending-mode, you can modify existing operator to behave differently.
Following keymap are available.
So you can use c o p and d o f rather than c o i p and d o a f.
| Sugar | Equivalent | Example |
|---|---|---|
o p |
o i p |
d o p delete all occurs in inner-paragraph
|
o f |
o a f |
c o f change all occurs in a-function
|
o l |
o i l |
c o l change all occurs in inner-current-line
|
o z |
o a z |
g U o z uppercases all occurs in a-fold
|
o r |
o a r |
d o r delete all occurs in a-range-marker
|
o v |
o i v |
d o v delete all occurs in a-visible-area
|
o v is added from v0.58.0
-
ois operator modifier. -
The command name of
oisoperator-modifier-occurrence. -
What's this? what operator-modifier?
-
Operator-modifier is command available in
operator-pending-modeand is used to modify existing operator's behavior to behave differently. -
Well known operator-modifier is
vandVwhich forces operator's wise(linewise,charcterwise).-
d jdelete two line, butd v jdelete same char as when you didv j d.- So you modified
dto behavecharacterwisebyvmodifier.
- So you modified
-
d ldelete right char only, butd V jdelete whole line(same range as you didd d).- So you modified
dto behavelinewisebyVmodifier.
- So you modified
-
-
So what
odoes? -
What
odoes is to instruct operator to re-select occurrence of cursor word from target range just after target selected but before applying operator to target.
g U i p uppercases all text in a paragraph, g U o i p uppercases all occurrences of cursor-word in a paragraph.


Vim's text editing operation is consists of operator and its target(motion or text-object).
Operator is command to instruct do something such as delete, change, uppercase, surround etc.
Target is command to specify to what such as here-to-end-of-line, paragraph, inner-parenthesis, inner-word etc.
- Operator:
g Uisupper-caseoperator,cischangeoperator. - Target:
i pisinner-paragraphtext-object used as operator target. - Operator modifier:
oinstruct re-select occurrence of cursor word within target.
When user type i p, paragraph is selected internally then apply g U or c to that selected text.
But when o modifier is used, before applying operator to selected paragraph, it scan occurrence of cursor word from selected range(paragraph) then re-select found words.
So, instead of directly applying operator to whole paragraph, operator is applied to those re-selected words.
Off course o modifier is available for all operators in vim-mode-plus.
But keystroke is a bit complex and might be confusing for many user.
And I believe most frequent use-case of occurrence operation is select-occurrence and change-occurrence.
So vim-mode-plus provides accessible keybindings for those commands and also have special support in visual-mode and incremental-search-input.

| Mode | Keybind | Description |
|---|---|---|
normal |
g cmd-d |
Select occur of cursor word in specific target |
visual.is-narrowed |
cmd-d |
Select occur of cursor word in selection. |
| incseach-input | cmd-d |
Select occur of search word in target |

| Mode | Keybind | Description |
|---|---|---|
normal |
c o |
Change occur of cursor word in specified target |
visual.is-narrowed |
ctrl-cmd-c |
Change occur of cursor word in selection. |
| incseach-input | ctrl-cmd-c |
Change occur of search word in target |
c o above is just a change operation with occurrence(o) modifier.
So nothing special, but put here for consistency.
When selection is multi-line(not single-line) in visual-mode, vim-mode-plus automatically sets an is-narrowed css class on editorElement(view part of text-editor).
As long as cursor word is starting from inner-selection, that word is treated as occurrence.
When ctrl-d, or ctrl-cmd-c is executed from incsearch-input, it tries to auto-set the target by following priority.
- In
visual-modeuse current selection as target. - If there is
range-markerthen use it as target. - None of above match, then enter operator-pending state to get target from user.