1

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.

niekas
  • 1,575
  • 4
  • 17
  • 25

2 Answers2

4

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.

Biggybi
  • 2,740
  • 9
  • 29
4

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("&lt;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.

statox
  • 49,782
  • 19
  • 148
  • 225