Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select a chunk of text and paste it to the current cursor position w/o using mouse in vim?

Tags:

vim

copy

paste

I want to give up using mouse for selecting and pasting chunks of text within a buffer. Whats the most efficient way to do this with just kb? I mean navigate to arbitrary line, copy the substring, return to the previous position and paste.

like image 703
planetp Avatar asked Feb 26 '10 12:02

planetp


People also ask

How do I select and copy text in Vim?

Copying in VimUse the y key on the keyboard when performing this operation. There are a number of yank commands, mainly differing on the amount of text you want to copy. Once in normal mode, move the cursor to the needed place and use the appropriate command. The command stands for “yank till x”.

How do I cut and paste in Vim?

Press d to cut (or y to copy). Move to where you would like to paste. Press P to paste before the cursor, or p to paste after.

How do I copy and paste in Vim editor?

You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.

How do I paste a line above and below the cursor line in Vim?

The command p pastes below the cursor and P pastes above the cursor.


1 Answers

Very simple method:

  1. Select the lines with Shift-V
  2. "Yank" (=copy) the text with y
  3. Paste the text with p at the position you want to.

There are of course many other ways to copy and paste, yy copies the current line for example.

Do the some VIM tutorials, it is better than learning everything bit by bit.

like image 194
Otto Allmendinger Avatar answered Oct 02 '22 03:10

Otto Allmendinger