vim 중괄호의 자동 완성
다음 코드를 에 붙여넣습니다.vimrc 파일:
function! AutoPair(open, close)
let line = getline('.')
if col('.') > strlen(line) || line[col('.') - 1] == ' '
return a:open.a:close."\<ESC>i"
else
return a:open
endif
endf
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
function! SamePair(char)
let line = getline('.')
if col('.') > strlen(line) || line[col('.') - 1] == ' '
return a:char.a:char."\<ESC>i"
elseif line[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
inoremap ( <c-r>=AutoPair('(', ')')<CR>
inoremap ) <c-r>=ClosePair(')')<CR>
inoremap { <c-r>=AutoPair('{', '}')<CR>
inoremap } <c-r>=ClosePair('}')<CR>
inoremap [ <c-r>=AutoPair('[', ']')<CR>
inoremap ] <c-r>=ClosePair(']')<CR>
inoremap " <c-r>=SamePair('"')<CR>
inoremap ' <c-r>=SamePair("'")<CR>
inoremap ` <c-r>=SamePair('`')<CR>