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?

John Winston
  • 656
  • 6
  • 15
  • 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 '21 at 08:36
  • Good find. I wouldn't have expected it to be such a popular Q (and have so many As). – B Layer Apr 23 '21 at 08: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 '21 at 09:01
  • Map normal mode enter to insert a blank line – minseong Apr 23 '21 at 23:22
  • Looking from a different perspective... If you didn't want to end up in Insert Mode because ESC is too far away, Ctrl+C is an alternative and more convenient way of returning to the Command mode. – raylight Apr 24 '21 at 06:51
  • 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 '21 at 15:12

2 Answers2

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). ;)

B Layer
  • 19,834
  • 2
  • 30
  • 57
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.

mattb
  • 1,111
  • 4
  • 15