Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between number command motion and command number motion

Tags:

vim

I'm learning vim with vimtutor. I was wondering if there is a difference between command motion number and number command motion. For example: 2dw seems to me to work exactly like d2w, similarly 2dd does the same as d2d.

like image 929
Sok Pomaranczowy Avatar asked Sep 20 '25 13:09

Sok Pomaranczowy


1 Answers

The two numbers are both called [count], in your example, indeed, they do same job. But the two counts come from different concept.

[count]command

this will do the command [count] times, 2dd does dd twice; 2dw does dw twice.

The second is from the {motion}, 2w, 2j etc.

If you want to see some differences, here are two I can think of:

  • Some commands don't support {motion}. For example, the X, you press 2X, will remove 2 characters before the cursor. However, you cannot do X{motion}. other commands that don't support {motion} p (paste), s etc. You can do 2p, 2s, but you cannot do p2w s3w

You get same result from 2dw and d2w, but the two 2 have different meaning, understanding what the number does is ok. you can combine the count and motion, like 2d3w.

like image 88
Kent Avatar answered Sep 23 '25 10:09

Kent