Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert empty lines without entering insert mode

Tags:

vim

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?

like image 704
Jamey Pearce Avatar asked Jul 03 '10 04:07

Jamey Pearce


People also ask

How do I add a line without entering?

For most writing, this is not a problem until you want Word to not create a new paragraph. Thankfully, there is a keyboard shortcut that moves to the next line. Move the text cursor to where you want the new line to begin, press the Enter key, hold down the Shift key, and then press Enter again.

How do I insert a blank line in vi?

To insert a blank line below the current line use :put , or :put! to insert one above. To specify where to insert the blank line (nth line) use :[n]put .

How do you escape insert?

To exit from 'insert' mode, hit ESC (the escape key). If you want to force a quit (i.e. quit without saving) type: :q!


1 Answers

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

like image 111
Luc Hermitte Avatar answered Nov 06 '22 02:11

Luc Hermitte