Vim Tip #25: Paste and Correct Indentation


tags: Vim

Vim Tips

If Vim's copy-paste system is new to you, review Vim Tip #4: Basic yank, delete, paste, and move before trying this.

Vim's yank-or-delete and then paste (p or P) system works pretty well. But if you're a programmer, it can be frustrating to paste a block of code and have it at the wrong indentation level: it's inevitably indented (or "outdented") from where you need it to be, and then you have to change the block's indentation and it just takes a while. But it turns out this is incredibly easy to fix with a single keystroke (why haven't I known this for the past 20 years of using Vim?). Use ]P or ]p to paste before or after the current line ... with indentation corrected.