Question

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?

Was it helpful?

Solution

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!

OTHER TIPS

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).

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top