Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I quite often find I have a need to insert a blank line either below or above the current line when editing in vim. o and O will do this, but they subsequently switch into insert mode, which is annoying. Is there any built-in command to do this which will remain in normal mode?

share|improve this question
add comment

4 Answers 4

up vote 13 down vote accepted

I've been using these

map <Enter> o<ESC>
map <S-Enter> O<ESC>

in my .vimrc for years.

Press Enter to insert a blank line below current, Shift + Enter to insert it above.

share|improve this answer
    
I am marking this correct as it's the simplest solution, although all these answers are good. –  Andrew Ferrier Jun 19 '13 at 13:07
add comment

Both Tim Pope's unimpaired plugin as well as my own LineJuggler plugin provide [<Space> and ]<Space> mappings to add [count] blank lines above / below the current line.

Basically, it boils down to this:

nnoremap <silent> ]<Space> :<C-u>put =repeat(nr2char(10),v:count)<Bar>execute "'[-1"<CR>
nnoremap <silent> [<Space> :<C-u>put!=repeat(nr2char(10),v:count)<Bar>execute "']+1"<CR>
share|improve this answer
add comment

Yet another way to insert lines above or below:

nnoremap <Enter> :call append(line('.'), '')<CR>
nnoremap <S-Enter> :call append(line('.')-1, '')<CR>

Note that the solution from romainl and Mr Shunz will move the cursor to the newly inserted line, whereas this and also the one from Ingo Karkat will keep the cursor at the same spot.

share|improve this answer
add comment

No, there's no built-in command for that.

These mappings do what you want:

nnoremap <leader>o o<Esc>
nnoremap <leader>O O<Esc>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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