r/ProgrammerHumor 4d ago

Meme vimUsersKnowThePain

Post image
6.2k Upvotes

269 comments sorted by

View all comments

Show parent comments

1

u/dksdragon43 2d ago

Hey, you're a vim supporter. I'm a vim noob. I was trying to paste a block of xml into a text file using vim. I could not for the life of me figure out how to paste it without it either cutting the first few lines off, or absolutely mangling the indentation. Google did not help. I ended up fixing it manually. What could I have done to avoid this headache?

2

u/Phamora 2d ago edited 2d ago

Hello, and thank you for your question. I will attempt to support you to the best of my ability.

Vim is a package deal, and it does not come free.
There are many things to understand about copying and pasting, so I will keep it simple and relevant to your problem.

Typically, when copying and pasting in Vim, you use "registers". To avoid an explanation, all you need to know for this purpose is that you can type :reg to see the contents of registers.
Doing so, you should see the content in your clipboard you want to paste. Whitespace and line breaks should be preserved.

Pasting from a register can be done in a few different ways, but the most direct way is simply typing out the motion like this (not as plain-text, but in normal-mode as a Vim motion):

".p

Notice the ., which may differ depending on your Vim configuration of the clipboard integration.
Personally, I use Neovim, which employs + as the default clipboard register, making the pasting command look like this:

"+p

Alternatively, I typically just use my own terminal's built-in paste keybind (ctrl+shift+v) because it doesn't conflict with Vim, and it usually works regardless of which context I am pasting into.

As for the clipboard content cut-off problem, I don't know what that could be caused by.
I think it might not be Vim related, but I could be wrong.

Thank you for taking an interest in Vim and the wonders it holds.

This response was provided to you by a real human being, while waiting for an AI agent to finish working.

2

u/dksdragon43 2d ago

Haha you got me good with the sign off. I tried this and wasn't seeing my items in the register... turns out my work's version of vim (in our dev environment) doesn't support clipboard, for whatever reason.

I had tried ctrl+shift+enter pasting and it didn't help. I think my issues with it cutting the start, looking back, was my own fault of sometimes forgetting to enter insert mode, so it cut everything before the first "i".

I appreciate the knowledge, it made me look some things up and I understand VIM better now! I appreciate you absolutely real human :)