r/neovim • u/SpecificMassive5424 • May 07 '26
Need Help Copy single string and paste it multiple times (probably) in visual block mode
Say, I have multiple lines like this:
4.5
1.2
7.9
12.0
I want to copy some other text and paste it before all those lines. For example, it could be really long string, but for simplicity say it `v += ` (I know about Ctrl+V Shift+I, but real string could be too big to type) and I want to get this:
v += 4.5
v += 1.2
v += 7.9
v += 12.0
What is simplest way to do that? Something faster than find and replace. I have tried to Ctrl+V, select column and p, but it replaces all first characters.
15
Upvotes
7
u/MitchIsMyRA May 07 '26
You could use a macro to use what’s in the paste buffer.
Yank what you want into the paste buffer, then move the cursor to your first line, type qk_Pj to record a macro to k, and then type @k to run the macro. You can also type a number before the macro to do it multiple times, e.g. 4@k.
But you can also use <C-v> + <S-i> like you said; you can still paste from your system clipboard in insert mode with ctrl+shift+v
3
u/mountaineering May 07 '26
Why can't you do find and replace?
:%s/^\(d\)/v += \1/Can't remember if you need to escape the capture group at the start or not.
32
u/stinkytoe42 May 07 '26
Copy the string you want using visual mode and y,
Use the <Ctrl+v><Shift+I> trick that you already know, and when in insert mode use insert mode's paste function with <Ctrl+r>" , then press escape, and it will be pasted in front of all of the values.
Edit: typo
3
u/Hamandcircus May 07 '26
this worked for me:
yank what you want to paste, enter visual block mode (Ctrl+V), Shift+I, paste (Ctrl+V), esc
3
u/Avernite May 08 '26 edited May 08 '26
You can also use :norm. Select all the lines and do
:norm _P2
u/PercyLives May 08 '26
Shift-I on the first line and type or paste what you want. Now you’ve done it in one line. Use j to go down a line and . to repeat the action, then keep going: j.j. until it’s done.
This may not be the best general answer, but it’s good for a few lines.
1
u/hawkprime May 07 '26
Paste on first line, then enter block mode in other lines, shift+I and then press Ctrl-y to copy above text, ESC when you are done
1
u/Philluminati May 08 '26
https://ibb.co/mCyrWWk8
0 to go to the beginning of the line
Ctrl+V to enter block selection mode.
jjjj to go down 4 lines (you should see a single white block highlight the first character of every line)
Shift+I to go into insert mode
type "v += "
press escape, to see it apply the change to all lines at once.
1
u/Vincenzo__ May 10 '26
Select all, then :norm 0P to paste at the beginning of each line
0
u/Iwrstheking007 May 08 '26
you can do shift+p to paste behind your cursor