On Tue, 28 Nov 2006, Ronald wrote:
> But here is a problem, when I want to enter something like:
>
> (test)
>
> I will enter the parentheses first
Try putting this in your vimrc:
function! s:ParenBack(type)
if getline('.')[col('.')-3] == a:type
return "\<Left>"
endif
return ""
endfunction
inoremap ) )<C-R>=<SID>ParenBack('(')<CR>
inoremap ] ]<C-R>=<SID>ParenBack('[')<CR>
inoremap } }<C-R>=<SID>ParenBack('{')<CR>
Basically, this jumps your cursor left one character if you type a
closing parenthesis/bracket and there's nothing between it the
matching bracket, otherwise it leaves your cursor position alone.
There are other auto-bracketing scripts on <www.vim.org> but I don't
use any of them so I can't recommend one.
You could add a mapping for > as well:
inoremap > ><C-R>=<SID>ParenBack('<')<CR>
- Christian
--
Life is like a diaper -- short and loaded.
Christian J. Robinson <[EMAIL PROTECTED]> http://infynity.spodzone.com/
PGP keys: 0x893B0EAF / 0xFB698360 http://infynity.spodzone.com/pgp