Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugin/AutoPair.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ inoremap { {}<C-G>U<Left>
inoremap <silent> ) <C-\><C-O>:call AutoPair#Close(')')<CR>
inoremap <silent> ] <C-\><C-O>:call AutoPair#Close(']')<CR>
inoremap <silent> } <C-\><C-O>:call AutoPair#Close('}')<CR>
inoremap <silent> " <C-\><C-O>:call AutoPair#Quote('"')<CR>
inoremap <silent> ' <C-\><C-O>:call AutoPair#Quote("'")<CR>
inoremap <silent> ` <C-\><C-O>:call AutoPair#Quote('`')<CR>
"}}}

" New line between brace pair {{{
" Must not use <Esc> here, since it changes the value of "@.".
inoremap <silent> <CR> <C-\><C-O>:call AutoPair#InsertBlankLine(@.)<CR><CR>
"}}}

fun! AutoPair#Quote(mapChar)
let l:nextChar = strpart(getline('.'), col('.') - 1, 1)
let l:prevChar = strpart(getline('.'), col('.') - 2, 1)
let l:feedkeys = (l:nextChar ==# a:mapChar || l:prevChar ==# a:mapChar) ? a:mapChar : a:mapChar . a:mapChar . "\<left>"
call feedkeys(l:feedkeys, 'n')
endf

function! AutoPair#Close(mapChar) "{{{

let l:nextChar = strpart(getline('.'), col('.') - 1, 1)
Expand Down