0

Yes, I know that d2e and 2de are two different commands and therefore works slightly different, though it's not visible to the eyes.

Let's call them "number-in-the-middle" (nim) and "number-in-the-beginning" (nib). As I know, some commands doesn't work with nim syntax, but successfully works with nib one. So, is it a good idea (for newbies) to get rid of nim syntax and stick to nib, to have consistent behavior across all commands? And are there any commands that doesn't support nib syntax?

  • 1
    wait, how are d2e and 2de different? – Mass Mar 4 at 2:16
  • @Mass Here are some links: first, second and third -- the pages in this book aren't numbered, so use a search phrase: "both d2w and 2dw will work". – john c. j. Mar 4 at 2:35
  • The second link there seems to explain the difference. You should stick with nib, since it is always supported. – Steven Walton Mar 4 at 2:37
  • all of these links confirm that they are the same. I would go further and say there is absolutely no difference between the two, certainly not from the point of view of vim's source code. – Mass Mar 4 at 2:51
0

As far as built-in operators and motions go, they are completely identical. There is some semantic value; "delete to 2 ends of words" vs "twice, delete to end of word," but from vim's perspective there is only a single count for the operator+motion. You can provide both if you wish:

  • 2d2e means delete 4 to end. The rule is that vim multiplies each given number to produce the count (which is 4).

In fact, you can use even more with registers:

  • 2"ade 2de, but place in register a
  • "a2de identical to above
  • "ad2e identical to above
  • 2"a2d2e, delete to 8 ends of words, placing in register a.

Similarly, with puts from a register, you can specify multiple counts:

  • 2"a2p paste four times from reigster p.
  • 2"a2"a2"a2"ap paste 16 times from register p.

Some commands, despite not being operators or motions do support "middle" count. The primary example is the <c-w> family of window commands. 2<c-w>2w means go to window 4.

There are some caveats though:

  • some operators are multiple characters, like gu. You can write 2gue or gu2e, but not g2ue, since the operator is gu as a unit.
  • some motions and text objects are multiple characters. d2iw is fine, but di2w is meaningless. d2gj is good, but dg2j is not.
  • custom maps can break. Let's say you make the map

    onoremap <space> 2w
    

    Then 2d<space> works exactly as you expect: it deletes four words. However, d2<space> means d22w!

  • 1
    I believe there exists a slight variation in handling the dot command . but I’d be willing to be proven wrong – D. Ben Knoble Mar 4 at 4:37
  • As I understand you agree that nib is better for newbies? – john c. j. Mar 4 at 11:54
  • @D.BenKnoble I think if there is such a variation, that needs to be proven, not the opposite. Otherwise, there is no reason to suspect they are different. I have never seen a difference, but I'd also be willing to be proven wrong... johnc.j., not sure who you were asking but my answer indented to say that neither was better for people new to vim. – Mass Mar 4 at 13:23
  • Experimentation indeed proved me wrong. What I had remembered reading in Practical Vim was the caveat that often counting is hard, and hitting . after, e.g., de, is much easier. – D. Ben Knoble Mar 4 at 14:49

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.