Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid extra brackets from appearing while I paste into Vim

Tags:

vim

mapping

I use some maps while I code :

imap ( ()<C-[>i
imap [ []<C-[>i
imap { {}<C-[>i

so that when I put "(" , it writes "()" (same thing for "[" and "{" ). The problem is that when i paste something into Vim :

for (i = 0; i < count; i++) {
tab[i] = something()
}  

I get

for (i = 0; i < count; i++) {
tab[i] = something()
}  
)]})

Is it possible to avoid the extra brackets?

like image 270
Taurus Olson Avatar asked Mar 20 '09 23:03

Taurus Olson


1 Answers

You want the 'paste' option; set it with :set paste. It disables insert mode mappings, abbreviations, and other autoformatting options.

The other thing is that there are multiple ways to paste:

  • "+p
  • :set mouse=a and then middle-click
  • insert mode, <C-R>+
  • :a! and then use your terminal's paste command

All of these will correctly paste. The only one that confuses vim is when you use your terminal's "paste" command without first warning it.

like image 79
Josh Lee Avatar answered Sep 28 '22 07:09

Josh Lee