5

I am just a bit curious on how vim makes the difference for i between the insert mode and the inner word.

If I am in normal mode, and I type i then I go in insert mode.

If I am in normal mode, and if I type ciw, it means that I want to change the inner word (well, I get in the insert mode at the end).

But how does vim know that the i in the second case does not mean "insert"?

5

This is the description of c in the help file:

["x]c{motion}      Delete {motion} text [into register x] and start insert.

The register is optional, but the motion is mandatory. A lone c makes no sense. In other words, we say that c triggers the operator-pending mode. Therefore the distinction between a normal mode i and an operator-pending mode i is unambiguous to Vim.

The bottom line is that Vim, being a modal editor, interprets keys differently depending on the mode it is in. They are frequently related (for example, e, ce and ve all involve movements to the end of the current word, although the second in operator-pending and the last in visual mode), but on some occasions, such as the one in question, they couldn't be related (what would entering the insert or append mode after a change or visual command mean?), and thus become good candidates for special behavior.

3
  • 1
    Thanks a lot ! Very clear ! – Makoto Dec 23 '20 at 12:05
  • 1
    It would be great to also mention Visual mode, since iw in Visual mode also means "inner word" and doesn't go into Insert mode (e.g. viw selects current word in Visual mode.) The general point is that Vim is a modal editor and keys and sequences mean different things in different modes. While some modes behave similarly (e.g. motions in Normal or Visual or Operator-pending mode) there are still differences (such as i from Normal to start Insert, vs. iw or other text objects in Visual or Operator-pending mode.) – filbranden Dec 23 '20 at 12:51
  • 1
    @filbranden I hope I have now made that point more clear. Thanks for the suggestion, cheers! – Quasímodo Dec 24 '20 at 11:42
5

Vim keeps what you type in memory, even when it seems to have no effect on the screen, this allows you to apply modifiers to commands.

To see what modifiers you typed, and will be applied to the next command, you can use :set showcmd. They will appear at the bottom right of the screen.

Another good example of that effect is how G will take you to the end of the document, but 10G will take you to the 10th line!

1
  • thanks a lot for your answer ! – Makoto Dec 23 '20 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.