views:

78

answers:

3

I like to insert blank lines without entering insert mode and I used this keymapping:

nomap go o <esc>

This does create the blank line but introduces some weird behaviour. I have smart indent and autoindent set. The new line follows the indents but doesn't remove them even though doing so manually automatically removes the redundant whitespace. It also adds a single whitespace where the cursor is each time.

Anyone have any insights as to explain this behaviour?

+5  A: 

Vim is very literal with how you write your mapping commands - it's actually processing the space in your mapping before it does the <ESC>. In other words, your mapping does this:

nnoremap go o<SPACE><ESC>

You should change it to:

nnoremap go o<ESC>

And make sure you don't have any extra spaces in the mapping!

too much php
D'oh! I was looking at the wrong problem! I assumed that it was just a list of key mappings rather than literal user input. Thanks a lot!
ipwnponies
A: 

I agree with "too much php". This is the relevant section from my .vimrc

nnoremap <A-o> o<ESC>k
nnoremap <A-O> O<ESC>j

I think it's faster since you get the cursor back at the original line (Although not on the original character).

Mosh
Try this then: 'nnoremap <A-o> mto<ESC>`t'
too much php
A: 

As usual, the vim wiki has a useful tip: Quickly adding and deleting empty lines. The trick is to set paste before adding the new line and afterwards set nopaste. Additionally, this will set a mark to remember the cursor position and jump back to where you were.

nnoremap go :set paste<CR>m`o<Esc>``:set nopaste<CR>
nnoremap gO :set paste<CR>m`O<Esc>``:set nopaste<CR>
innaM