Operator-Pending Mode

Reading through public dotfiles is one of the ways that I research articles for usevim, and also how I learn new Vim techniques. However, one thing that I find surprisingly lacking is operator-pending mappings (:help omap-info). To understand this cryptic term, you need to revisit operators and motions.

After typing an operator command, Vim will wait for a motion. For example, typing yw when in Normal mode will yank the word under the cursor: y is the operator command and w is the motion. The operator is said to be pending in the time between typing the operator command and the motion.

Operator-pending mappings can be used to map characters during this time.

If I was replacing a lot of text inside HTML tags, I could map the it text object to t:

:omap t it

Now typing dt will delete the text between an opening and closing tag. Also, yt will yank it and ct will remove it and start editing.

Although we're used to thinking about the Normal, Visual, and Command-line modes, Operator-pending mode (:help Operator-pending-mode) is also considered a mode. Granted, it's a variant on Normal mode, but it is a specific state that's addressable by mappings.

blog comments powered by Disqus