Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paste data at the start of line in visual mode

Tags:

vim

vi

I can select lines using SHIFT + V, then selecting lines using up down left right keys, then copy them using y (yank them) and paste them using p (put).

I can similarly select data block using CTRL + V, then selecting lines using up down left right keys, then then copy them using y (yank them) and paste them using p (put).

But when I am pasting data blocks using p, it always pastes data after the current cursor location. Which means, if I want to paste to the beginning of lines, it won't work - it copies the data after the first character. So how can I paste data block at the beginning of a line in vim in visual mode?

Curently I do this by pasting at the second cursor location, deleting the characters at the beginning of line, and then pasting them after the previously pasted block.

like image 492
Anshul Goyal Avatar asked Dec 11 '14 10:12

Anshul Goyal


People also ask

How do I paste to the beginning of a line in Vim?

Lowercase 'p' will paste AFTER the cursor. Use a capital 'P' and it will end up BEFORE the cursor.

How do I paste a yanked line in Vim?

For pasting something from the system clipboard into the Vim command line ("command mode"), use Ctrl + R followed by + .

How do I copy text in visual Vim?

Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy.


1 Answers

select and yank as what you are doing, when you paste press P instead of p. The content in " register will be put before your cursor.

also note that: with p or P, after your pasting, the cursor will stay at the beginning of the just pasted content. If you want your cursor to be at the end of pasted text, use gp or gP.

like image 195
Kent Avatar answered Sep 21 '22 15:09

Kent