Jarek
Jarek

Reputation: 7729

Inserting above/below X lines in Vim

I'm wondering ho to insert arbitrary number of lines below curent line wit "o" command. When i type for example 5o, first new line is inserted directly below, so i can write and when I hit esc then the line gets copied four times. Is there any way to directly insert 5 blank lines and after that start typing without the need of 5+o+esc?

Upvotes: 2

Views: 1220

Answers (2)

icecrime
icecrime

Reputation: 76745

I can't think of any way which does not involve a mapping or function :

:noremap <leader>o o<ESC>
:noremap <leader>O O<ESC>

With this, you can type 5\o to insert 5 blank lines.

Upvotes: 2

Peter Rincker
Peter Rincker

Reputation: 45097

My preferred way of doing things like this is to use the dot command.

o<esc> to create the initial blank line, then repeat the command with ..

The dot command can also take a count so 5. will repeat the last command 5 times.

You may also want to have a look at unimpaired.vim as it has the following mapping:

]<Space> - Add [count] blank lines below the cursor.

Since it is a mapping you can also provide a count. e.g. 5]<space>

unimpaired.vim also has many other convenient mappings. e.g. ]a for :next and ]b for :bnext`

Upvotes: 3

Related Questions