tags:

views:

661

answers:

5

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?

+3  A: 

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.

Bombe
I know that, and I use it, but it's not what I'm asking, because sometimes what you're copying just doesn't have any LF in it. If there was a "paste into a new line" command, it would work regardless of the content you're about to paste, so you wouldn't have to think about it.
static_rtti
Okay, `:pu[t]` will put the text in a new line after the current line, `:pu[t]!` will put the text in a new line before the current line. I will edit my answer accordingly. (Hooray for `:help p`.)
Bombe
Not really better than my current solution, but I think it's the best answer to my question.
static_rtti
A: 

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.

Peter
The problem is, sometimes you simply don't want to copy a whole line... I'd like a solution that works whether I've copied ten lines or two words.
static_rtti
+6  A: 

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
Al
Well, I guess I'll make a mapping. I was just hoping there might be a standard solution :-/Thanks for your answer!
static_rtti
+5  A: 

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>"
soulmerge
Thanks, that's a useful tip.
static_rtti
A: 

If you want to do the same but with data from the clipboard ( "+p ). How do you accomplish that?

BRG Anders Olme

Buzzzz