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

No comments:

Post a Comment