r/vim • • Aug 28 '19

Cut, Copy and Paste in Vim

Post image
659 Upvotes

38 comments sorted by

68

u/ceplma Aug 28 '19 edited Aug 28 '19

I have doubts about this approach. You try to translate vim to the more common Copy/Cut/Paste operations, but I am afraid the result is that both reader is confused and vim looks silly (because it looks ridiculously complicated). I would rather teach new users about objects and movements, which I think is a way more important thing about vim than whole hjkl (I still use arrow keys quite frequently and I don’t think there is anything wrong with it).

5

u/[deleted] Aug 28 '19 edited Aug 28 '19

To each at their own, i guess. Personally I like this way.
**Edit: There it is other version with Delete,Yank,Put

13

u/Asfalots Aug 28 '19

I agree, vim commands must be teach as language, not as reference to other concept. It will make them a lot easier to remember.

Best talk on this: https://www.youtube.com/watch?v=wlR5gYd6um0

5

u/[deleted] Aug 28 '19

I watched this talk when I first got using vim and I remember how waaaayyy over my head everything seemed to be for me. Barely understood anything he said and thought it was way too complicated for me.

Having used vim for months now (not as my main editor but at least once a day I switch to vim to practice and growing a lot more familiar with its core functionality, I can understand a lot better this talk and actually get useful information out of it. Definitely realized some gotchas I was doing like using w instead of iw for editing.

I still got lost a bit when he got into all the plugins but I figure give I another year and I’ll be watching this and saying ahhh yes this makes perfect sense.

1

u/red_circle57 Apr 16 '26

I know this is old but this comment is baffling. A beginner this cheat sheet is way easier to understand and consume than the 2,700 word stack overflow answer you linked.

24

u/[deleted] Aug 28 '19

I do not recommend beginners (or anyone else for that matter) to use this.

Trying to use vim like notepad by translating things into copy-paste commands is confusing and kind of pointless.

People should instead learn about registers, and vim language, i.e. operator + (object / movement). Trying to memorize this cheatsheet without understanding the core philosophy is just making things more complicated than they need to be.

19

u/ivster666 Aug 28 '19

TIL: gp

2

u/zorganae Aug 29 '19

You are not alone my friend!

1

u/chrisrelaxes Sep 01 '19

exactly my thoughts fellow vimmer.

7

u/benoliver999 Aug 28 '19

The more I think about it, the more I think that the cut/copy/paste features are what make me so quick in vim.

2

u/Skaarj Aug 28 '19

So, gp is new for me. However, to me it seems the same as p followed by move right. Is there a special case that I am missing where gp does something special/useful?

2

u/[deleted] Aug 28 '19

Pasting with p cursor stay static (it doesn't change position). Pasting with gp or gP, cursor is moved to the end of the text you pasted.

3

u/Skaarj Aug 28 '19

Pasting with p cursor stay static (it doesn't change position).

That is not true. I just tried with (even with vim -u NONE) and my cursor is on the last character of the end of the text I pasted with p.

2

u/Probotect0r Aug 28 '19

gp is useful for when you are pasting lines, instead of just words. When pasting lines (say after using yy), your cursor stays in the same spot.

1

u/Botskiitto Aug 28 '19

Can confirm, also I don't really see a use case for the gp but please someone prove us wrong.

10

u/crajun gave up on vim Aug 28 '19

‘]p’ to paste and auto indent is something I use several times a day.

5

u/Reasintper Aug 28 '19

also, for the command line:

:. <-- . is current line
:.,+3 <-- plus the next 3 lines
:.,+3y <-- yank them :)

from the : you can also do m=move and t=copy so

:.t0 <-- copy the current line to the 0th position in the buffer
:.m$ <-- move the current line to the last line of the buffer

maybe this is off topic, but seemed related to me

1

u/meathead_joe Nov 08 '25

late reply, but I couldn't remember this command for anything. Thanks so much!

4

u/Reasintper Aug 28 '19

Vim "can" use the clipboard by adding

set clipboard=unnamedplus,unnamed

To the end of my .vimrc file I can simply use things like ggyG or yy and move to another application and sh-insert or ctrl-v to my heart's content :) Or just as well, I can copy a block of text from this webpage with the mouse or ctrl-c and move over to vim and use p or shift-insert.

5

u/hangulsve Aug 28 '19

I don't know if every command has a "sentence" to remember it by, but for example "yiw" can be memorised with/means "yank inner word".

5

u/[deleted] Aug 28 '19

[removed] — view removed comment

7

u/hangulsve Aug 28 '19

Yeah it's like if you know the parts you can assemble what you want to do.

I want to y: yank, d: delete, c: change, etc.

Where? i: in, a: around, etc.

What? w: word, (: parentheses, ": quotes, [: curly-brackets, etc.

2

u/derpOmattic Aug 28 '19

Very nice! Thanks.

2

u/gderti Aug 28 '19

Has anyone else asked?? Will there be/is there some Reddit way to group these, to me, WONDERFUL cheatsheets and see them all or reference them all together? Everyone has shown me some nuance that I've missed or forget. They're the perfect set of help, as far as I'm concerned...

Thank you.

4

u/starship-unicorn Aug 28 '19

OP has said they plan to post a consolidated document once they have worked their way through the series.

2

u/christian-mann nnoremap ; : Aug 28 '19

Search "you don't grok vi stackoverflow" and then come back and see the simplicity here

3

u/BloodyNobody Aug 28 '19

Vim doesn't put text on clipboard, but in registers.

Gvim, on the otherhand, has a clipboard register: +

To copy to it, enter

:"+y

6

u/Chessifer Aug 28 '19

Vim also has those registers (:"+y and :"*y)

0

u/[deleted] Aug 28 '19 edited Aug 28 '19

Because I tend to use the clipboard register pretty frequently, I remapped "*y and "*p to ;;y and ;;p. Much easier to type ;)

It does interfere a little with ; to go to the next instance of f/F/t/T<char>, so maybe others may want to choose a different key. (it doesn't stop ; from working, but introduces a slight lag)

I typically use / or ? for searching, so it doesn't bother me too much.

0

u/graywh Aug 28 '19

only if it's actually gvim (generally)

2

u/[deleted] Aug 28 '19

All it requires is that your Vim is compiled with +clipboard (IIRC), which is the case for the Vim that comes with many GVim packages

1

u/graywh Aug 28 '19

Did you mean :y+? Because what you put is just a comment.

2

u/Bakton Aug 28 '19

Love it, keep 'em coming. :)

1

u/jillesme Aug 29 '19

I use all these on a regular basis but never saw them written out like this.

1

u/mlopes neovim Aug 29 '19

You can also start your copy command with ”+ to yank to clipboard, as long as your vim is compiled with clipboard support.

1

u/[deleted] Aug 29 '19

Something that I have been trying to find for a long time. Is there a way to delete lines/blocks/motions without modifying the registers?

1

u/ultrablastTTV Jun 18 '25

Вообще комменты не читайтей тут одни душнилы. Для работы при ребейзе самое то

1

u/javajunkie314 Aug 28 '19

For some reason I'd never considered %y. I've always used ggVGy. So thanks for that.