Vim automatically set paste mode
Vim automatically tires to indent pasted text when running inside a terminal. To avoid this ‘paste’ mode can be set and unset before and after the paste operation, by the following commands:
Toggle key
To speed up this process it is possible to specify a key sequence that toggles the ‘paste’ mode.
Now you hit F2 key to toggle the paste before and after pasting.
Automatically detect paste
Here’s a little trick from Coderwall, that uses terminal’s bracketed paste mode to automatically set/unset Vim’s ‘paste’ mode. The following lines should be added to .vimrc:
Under tmux
If Vim is inside of a Tmux session then double escape is required. The above config for Tmux users looks like this: