2

Let say I have a simple line

hell<cursor>o

What is the fastest way to yank this line and paste to a result like this?

hello

hello

I am currently doing this:

yy # To yank this line
p # Paste on next line
O # To insert and add a line above the pasted line

But doing so I will end up in Insert Mode. How can I stay in normal mode for all this?

6
  • 3
    I think this might be a duplicate of How to insert a newline without leaving normal mode, or at least it is very related. This the mapping from this question you'd end up with Y<leader>op
    – statox
    Apr 23, 2021 at 8:36
  • Good find. I wouldn't have expected it to be such a popular Q (and have so many As).
    – B Layer
    Apr 23, 2021 at 8:46
  • 1
    Surprisingly, it doesn't look like my answer appears there. Closest I found is "you can yank yy an empty line and then pasted p for below cursor and P for above the cursor". I'm not sure whether that means Y2pD is kinda clever or sorta tacky. :D
    – B Layer
    Apr 23, 2021 at 9:01
  • Map normal mode enter to insert a blank line Apr 23, 2021 at 23:22
  • 1
    @raylight C-c is emphatically not equivalent to Escape; too many people think they are equivalent. Here's a simple demonstration of why not: launch vim -Nu NONE. Now see what the difference is between 5ii<esc> and 5ii<C-c>.
    – D. Ben Knoble
    Apr 26, 2021 at 15:12

2 Answers 2

5

Vim golf? :)

How about

Y2pD

It's perhaps a little contrived to create two new hello lines only to delete one but trying to avoid Insert mode is also a bit contrived when you're actually, you know, inserting new text (the blank line). ;)

3
  • 2
    What magic is this! Apr 23, 2021 at 9:05
  • 2
    This is terrific! (Although not actually any fewer keystrokes than YpO<Esc>)
    – Rich
    Apr 23, 2021 at 14:48
  • @Rich YpO<Esc> is good too! Apr 26, 2021 at 15:13
2

There is also the unimpaired plugin that give mappings in normal mode for putting in blank lines (among other [ and ] base mappings). I never would have thought I'd use them, but I do constantly - these in particular are burned into my fingers:

There are linewise mappings. [<Space> and ]<Space> add newlines before and after the cursor line. [e and ]e exchange the current line with the one above or below it.

So you could do:

Yp[<Space>

Also:

The . command works with all operator mappings, and will work with the > linewise mappings as well if you install repeat.vim.

Not the answer you're looking for? Browse other questions tagged or ask your own question.