On Feb 4, 9:41 am, Ben Fritz <[email protected]> wrote:
>
> I'm thinking it may be possible to map { to insert the opening and
> closing brace in one fell swoop using the expression register, but I
> haven't tried it yet.
>

I already had some bracket-matching code already in my .vimrc, based
off:

http://vim.wikia.com/wiki/Automatically_append_closing_characters

I've modified it to also protect the folds below the insertion point.
Not very pretty, but here it is:

" autocomplete '{}' groups
---------------------------------------------
" this will usually take effect, you must press '{{' to prevent it
inoremap <silent>   {          x<Esc>"="{}"<CR>Pl"_s<Left>
inoremap <silent>   {<CR>      <ESC>"="{\n}"<CR>p=aBo
inoremap <silent>   {<SPACE>
x<Esc>"="{<SPACE><SPACE>}"<CR>Pl"_s<Left><Left>
inoremap <silent>   {}         x<Esc>"="{}"<CR>Pl"_s
inoremap <silent>   {{         {
if v:version >= 700
  inoremap <expr>   } strpart(getline('.'), col('.')-1, 1) == "}" ?
"\<Right>" : "}"
else
  inoremap <silent> } <C-R>=strpart(getline('.'), col('.')-1, 1) ==
"}" ? "\<lt>Right>" : "}"<CR>
endif

And similar for () and [] pairs.

Works around the issue for me, anyway. Can anyone get Matt's suggested
solution working in 7.2.356 instead? It's quite a bit more elegant.

-- 
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to