Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

is there a way of inserting a new line above the current, without opening the line (so without entering Insert mode)? That is, like "O", but without opening.

share|improve this question
2  
What does "opening a line" mean? –  Matteo Riva Jun 1 '10 at 18:41
    
"opening a line" means going form normal mode to insert mode, which is what happens when you press "O" (oh). –  tmadsen Jun 1 '10 at 19:14

5 Answers 5

up vote 2 down vote accepted

I use Tim Pope's plugin unimpared which has a command specifically for this purpose:

[<space>

And if you want to add a space after the line you are on:

]<space>

share|improve this answer

The definition of your request is O.

Logically when inserting a new line above would be O.

To insert before the curser: i
After: a
Before the line (home): I
Append at the end of line: A

The closest I think you'll come is I which will put the cursor at the beginning of the line.

share|improve this answer
    
Maybe I wasn't clear. The scenario is this: I'm in normal mode and want to insert a blank line above the one I'm currently on, while staying in normal mode. Pressing "O" puts me in insert mode. Maybe there's no way to do it and that's ok, just thought I would ask :) –  tmadsen Jun 1 '10 at 19:16
2  
Just map it, m`O+Esc` –  Josh K Jun 1 '10 at 19:33
    
Good idea, hadn't considered that. Did a :noremap <leader>O O<ESC> –  tmadsen Jun 1 '10 at 20:05
    
2tmadsen: You can map this <yourkey> O<ESC> –  nXqd Jun 2 '10 at 4:01

You can map whatever key or key sequence you like to

m`O<ESC>``

this inserts a blank line above the current one keeping you in normal mode and without changing cursor position.

share|improve this answer
    
so the command to map this to Alt-O would be :map <M-o> m`O<ESC>`` –  K Robinson Jun 3 '10 at 16:47
    
That's correct. –  Matteo Riva Jun 3 '10 at 19:05
:nmap <CR>_i<CR><ESC>
share|improve this answer
:h append()

It won't move the cursor, it will let you insert as many lines (empty or not) as you wish, and it won't modify the previous position mark.

call append(line('.')-1, '')
share|improve this answer
    
yah, that is +1 neat! /me changes his vimrc –  akira Jun 2 '10 at 6:52
    
Well, it got a few advantages when it comes to scripting. It's bit overkill to type otherwise. –  Luc Hermitte Jun 2 '10 at 7:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.