Your question looks like an almost duplicate of this question on SO: https://stackoverflow.com/questions/3170348/insert-empty-lines-without-entering-insert-mode/3171023 and of this one on SU: https://superuser.com/questions/147715/vim-insert-empty-line-above-current-line-not-open-i-e-without-entering-inser
I though it was also answered here, but I cannot find any trace of it.
Any way, append()
is the best way to insert line(s) without moving the cursor nor altering any thing but the current buffer. It's indeed cumbersome to use on the fly, but for scripting it's the right tool.
Which gives:
nnoremap µ :<c-u>call append('.', '')<cr>:call append(line('.')-1, '')<cr>
(Note that I don't see a solution that doesn't require to leave the NORMAL mode to enter the COMMAND mode. It respects the requirement of not entering the INSERT mode though)
Note that when there is no objective of writing a plugin with no side effect, and if the "no insert mode" is just a useless requirement imposed for no good reason, we usually sacrifice a mark (as in :h mark
) ->
mxO<esc>`xo<esc>`x
We can, of course, put this in a mapping, but it will alter the x
mark, which can be problematic if we use it to bookmark a position in the text/code we're editing. I use marks a lot when I'm editing texts, that's why I avoid them as much as possible in mappings. I don't want the mappings I use to mess with what I'm doing.