I would like to create a mapping that will add N lines below the cursor and return the cursor to where it started. For example, to add ten lines I would do:


How could I create mapping for this so that I could type in something like 18T and it would insert those 18 blank lines. Something like:

nnoremap 0<esc>Number??k

I was thinking to do something like this:

function InsertBlankLines()
    execute "normal! o\<esc>k"

But it keeps 'sliding down'

nnoremap ]<space> o<esc>'[k

BTW. A similar mapping is defined in tpope/vim-unimpaired plugin, alhough I haven't looked if the implementation the same or different.

  • that's pretty neat, thank you. Could you explain how it works a bit? For example, how does '[ (start of yanked text) go back to the second line (if we say the first line is where we start) ?
    – David542
    Jun 15 '20 at 6:21
  • @David542 It's the start of "changed text", that is the first added blank line.
    – Matt
    Jun 15 '20 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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