2

If I paste text that ends with "\n" (eg. "aaa\n") into quotes (eg. "") or tags (eg. <foo></foo>), It will paste like this:

aaa
""

aaa
<foo></foo>

but it should be:

"aaa
"

<foo>aaa
</foo>

Does anybody know what's the matter?

Aaron Bell
  • 852
  • 2
  • 11
  • 26
jamesqiu
  • 1,694
  • 1
  • 11
  • 6

2 Answers2

1

What happens here is that the register from which you are pasting is not characterwise but probably linewise. you've probably pasted the text with yy or Vy or dd or Vd. That's a feature that enables you for example to use ddp to swap two lines.

If you want to turn the register to a linewise register you can do:

:call setreg('"', @", 'c')

then P or p will insert what you pasted characterwise.

Of course if you are pasting with another register ("ap for example) you'll have to modify the first and second arguments to setreg.

Another way to copy lines: if you want to yank a line characterwise including the newline, you can do 0y$.

References:

  • :help setreg()
  • :help linewise-register
Benoit
  • 76,634
  • 23
  • 210
  • 236