Auto Closing Parentheses
I wanted to make typing parentheses easier for calculation and function calls, but not when changing existing code. So with the following mappings you can type '(' and it will act normally if in between text but when there is nothing in front of the '(' it wil print '()' and put the cursor in between the parentheses. Then you can type the arguments, change them and finish with enter, which will put the cursor behind the last ')'.
" If from current cursor pos to end of line contains only spaces or is at the end of the line, then start inBracketMode
ino <expr> ( match(strpart(getline('.'), getpos(".")[2]-1, strlen(getline('.'))), '^\s*$')==0 ? '()<Esc>:let inBracketMode=1<CR>i' : '('
ino <expr> <CR> (exists('g:inBracketMode') && g:inBracketMode!=0 ? '<Esc>:let inBracketMode=0<CR>:startinsert!<CR>' : '<CR>')
ino <silent> <C-c> <C-c>:let g:inBracketMode=0<CR>
ino <silent> <Esc> <Esc>:let g:inBracketMode=0<CR>
set showmatch can be sped up with set matchtime=1
Modified from: Vim Wikia Making Parentheses And Brackets Handling Easier: http://vim.wikia.com/wiki/Making_Parenthesis_And_Brackets_Handling_Easier
Bracket handling plugins:
Surround: quoting/parenthesizing made simple https://github.com/tpope/vim-surround
Vim LH Brackets: https://github.com/LucHermitte/lh-brackets
--Ivovk (talk) 22:49, May 27, 2017 (UTC)