Vim's quirks in key layout

I like to insert blank lines without entering insert mode, and I used this keyboard shortcut:

nomap go o <esc>

      

This creates an empty string, but introduces some strange behavior. I have smart indentation and autoindent set. The newline follows the indentation, but does not remove it, although it does manually automatically remove the excess space. It also adds a single space where the cursor is each time.

Anyone have any ideas to explain this behavior?

+2


source to share


3 answers


Vim is very literal in how you write your display commands - it actually handles space in your mapping before it is . In other words, your mapping does the following: <ESC>

nnoremap go o<SPACE><ESC>

      

You have to change it to:



nnoremap go o<ESC>

      

And make sure you don't have any extra display spaces!

+5


source


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 this is faster, since you are returning the cursor on the original line (although not on the original character).

0


source


As usual, the vim wiki has a handy tip: Quickly add and remove blank lines . Focus in set paste

before adding a new line and then set nopaste

. Also, this will set a mark to remember the cursor position and go 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>

      

0


source







All Articles