Plugin for maintainging correct indent when pasting.
Paste-indent is a simple plgin that makes indentation simple when pasting with vim. Take this block of C code for example with the cursor at '|':
int main(int argc, char **argv) {
if (argc == 2) {
}
|printf("%s\n", argv[1]);
return 0;
}
Input: ddkP
Without paste-indent:
int main(int argc, char **argv) {
if (argc > 1) {
printf("%s\n", argv[1]);
}
return 0;
}
With paste-indent:
int main (int argc, char **argv) {
if (argc > 1) {
printf("%s\n", argv[1]);
}
return 0;
}
This works for any number of lines, can take a range, uses the correct registers, and even works for nested code.
It's smart too! When making characterwise pastes (without newlines), paste-indent knows not to indent unless pasting on an empty line.
Copy plugin/paste-indent.vim to ~/vim/plugin
If you prefer to use pathogen, just run the following commands:
cd ~/.vim
git clone https://github.com/ForTheReallys/paste-indent.git
bundle/paste-indent
Do nothing on startup
The character to paste after the cursor
Default: 'p'
The character to paste before the cursor
Default: 'P'
Map the the appropriate paste keys to indent after pasting
Turn off indent after pasting