Sometimes I want to add several empty lines for better visualization. Now I end up clicking o<Escape>
multiple times. I would love to reduce number of clicks by using something like 7o
instead, to get 7 empty lines without entering insert mode.
I've had these mappings in my dotfiles for years and they are so useful that I forgot that it's not a built-in feature:
" Quickly insert an empty new line without entering insert mode {{{
nnoremap <Leader>o o<Esc>0"_D
nnoremap <Leader>O O<Esc>0"_D
They are the equivalent of o
and O
but without entering insert mode. The deletion to the black hole register is quite useful for some corner cases ("_D
).
If you don't want to install a mapping you can add just these two lines to your vimrc.
Also out of curiosity here is how vim-unimpaired does it:
function! BlankUp(count) abort
put!=repeat(nr2char(10), a:count)
']+1
silent! call repeat#set("\<Plug>unimpairedBlankUp", a:count)
endfunction
function! BlankDown(count) abort
put =repeat(nr2char(10), a:count)
'[-1
silent! call repeat#set("\<Plug>unimpairedBlankDown", a:count)
endfunction
nnoremap <key> :call BlankUp(v:count1)<CR>
nnoremap <key> :call BlankDown(v:count1)<CR>
The difference is that my version puts your cursor on the newly created line whereas Pope's version adds the line but leave your cursor on the same place.
If installing a plugin is an option, Tpope's vim-unimpaired is a great pick which provides a mapping to insert empty lines:
]<space>
to insert a line under the current line[<space>
to insert a line above the current line
Both accept a count, so 42]<space>
will put 42 new lines under the current position.
7o<Esc>
does work to insert 7 empty lines, so... – filbranden♦ Feb 19 at 23:38o<CR><CR><CR>[..]
work as well? Why useo<Esc>
? – Martin Tournoij Feb 20 at 0:23o<Esc>...[..]
. Dot is cool. – Biggybi Feb 20 at 15:49