The command p pastes below the cursor and P pastes above the cursor. What's the command to paste in the line where cursor is?
This all depends on the type of data in the register you're pasting. If the data is line-oriented data (yanked with yy for instance) it will be pasted as a whole line above or below the cursor. If the data is character-oriented (yanked with e.g. y2w) then it will be pasted at or before the cursor position in the current line.
See :help linewise-register
for more info on the interaction between the type of register and the put command.
0y$
rather than the linewise yy
. p
or P
will paste into current line or different line depending on whether yank was characterwise (pastes into current line) or linewise (pastes into line above or below). –
Weisman p
/P
, you might want to check out UnconditionalPaste by Ingo Karkat. vim.org/scripts/script.php?script_id=3355 –
Myriapod vp
is the answer... https://mcmap.net/q/299254/-how-to-paste-in-the-line-where-the-cursor-is –
Kenna The Edit menu in gvim lists the following:
Paste = "+gP
Put Before = [p
Put After = ]p
If you're running vim in Windows, you can do the following to get Ctrl+C and Ctrl+V to work as expected:
source $VIMRUNTIME/mswin.vim
behave mswin
If you want to keep the current line as it is, you either paste above or below the line.
If you want to overwrite the current line you'll have to delete it first, which means that the following line takes its place, then paste above the new current line.
There are more than one way to do it:
"_ddP
"_dd
deletes the whole current line in the "black hole register", the following line is now the current line.P
puts the content of the unnamed register above the current line.
Vp
V
puts you in VISUAL LINE mode and selects visually the whole current linep
replaces the selection with the content of the unnamed register
S<C-r>"
S
deletes the content of the current line and puts you in INSERT mode<C-r>"
puts the content of the unnamed register
The two last options have an interesting side effect: the content of the previous line is put into the unnamed register which makes it impossible to do multiple pastes with the same content.
Luckily, you can work around this situation:
The "black hole register", mentioned in the first solution works, well… like a black hole. Whatever you put into it disappears forever so you can continue using
p
andP
with some degree of confidence that the unnamed register is still the same from paste to paste.Vim gives you access to 26 alphabetic registers that you can use to save macros or… paste stuff repeatedly.
Taking the second solution as a starting point, you start by yanking a whole line into register
"a
with"ayy
then you doV"ap
on another line.
But all of the above assumes that the text you want to paste is an actual line. Vim makes the difference between "line-wise" and "character-wise" : it won't let you paste a line in a character-wise context or the other way around.
Yanking a whole line with yy
keeps its line-wiseness or character-wiseness and you won't be able to p
between two characters on a same line. For that you need to make sure that what you yank won't be interpreted as line-wise by Vim. For example, let's assume you are on the first character of the first line and want to yank ipsum dolor
and put it at its normal place between lorem
and sit
:
ipsum dolor
lorem sit amet
You should type "ayee
to put your yanked text in register "a
, place the cursor where needed and type "aP
.
"*
is not the unnamed register. ""
is the unnamed register. See :h quotequote
. I imagine you have changed 'clipboard'
to include unnamed
. –
Myriapod To paste in insert mode you just press Control+R. Then enter the register, e.g. Shift++.
To paste in command mode, you press P, however you've to make sure your line doesn't have a new line character (e.g. yanked by 0v$hy
), otherwise it'll appear above the cursor.
The same for visual mode, see: How to paste a line in a vertical selection block? at Vim SE
vp
that's how, type vp
in normal mode
How is this not an answer to a 10 year old question, stackoverflow slip'n?
The character under the cursor will be replaced by the the put
To help with and many others scenarios, I've mapped rr
for the ability to quickly add a space, or some other 1-off character.
noremap rr i<space><esc>r
in my ~/.vimrc
You can use D to delete from current cursor position to the end of line, and the p to the new cursor position.
That is to cut and paste a whole line use ^D and p.
I needed to "cast" register contents into a certain (characterwise / linewise / blockwise) mode so often, I wrote the UnconditionalPaste plugin for it. It provides gcp
, glp
, etc. alternatives to the built-in paste commands that force a certain mode (and by now several more variations on this theme, like pasting with joined by commas or queried characters).
With it, you can just use gcp
/ gcP
to paste after / before the cursor position, regardless of how you've yanked the text.
Shift + v will select the entire line, but you don't want to do that. Instead, press CTRL + v from the beginning of the line which will select by character, then $ to select to the end of the line. yank y and paste p.
(I know this thread is old, just leaving this and hope this may help someone)
Inspired by @wbg's comment above regarding deleting the line feed, I added these to my mappings:
nnoremap <leader>p :let @"=substitute(@", '\n\+$', '', '')<CR>p
inoremap <leader>p <esc>:let @"=substitute(@", '\n\+$', '', '')<CR>pa
This is useful when I have a file with some SQLs (line by line) and I have to yank into the code.
.vimrc
. I added a space at the end of the command so it makes more sense for me. Surprised this answer has not appeared many times elsewhere. nnoremap <leader>p :let @"=substitute(@", '\n\+$', '', '')<cr>pa <esc>
–
Erhard If you want to shift existing contents and you are pasting a full line or more from the buffer...
- P pastes on the current line and stays on the current line.
- p pastes on the next line and stays on that next line (aka the first line of pasted content).
- gP pastes starting on the current line and moves to the line after the paste.
- gp pastes starting on the next line and moves to the line after the paste.
To overwrite the current line, refer to other answers (usually something like R, Ctrlr, ")
I'm not sure there is one. I tried to find documentation and ran across the following three documents:
Unfortunately, all three only have the two commands that you list. Particularly, the third link states that The commands to paste are p and P...
divide the line into 2 wherever you want to insert
paste the section between them
merge the 3 lines with j as described here (Delete newline in Vim)
works, but tedious, and had to think about, look it up => vi and emacs are garbage software
© 2022 - 2025 — McMap. All rights reserved.