Removing Staircase Effect in Vim

Name one of the repetitive manual work in your life right now?
I always have to toggle between paste and nopaste mode in vim to prevent misaligned source code indentation. This is also known as staircase effect.

Staircase effect? Tell me more about it.
Vim will assume all paste text is typed to the editor rather than paste. If autoindent is on, the editor will reindent the whole text again as illustrated by below screenshot.

Ok. How you going to reduce the manual typing?
Configure vim to use keyboard shortcut to reduce typing as described by this vim tip. In your .vimrc file, add these options.

" switch between paste and no paste mode fast and go into insert mode
" after that
let mapleader = ","
nnoremap p :set invpaste paste?i
set pastetoggle=p
set showmode

What the improvement?
Number of key press to copy and paste
Without keyboard shortcut : 21
With shortcut : 4

About

Disclaimer

Opinions expressed here are my own and do not represent the views of my current or past employers.

All content provided in this blog is for informational purposes only. I cannot guarantee the accuracy or completeness of all information supplied here or found by following any link on this site and will accept no liability for any loss or damage incurred.