Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to safely paste text into Vim in terminal mode

📅 2013-Jan-21 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ paste, terminal, vim ⬩ 📚 Archive

When Vim is running in terminal mode (at the console) and you paste text (say source code) into it, the pasted text might get crazily indented.

This happens because Vim in terminal mode cannot distinguish between typed text and pasted text. Vim thinks that you had typed in that pasted text and it adds in its automatic indentations to that text. Since that text already has all the necessary indentation, the extra indentation makes it looks crazy.

One way to safely paste text into terminal Vim is to temporarily switch it to paste mode, then paste in the text and then toggle it back to nopaste mode.

You can switch it to paste mode by typing :set paste. You can switch it back by typing :set nopaste

These tricks are not needed for GVim since it can distinguish that the pasted text is coming from outside the application.

Tried with: Vim 7.3


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧