Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In vi, I can use o or O to add a blank line and go into insertion mode. But what if I want to stay in command mode, is there a command for this?

In googling, I'm seeing suggestions to add stuff to my vimrc, but it seems like there should be an easier way (that will always work.)

share|improve this question

5 Answers 5

up vote 13 down vote accepted

According to the VIM FAQ you can use the :put command:

12.15. How do I insert a blank line above/below the current line without entering insert mode?

You can use the ":put" ex command to insert blank lines. For example, try

:put ='' :put! =''

For more information, read

:help :put

but then really it's easier to add:

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

to your .vimrc. This way you can press Enter or Shift-Enter in normal mode to insert a blank line below or above current line. Of course substitute <Enter> and <S-Enter> with your preferred keys.

share|improve this answer

Part of the allure of using VI is having a command mode for manipulating the text, and an edit mode for adding text. This keeps you from having to hit CTRL-whatever to accomplish things.

The other suggestions may work - I haven't tried them - but they seem to require quite a few characters or manipulating your VI environment too much.

Try using o[ESC] followed by a . for each new line you want to add, or 5. to add 5 lines. This is much faster, and will always work on any install of VI.

share|improve this answer
1  
You can use . to repeat,but you can also do <number>o<esc>,example: 5o<esc> –  bollovan Jul 11 '11 at 18:42
    
That would certainly work. But I like seeing how the command will actually impact the document before I have it do it multiple times. I can't tell you how many times I've o'd append a new paragraph in VI, only to find out that the pretty paragraph was actually six carefully broken/word-wrapped lines. –  Glorytoad Sep 6 '11 at 19:48

In vim, there's also :normal o or :normal O.

share|improve this answer

On Vim 7.3: <number>o<esc> creates only one empty line.

share|improve this answer
    
Well, by adding <esc> you go again from insert mode to command mode. I think he is looking for an answer that do not go to insert mode at all. –  Bernhard Apr 7 '13 at 19:40
    
Oh! I forget to quit insert mode with <esc>. In this case, it will work. It will even duplicate the line edited on all the following lines. –  Hakim Benoudjit Apr 9 '13 at 8:11

Both Tim Pope's unimpaired.vim - Pairs of handy bracket mappings and my own LineJuggler - Duplicate and move around lines plugin offer handy short ]<Space> mappings for this.

share|improve this answer

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.