tags:

views:

89

answers:

2

I often find myself bouncing on o or O and ctrl{ to insert blank lines and get back out of insert mode.

Thinking there must be a simpler way, and hoping to retain my cursor position, I hacked together these sloppy macros:

map <Leader>O :let cursorpos = getpos(".")<CR>:i<CR><CR>.<CR>:let cursorpos[1] = cursorpos[1] + 1<CR>:call setpos('.', cursorpos)<CR>
map <Leader>o :let cursorpos = getpos(".")<CR>:a<CR><CR>.<CR>:call setpos('.', cursorpos)<CR>

However, this doesn't allow for ranges. It would be nice to be able to go 5\O and get 5 blanks above my current line.

Any suggestions on how I can fix this to allow ranges and still return to the original cursor position when done?

+2  A: 

You can use :call append(linenumber, repeat([''], 5)). It won't move the cursor.

Luc Hermitte
Excellent, that's perfect. I figured there had to be some more elegant way.Switched it up to: map <Leader>O :<C-U>call append(line(".") -1, repeat([''], v:count1))<CR> map <Leader>o :<C-U>call append(line("."), repeat([''], v:count1))<CR>to respond to ranges. Thanks!
JameyC
+1  A: 

The unimpaired plugin adds mappings that do what you want. You can insert a blank line above the cursor with [<space>, or below the cursor with ]<space>. Both of these mappings can be prepended with a count.

nelstrom