52

Just a question about copy/paste workflow in gVim.

Right now I'm working on a document. I want to select some lines of code and copy and paste. I'm using gVim (Windows).

If I use Control + C and Control + V, gVim takes sometimes 2, 3 seconds to paste...

The other way is using, Shift + v (right, now I'm in visual mode), then I keep the Shift key pressed and drag my selection with the mouse. Now I can copy with 'y' or 'c' and paste with 'p'. This is faster, but I have to keep the Shift key pressed.

Is there a way to use the mouse to select text in visual mode without keeping the Shift key pressed? I want to use y/d/p instead of slow Control + c and Control + v. Is there a better workflow or setup that I should try?

Thanks,

[]'s

Mateus

1 Answer 1

133

Stay away from using CTRL-C/V and your mouse in vim, or at least until you're familiar with vim's way of text handling.

--

SHIFT-V to enter visual line mode

enter image description here

Press 3j to go down 3 lines, or press j 3 times

enter image description here

y to yank/copy, x to cut, p to paste after cursor, P to paste before cursor.

enter image description here

Using hjkl will improve your workflow greatly as you don't have to move your hands from the typing position to the arrows and the mouse.

There are a couple of ways to yank multiple lines without entering visual mode. One of which is to type <action><number><direction>. For example, y3j means to yank from your current row to 3 rows down.

If you want to yank the entire paragraph or sentence you're in, type yip (yank IN paragraph) or yis (yank IN sentence) respectively. You can also do yi" (yank IN ") or ya" (yank AROUND ") to yank everything that's surrounded by " on your current position.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Jin, thanks! It's not easy to 'unlearn' the mouse... I try your method and find out other way.
@homemrobo It wasn't easy for me too.. but I feel that it is worth it at the end. Took me about a week or two to learn enough essentials to get away from the mouse :p
Fun Fact: The yanked lines can not be pasted anywhere else or in vim on another machine. Figured out when I yanked (still not comfortable with this term) some lines on Vim on a remote server and tried pasting those in Vim on my local machine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.