I have update my vimrc like below, I think it can handle some case, any one has some good suggestion about this?
function! SmartPairs(open, close)
exec 'inoremap ' . a:open . ' ' a:open . a:close . repeat('<left>', len(a:close))
exec 'inoremap ' . a:open . '<space> ' a:open . '<space><space>' . a:close . repeat('<left>', len(a:close) + 1)
exec 'inoremap ' . a:open . '<cr> ' a:open . '<cr>' . a:close . '<esc>O'
exec 'inoremap ' . a:open . a:close . ' ' . a:open . a:close
endf
call SmartPairs('"', '"')
call SmartPairs("'", "'")
call SmartPairs('(', ')')
call SmartPairs('{', '}')
call SmartPairs('[', ']')
call SmartPairs('/*', '*/')
call SmartPairs('/**', '*/')
inoremap /*<CR> /*<CR>/<ESC>O
inoremap /**<CR> /**<CR>/<ESC>O
2011/11/12 jason.桂林 <guileen@gmail.com>
thanks Ben Fritz, good article, teach me a lot, but I still has some question.function! ConditionalPairMap(open, close)let line = getline('.')let col = col('.')if col < col('$') || stridx(line, a:close, col + 1) != -1return a:openelsereturn a:open . a:close . repeat("\<left>", len(a:close))endifendfinoremap <expr> ( ConditionalPairMap('(', ')')inoremap <expr> { ConditionalPairMap('{', '}')inoremap <expr> [ ConditionalPairMap('[', ']')inoremap <expr> /* ConditionalPairMap('/*', '*/')inoremap <expr> /*<space> ConditionalPairMap('/*<space>', '*/<space>')inoremap <expr> ' ConditionalPairMap("'", "'")inoremap <expr> " ConditionalPairMap('\"', '\"')autocmd FileType javascript inoremap , ,<SPACE>autocmd FileType javascript inoremap : <SPACE>:<SPACE>1. not works if insert ( [ { in the center of a line, only works at the end of the line,2. Can I use inoremap in function too? I want add this in functioninoremap <expr> ) strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : ")"3, how can I get some API of strpart, get line, col, all of this internal functions?4, Where I can get the syntax of vim script, like string operation, ! # symbols meansThanks a lot
Ben Fritz <fritzophrenic@gmail.com>Have a look here, it will get you started and/or walk you through
On Nov 11, 8:36 am, Jason <guil...@gmail.com> wrote:
> I just need a very simple plugin, I want do it myself, when I press
> {<enter> , it become
>
> below `I` means cursor
>
> {
> I
>
> }
>
> if I press ({<enter> it goes to
>
> ({
> I
>
> })
>
> |( => (|)
> |{ => {|}
>
> I don't want to know every thing about plugin development, but I want
> to know the most useful things about write a plugins.
creating such mappings:
http://vim.wikia.com/wiki/Automatically_append_closing_characters
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
--
Best regards,
Jason Green
桂林
Best regards,
Jason Green
桂林
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment