Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simplify "copy and paste" in Vim?

Tags:

I find that the procedure to copy and paste in VIM is very tricky:

  • Visual mode
  • Y
  • p (or shift p)
  • insert mode

and if you wrongly use "delete" key, you lost the content (is replaced by the char you deleted) and you have to re-copy it !

I am working on vim since several months, I like it, but I hate the copy and paste, there is a way to simplify it ? or some alternative ?

thank you

like image 425
Alessandro De Simone Avatar asked Jan 21 '12 23:01

Alessandro De Simone


People also ask

How do I copy and paste in Vim mode?

Press the “Esc” key and tap “I” to open the “Insert” mode of the Vim editor. The “yank” or “y” command is used to copy the selected text.

How do I copy and paste an entire line in vi editor?

Directions: Press the ESC key to be sure you are in vi Command mode. Place the cursor on the line you wish to copy. Type yy to copy the line.


1 Answers

Vim maintains a list of the last 9 deletes you have made in the numbered registers. So "0p will paste the most recent thing you have yanked, "1p will paste the 2nd most recent thing you have deleted or changed (note this does not include text that was simply yanked), and so on for registers 2-9.

If you want to use more than the last 9 deleted items or if you want an easy way to access previous yanks I would recommend the yankring plugin which, among other things, lets you see your last 100 yanks and choose which one you want to paste with the :YRShow command.

Finally if you want to paste without leaving insert mode you can use Ctrl-R to insert the contents of any register. So in insert mode typing <Ctrl-R>" would insert the contents of the unnamed register " (which is where yanked text gets put when no register is specified).

like image 140
David Brown Avatar answered Oct 09 '22 21:10

David Brown