I often have to paste some stuff on a new line in vim. What I usually do is:
o<Esc>p
Which inserts a new line and puts me in insertion mode, than quits insertion mode, and finally pastes.
Three keystrokes. Not very efficient. Any better ideas?
I often have to paste some stuff on a new line in vim. What I usually do is:
o<Esc>p
Which inserts a new line and puts me in insertion mode, than quits insertion mode, and finally pastes.
Three keystrokes. Not very efficient. Any better ideas?
Shortly after :help p
it says:
:[line]pu[t] [x] Put the text [from register x] after [line] (default
current line). This always works |linewise|, thus
this command can be used to put a yanked block as
new lines.
:[line]pu[t]! [x] Put the text [from register x] before [line]
(default current line).
Unfortunately it’s not shorter than your current solution unless you combined it with some keyboard as suggested in a different answer.
If you're copying a whole line then pasting a whole line, use Y
to yank the line or lines, including line break, in the first place, and p
to paste. You can also use V
, which is visual line mode, in contrast with plain v
for visual mode.
Options:
1) Use yy
to yank the whole line (including the end of line character). p
will then paste the line on a new line after the current one and P
(Shift-P) will paste above the current line.
2) Make a mapping: then it's only one or two keys:
:nmap ,p o<ESC>p
:nmap <F4> o<ESC>p
3) The function version of the mapping (unnecessary really, but just for completeness):
:nmap <F4> :call append(line('.'), @")<CR>
" This one may be a little better (strip the ending new-line before pasting)
:nmap <F4> :call append(line('.'), substitute(@", '\n$', '', ''))<CR>
:help let-register
:help :call
:help append()
:help line()
:help nmap
You can paste a buffer in insert mode using <C-R>
followed by the name of the buffer top paste. The default buffer is "
, so you would do
o<C-R>"
I found that I use <C-R>"
very often and bound that to <C-F>
in my vimrc:
inoremap <C-F> <C-R>"
If you want to do the same but with data from the clipboard ( "+p ). How do you accomplish that?
BRG Anders Olme