Native paste / bracketed paste is the best and simplest way since vim 8
(released in 2016). It even works over ssh! (Bracketed paste works on Linux and Mac, but not Windows Git Bash)
Make sure you have vim 8+ (you don't need the +clipboard
or +xterm_clipboard
options).
vim --version | head -1
Simply use the OS native paste command (e.g. ctrl+shift+V
or cmd+V
) in Normal Mode. Do not press i
for Insert Mode.
Test
Copy (ctrl+shift+C
or cmd+C
) the output of this (2 lines with a tab indent) to the system clipboard:
echo -e '\ta\n\tb'
Launch a clean vim 8+ with autoindent:
vim -u NONE --noplugin -c 'set autoindent'
Paste from the system clipboard (ctrl+shift+V
or cmd+V
) in Normal Mode. Do not press i
for Insert Mode. The a
and b
should be aligned with a single tab indent. You can even do this while ssh-ing to a remote machine (the remote machine will need vim 8+).
Now try the old way, which will autoindent the second line with an extra tab: Press i
for Insert Mode. Then paste using ctrl+shift+V
or cmd+V
. The a
and b
are misaligned now.
Installing Vim 8
Ubuntu 18.04 - comes with Vim 8 by default.
Ubuntu 16.04 - install from a PPA.
sudo add-apt-repository ppa:jonathonf/vim
sudo apt update
sudo apt install vim
brew install vim