Created
May 9, 2019 16:15
-
-
Save jams2/b3eadf8e3c338ee14f35866aacfab7f0 to your computer and use it in GitHub Desktop.
Revisions
-
jams2 created this gist
May 9, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ """""""""""""""""""""""""""""""""""""""""" " Change matching pair of parens nnoremap <leader>cp :call CycleParens()<CR> function! CycleParens() abort let parens = ['[', '{', '(', ']', '}', ')'] call CyclePairs(parens) endfunction function! CyclePairs(pairs) abort let cycleLen = len(a:pairs) let halfCycle = cycleLen / 2 let currentChar = strcharpart(getline('.')[col('.') - 1:], 0, 1) let charIndex = index(a:pairs, currentChar) if charIndex == -1 | return | endif if charIndex + 1 == cycleLen || charIndex + 1 == halfCycle let nextChar = charIndex + 1 - halfCycle else let nextChar = charIndex + 1 endif execute 'normal! %r' . a:pairs[(nextChar + halfCycle) % cycleLen] . \ '``r' . a:pairs[nextChar] endfunction