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.)


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.

| 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.

| 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
  • 1
    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.

| improve this answer | |

This will add a blank line after the current line:

:put _ 

Alternatively, specify a line at the start.

| improve this answer | |

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

| 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 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.

| improve this answer | |

To insert a blank line after the current line while staying in command mode, use:

: r !echo

This is the "read in a file" command, but instead of giving it a filename, we tell it to read the output of a shell command (!); that shell command, echo, simply prints a blank line. After the blank line is inserted, you remain in command mode.

| improve this answer | |

I'm surprised no one else mentioned this:

Use 'r' followed by 'Enter key' in command line mode.

Late to the the party by 7 years though :)

| improve this answer | |
  • 1
    Except that this takes you out of command mode and replaces the current line with a blank one. – Jeff Schaller May 17 '18 at 20:41
  • I’m not sure what @Jeff is saying.   My observations regarding this command are (1) it doesn’t work if you’re currently on a blank line, and (2) otherwise, it deletes the character under the cursor. – Scott May 17 '18 at 21:53
  • I misspoke; r indeed replaces the current character. Still takes you into command mode. – Jeff Schaller May 17 '18 at 22:30
  • Agreed. This is a limitation: It has to be done on a non-empty line + on a blank space before the line. Did not think of this. Thanks. – Akhilesh Siddhanti May 19 '18 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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