Content #
An operator is a command that waits for you to enter a movement command, and then does something on the text between where you currently are and where the movement would take you. Some examples of operators are: d, y, c.
Movement Mappings #
:onoremap p i(
在代码的函数参数中按dp,可删除所有参数。按cp会删除后进入插入模式。
:onoremap b /return<cr>
在函数体代码中按db,可删除从当前位置开始直到return所在位置之间的所有代码。
定义新的operator-pending movement的步骤如下:
- Start at the cursor position.
- Enter visual mode(charwise).
- …mapping keys go here…
- All the text you want to include in the movement should now be selected.
Changing the Start #
:onoremap in( :<c-u>normal! f(vi(<cr>
“<c-u>”: remove the range that Vim may insert. “normal!”: simulate pressing keys in normal mode. “<cr>”: executes the :normal! command. 按下cin(,会删除当前行的小括号中的内容,并进入插入模式。
inside last parentheses
:onoremap il( :<c-u>normal! F)vi(<cr>
上一个括号。
General Rules #
- If your operator-pending mapping ends with some text visually selected, Vim will operate on that text.
- Otherwise, Vim will operate on the text between the original cursor position and the new position.
From #
Links #
:help omap-info