tags:

views:

140

answers:

1

Hi,

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?

+11  A: 

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.

jleedev
Thank you. That's what I wanted. If I want to enable my abbreviations I must do :set nopaste
Taurus Olson
One thing I like to do is bind a function key to toggle an option, like `map <F4> :set paste!^M`. (You have to type the ^M as <C-V><C-M>.)
jleedev
You can use <Cr> instead of typing ^M using ^V, this is more portable.You can also use the following mapping:map <F4> :set paste! paste?<Cr>so that after pressing F4 you'll see the new state of the option.
Paul
":set paste! paste?<CR>" That's a nice trick Paul, thanks for mentioning it!
There's actually a command specifically for setting the paste mode toggle key: `set pastetoggle=<F5>`. Of course, you can set it to whatever key you like.
Lucas Oman

related questions