02.28.08
Vim staircase effect
If you are terminal vim users, I’m sure you have tried to copy/paste text into a file and thought “Wtf, this is pretty damn wrong” seeing something like this:
void randomize (void) { struct timeval *tv = malloc (sizeof (struct timeval)); struct timezone *tz = (struct timezone *) malloc (sizeof (struct timezone)); gettimeofday (tv, tz); srand (tv->tv_usec); free (tv); free (tz); }
That’s called vi staircase effect.
The solution is to type:
:set pastebefore pasting and
:set nopasteafter finishing.
Alternatively, just add to your ~/.vimrc:
nnoremap <silent> <F12> :set paste!<CR>
to press F12 for toggling between paste and nopaste conditions.