tags:

views:

176

answers:

5

How can I print a blank line at some line with one pressing while not in the insert mode?And after that I should still be in normal mode.

+1  A: 

Try this: o - open line

Bozhidar Batsov
+2  A: 

Press: O or Shift-O

Yaroslav
Better use lowercase "o" since it's confusing this way
Bozhidar Batsov
+2  A: 

To add a blank line after the current line: o (small o) and Escape. To insert a blank line before the current line O (capital O) and Escape. You can skip the Escape if you want to stay in insert mode.

hlovdal
+4  A: 

In vanilla vim it is o<ESC>. It is 2 keys to press.

You can also add the following in your .vimrc:

noremap <CR> o<ESC>

to speed up blank line creation with just one single Enter :).

Maxim Kim
That's nice.Thanks!
SpawnCxy
+1  A: 

Even though o<ESC> is just two keypresses, it moves the cursor and adds the creation of new line to change history which might not be desired. That is, the command . will afterwards repeat creating the new line.

1) unimpaired.vim

There's a plugin, unimpaired.vim, that has a mapping for creating new lines before or after the cursor without changing the change history, and it doesn't move the cursor to the new line. The cursor will also remain in its current column if nostartofline is set. Using unimpaired.vim, create a new line after the cursor:

]<Space>

or before the cursor:

[<Space>

http://www.vim.org/scripts/script.php?script_id=1590

It also accepts a count, so to create 3 new lines after the cursor you can use:

3]<Space>

2) Mapping

You can also just make a mapping of your own to create a new line, for example to map \] (or whatever your leader key is) to add a line after your cursor:

:nnoremap <Leader>] :put!=repeat(nr2char(10),v:count)<Bar>']+1<Cr>

This is how unimpaired.vim creates the new lines. In order to make a similar mapping to create the new line before the cursor, just change the +1 to -1

Heikki Naski