Skip to content

Instantly share code, notes, and snippets.

@Jeanhwea
Created April 26, 2017 03:29
Show Gist options
  • Select an option

  • Save Jeanhwea/515db94b1d3843a542c7f7504a2b25ec to your computer and use it in GitHub Desktop.

Select an option

Save Jeanhwea/515db94b1d3843a542c7f7504a2b25ec to your computer and use it in GitHub Desktop.
vim 新行自动添加括号
function! s:OpenSpecial(ochar,cchar)
echo "OpenSpecial"
let line = getline('.')
let col = col('.') - 2
if(line[col] != a:ochar)
if(col > 0)
return "\<ESC>a\<CR>"
else
return "\<CR>"
endif
endif
if(line[col+1] != a:cchar)
call setline('.',line[:(col)].a:cchar.line[(col+1):])
else
call setline('.',line[:(col)].line[(col+1):])
endif
return "\<Esc>a\<CR>;\<CR>".a:cchar."\<Esc>\"_xk$\"_xa"
endfunction
inoremap <silent> <CR> <C-R>=<SID>OpenSpecial('{','}')<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment