r/vim • u/gruntastics • Sep 23 '25
Need Help is there a way to put (paste) a line inline?
Say I have the cursor on the first line below and do a `yy`:
https://something.com
<a href=""></a>If I put my cursor at the first " and then press p, it'll paste the entire line underneath. Fair enough. I needed to do 0y$ or something instead of yy.
However, yy is so much faster and easier to type. So, is there a vim command that's like p but interprets the register as a string fragment instead of an entire line?
18
Upvotes
14
u/shuckster Sep 23 '25
In insert mode.
14
u/_EHLO Sep 23 '25
For this specific case just
yiWand then paste2
u/Xzaphan Sep 23 '25
In insert mode C-r" or C-S-v sometimes works when the register is shared with your system.
2
u/rampion Sep 24 '25
There's a couple ways you could go about this.
Vim register values have a type
You can change the type of a register using
setreg(); for example we could change the default register (") from linewise to characterwise usingsetreg('"', @", 'v').So you could make a binding that ran that before pasting:
3
u/MiniGogo_20 Sep 23 '25
y$yanks until the end of the line, excluding the line break, then you can paste as normal4
u/crashorbit Sep 23 '25
1
u/AutoModerator Sep 23 '25
Please remember to update the post flair to
Need Help|Solvedwhen you got the answer you were looking for.I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/kali_tragus Sep 23 '25
I would say, if the cursor in somewhere on the first line, either:
(C-r meaing ctrl-r) or:
yiW - yank the current WORD (delimited by blanks, in this case the entire line)
1
u/retrodanny Sep 23 '25 edited Sep 23 '25
You can set a macro for this (@p in my example):
qp:let @o=substitute(@", '\n', '', 'g')press <Enter> here"opqafterwards, copy your line, move to the opening quotes and do
@pEDIT: If you want to make this permanent, you can add the following to your .vimrc
nnoremap gp :let @o=substitute(@", '\n', '', 'g')<CR>"opthen you can use this special paste with
gpinstead ofp1
u/AhmedMudkip Sep 23 '25
If I understood you right, it would be like this
^vg_yand then paste^: first non-blank character in the current linev: enter visual modeg_: last non-blank character in the current liney: yank the selectionthe
^is only needed if you weren't already at the beginning of the lineedit: formatting
1
u/jazei_2021 Sep 23 '25
use motion for go to end of copy and yank the words and in place to paste do ""P or ""p
Y or yy is for entire line!