Saturday, May 19, 2018

vi - Inserting a blank line in vim?


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?


Answer



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


Basically, it boils down to this:


nnoremap  ] :put =repeat(nr2char(10),v:count)execute "'[-1"
nnoremap [ :put!=repeat(nr2char(10),v:count)execute "']+1"

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...