user7166570
user7166570

Reputation:

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

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

Upvotes: 4

Views: 1085

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172638

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.

Upvotes: 2

Rakib
Rakib

Reputation: 2096

In vi or vim editor you need to go in visual block mode from command mode using ctrl+v. before going to visual block mode move cursor to the block you want to copy. then press ctrl+v. and select your block.After selecting you just press single y for copy. Then move to cursor end of the file and press p to paste. Thats it.

Upvotes: 0

Related Questions