How to avoid extra brackets from appearing while I

2019-04-28 14:00发布

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?

标签: vim mapping
1条回答
做个烂人
2楼-- · 2019-04-28 14:48

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.

查看更多
登录 后发表回答