I recently surprised myself wanting to insert blank lines above or below the current line either in normal or insert mode.
I usually add blank lines to my code for better reading or to properly separate blocks of code.
To do this I am using the following in my .vimrc:
" Add empty line above and below the current line
nnoremap <silent> <C-K> mP:pu! _<cr>:']+1<cr>`P
inoremap <silent> <C-K> <esc>mP:pu! _<cr>:']+1<cr>`Pa
nnoremap <silent> <C-J> mP:pu _<cr>:'[-1<cr>`Pa
nnoremap <silent> <C-J> <esc>mP:pu _<cr>:'[-1<cr>`Pa
The only ugly thing with these mapping is I'm using the marker P just to go back to the previous cursor position. I tried to use `` instead but it doesn't do what I expected.
Perhaps there is a slightly better solution otherwise this snippet works quite well for me.
I am slowly adding new mapping in my .vimrc. I noticed the <C-[a-z]>
combinaisons are mostly free and the existing ones are pretty useless (i.e. <C-Q>
, <C-H>
, <C-M>
…). Then I decided to bind them to new useful mapping:
<C-N> New file
<C-S> Save (:update!)
<C-P> CtrlP mixed mode
<C-S-P> CtrlPCmdPalette
<C-B> CtrlP buffers mode
<C-D> <C-C>ciw
…