0

When editing text, I find it quite irritating that the normal mode commands, x, d and s all copy the text they remove. Don't we have y for copying? Perhaps I am "just doing it wrong", but for example in the following snippet,

copy me

_____ here ____

I would gg 0 yy jj fh dw h p. But dw also copies the word so we end up where we started. Instead I do something like gg 0 yy jj f<Space> p l de. Same number of commands but feels awkward.

To be clear, I'm not asking for a more effective way of achieving the above copy/paste situation (but feel free include anyway). Rather, is it possible to have d to only delete text and not copy it?

  • 1
    Check this answer. I suggest you get used to it. You can always use quote0 to get the copid text. I would do the copy by Scopy<c-x><c-l> or dd:1t.<cr>. – dedowsdi May 22 at 6:08
  • 1
    Also check this answer. – dedowsdi May 22 at 6:18
  • Thanks. Yes I forgot I could paste on top of a visual selection.. – algae May 22 at 6:30
2

Vim has many registers, and it's a shame not to use them all.

When you yank (copy) some text, it goes to the register "0". When you delete some word(s) they go to the register "-", when you delete some line(s) they go to the registers "1" (and old register "1" goes to register "2" and so on upto "9").

The problem arises when you put (paste) your text back. As Vim can't know what you exactly think of, it simply takes the last register used, be it "0", or "-", or "1" (well, actually there are also "letter"-registers and such, but let's forget about them for a moment). So this is what we call "unnamed register".

So it is a very reasonable default. But if it's not want you really want, you have to specify "0 (most often), "1 or "- before p explicitly. That's all.

| improve this answer | |
  • 1
    @algae Read :h registers. All "delete"-like commands are the same in this aspect. No real difference between d, c, r, x and so on. (Except, x can only delete lines in Visual mode, and such). – Matt May 22 at 8:08

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.