Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I block copy into the original text not overwrite in VI?

Tags:

vim

Now, I'm using Linux and VI editor. During I use VI I have some problem. When I use block copy into the text, that texts are overwrited on the original text.

How do I block copy into the original text not overwrite in VI?

add screen shot

screen shot


1 Answers

If you've yanked a blockwise visual selection, pasting that will insert the block at the current position, into the existing text, without adding new lines or shifting existing text downwards. That's the expected behavior; you're effectively handling a square "cutout" of text, separate from the underlying text structure.

If you're handling complete line(s) (and based on your screenshot, you're doing just that), the correct approach is to select and yank the text linewise; i.e. use Shift + V instead of Ctrl + V for the selection (or [count]yy in normal mode, which is faster if you know the number of lines).

If you really need to yank a square block, and paste this as new lines, there are the following approaches:

  1. Make space before the paste (e.g. 10o<Esc>`[), then paste.
  2. Change the mode of the register between yank and paste: :call setreg('', '', 'al')
  3. Use my UnconditionalPaste plugin; it offers (among others) a glp command that forces linewise pasting, regardless of how the text was yanked.
like image 184
Ingo Karkat Avatar answered Sep 19 '25 18:09

Ingo Karkat