operator,
the true power of Vim

kana <wizard(a)vim-users.jp>
http://whileimautomaton.net/

How Vim user grows

How Vim user grows - Lv0

You already know what Vim is, eh?

How Vim user grows - Lv1

i, a, <Esc>, x, dd, :e, :w, :q, ...

Lv2. Visual mode

Basic usage

  1. Start Visual mode, v
  2. Select text by moving the cursor, hhjjkkll
  3. Do something on it. d

Example of something:

Advanced usage

There are 3 variants of Visual mode:

Do something on *wise text.

Summary

Merits of Visual mode:

So Visual mode is quite useful for beginners.

See also :help Visual-mode

Lv3. Various motions

What is "motion"?

Vim has various motions.

motion is a command to move the cursor.

Example of motions:

See also :help Q_lr

Combination

Visual mode + various motions =

But...

Recall that Visual mode is:

... Similar to ordinary editors?

So why don't you use them instead of Vim, the strange editor?

You still have a lot of work to do.

Lv4. Operators

What is "operator"?

Recall the last description of Visual mode:

  1. Start Visual mode, v
  2. Select text by moving the cursor, hhjjkkll
  3. Do something on it. d

something is called an operator.

operator is a command to edit a portion of text.

Basic usage

operator edits on the selected text in Visual mode. But

operator can also be used in Normal mode. If so,

operator takes a motion to determine text to be edited.

Example of usage:

Orthogonality

operators and motions are orthogonal, so:

Once you learn a new motion,
you can do edit on various portions of text with operators you learned.
Once you learn a new operator,
you can do new kind of edit with various motions you learned.

In other editors, you have to learn many comibations of them. kill-line, kill-sentence, kill-pragraph, kill-sexp, ... too-many-to-learn

inclusive/exclusive (advanced)

{operator}{motion} is similar to v{motion}{operator}

But there are 2 types of motions:

inclusive motion
works as same as v{motion}{operator}
exclusive motion
the character at the destination of motion is not affected

The differences are natural - You don't need to be conscious of the types of motions.

*wise (advanced)

There are 3 types of the effects of operators:

*wise can be varied by operator and motion

Forcing *wise (advanced)

You can force *wise with the following keys:

Usage: {operator}{*wise-specifier}{motion}

Summary

The merits of operators are:

In most cases, you can specify some portion of text by a single motion, so you don't need to use Visual mode often.

Lv5. Text objects

Basic usage

Text object is a special kind of motion

Text object can be used in Visual mode or Operator-pending mode (i.e., after an operator)

Text object selects a kind of object, for example:

See also :help text-objects

Comparison

Some text objects are similar to some motions, but

You don't need to adjust the cursor

You'll be able to edit more effectively with text objects

Lv6. New text objects

Once you master text objects...

You'll want to write your own text objects

Examples:

But it's too hard for usual Vimmers to write text objects in valid and right way

How to write your own text objects

textobj-user - a library to write new text objects - http://www.vim.org/scripts/script.php?script_id=2100

call textobj#user#plugin('datetime', {
\      'full': {'select': ['adf', 'idf'],
\               '*pattern*': s:REGEXP_FULL},
\    })

Summary - How Vim user grows

Do you have any questions?