我的Vim配置

带括号补齐

 1 syntax on
 2 filetype plugin on
 3 let filetype_m='objc'
 4 set nocompatible
 5 set encoding=utf-8
 6 set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
 7 set history=400
 8 set autoread
 9 set nu
10 set ai
11 set cindent
12 set cmdheight=2
13 set backspace=eol,start,indent
14 set ignorecase smartcase
15 set incsearch
16 set magic
17 set hlsearch
18 set laststatus=2
19 set tabstop=4
20 set shiftwidth=4
21 
22 "Format the statusline
23 set statusline=%F%m%r%h%w/[FORMAT=%{&ff}]/[TYPE=%Y]/[ASCII=%03.3b]/[HEX=/%02.2B]/[POS=%04l,%04v][%p%%]/[LEN=%L]
24 
25 "Map auto complete of (, ", ', [, {
26 :inoremap <S-ENTER> <c-r>=SkipPair()<CR>
27 :inoremap <S-SPACE> <ESC>la
28 :inoremap <C-ENTER> <ESC>A;<CR>
29 :inoremap ( ()<ESC>i
30 :inoremap ) <c-r>=ClosePair(')')<CR>
31 :inoremap { <c-r>=ClsoeBrace()<CR>
32 :inoremap } <c-r>=ClosePair('}')<CR>
33 :inoremap [ []<ESC>i
34 :inoremap ] <c-r>=ClosePair(']')<CR>
35 ":inoremap < <><ESC>i
36 ":inoremap > <c-r>=ClosePair('>')<CR>
37 :inoremap ;; <ESC>A;<CR>
38 
39 function ClosePair(char)
40     if getline('.')[col('.') - 1] == a:char
41         return "\<Right>"
42     else
43         return a:char
44     endif
45 endf
46 function Semicolon()
47 "echo getline('.')[col('.')]
48     if getline('.')[col('.')] == ')'
49         return "<ESC>A;"
50     elseif getline('.')[col('.')] == '}'
51         return "\<ESC>A;"
52     elseif getline('.')[col('.')] == ']'
53         return "\<ESC>A;"
54     else
55         return ";"
56     endif
57 endf
58 function SkipPair()
59     if getline('.')[col('.') - 1] == ')'
60         return "\<ESC>o"
61     else
62         normal j
63         let curline = line('.')
64         let nxtline = curline
65         while curline == nxtline
66             if getline('.')[col('.') - 1] == '}'
67                 normal j
68                 let nxtline = nxtline + 1
69                 let curline = line('.')
70                 continue
71             else
72                 return "\<ESC>i"
73             endif
74         endwhile
75         return "\<ESC>o"
76     endif
77 endf
78 function ClsoeBrace()
79     if getline('.')[col('.') - 2] == '='
80         return "{}\<ESC>i"
81     elseif getline('.')[col('.') - 3] == '='
82         return "{}\<ESC>i"
83     elseif getline('.')[col('.') - 1] == '{'
84         return "{}\<ESC>i"
85     elseif getline('.')[col('.') - 2] == '{'
86         return "{}\<ESC>i"
87     elseif getline('.')[col('.') - 2] == ','
88         return "{}\<ESC>i"
89     elseif getline('.')[col('.') - 3] == ','
90         return "{}\<ESC>i"
91     else
92         return "{\<ENTER>}\<ESC>O"
93     endif
94 endf
posted @ 2012-05-07 15:41  Jojodru  阅读(281)  评论(0编辑  收藏  举报