1

I've read this question and answer already, however it could not solve my doubts.

As far as my understanding is correct, p always has the same effect (pastingutting the content of a bufferregister, by default the " bufferregister).

Different effects of the p command are actually a consequence of different contents of the register(s) that we paste. In this respect, given the sample text

-----------
---moree---
---lines---
---oftxt---
-----------
moree---
---l

I notice the following:

  1. yanking/deleting character-wise more into a register fills the register with more;
  2. yanking/deleting line-wise ---moree--- into a register fills the register with ---more---^J, where ^J is a single caracter representing the linefeed <NL>;
  3. yanking/deleting block-wise the alphabetic rectangle fills the register with moree^Jlines^Joftxt, where ^J has the same meaning as above.

However:

  • Concerning 2 as compared to 1 and 3, how can something (^J) later in the register affect where the pastingutting action starts?
  • Concerning 1 and 2 as compared to 3,
    • yanking a visual selection going from the first m to the first l will fill the register with moree---^J---l,
    • yanking a block CTRL-Visual selection of the last two lines (obtained by 0CTRL-Vj$) fills the register exactly with the same content moree---^J---l,
    • however pastingputting the two registers will have a different effect.

Can someone please help me understand this?

Besided, is it possible to get ^J in text just as can get ^M in text by CTRL-VEnter, ^[ by CTRL-VEscape and so on?

  • 1
    RE the last question: Ctrl-V + Ctrl-M then :set fileformat=mac ;) – B Layer Sep 20 at 0:57
  • 1
    Just to clarify: p pastes from registers (you use the term in most of your Q, but you say buffer at the top, and that has a very different meaning in vim) – D. Ben Knoble Sep 20 at 2:06
3

As far as my understanding is correct, p always has the same effect (pasting the content of a buffer, by default the " buffer).

In Vim they say "putting", not "pasting". And what is more important, that particular "thing" is called "a register", so to find a relevant help topic you should type: :h registers, not :h buffers (which will lead you to a totally different place).

Another (more subtle) point is that although the documentation says "unnamed register", but, in fact, " is a pointer to the last register used. So, for example, after the yank command (without explicit register override) " points to a register named 0, and after delete it points to the register 1, etc.

however pasting the two registers will have a different effect.

That's easy. Besides "contents" all registers also have "type" which is normally deduced automatically. In your case :echo getregtype('"') will print different values, and so p will behave differently too.

  • +1 and accepted (even though the idea that the textual content of the register was enough to determine the effect of p with no need to have such a thing as the type of the register was cooler). The comment about the " being a pointer to the last register used is illuminating. – Enrico Maria De Angelis Sep 21 at 22:31

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.