Browse Source

fix simplified mapping to handle braces

Daniel Sheffield 2 weeks ago
parent
commit
aa6c09d0a5
1 changed files with 6 additions and 4 deletions
  1. 6 4
      vim/vimfiles/vimrc

+ 6 - 4
vim/vimfiles/vimrc

@@ -104,13 +104,15 @@ nnoremap gtt V:s/\v<(.)(\w*)/\u\1\L\2/g<CR>:noh<CR>
 
 function! SelectionSurroundWith()
     " Surround selected text with a single char
-    let l = nr2char(getchar())
-    execute "normal! c" . l . "\<C-r>\"" . l . "\<Esc>"
+    let open = nr2char(getchar())
+    let pairs = {'(': ')', '[': ']', '{': '}', '<': '>'}
+    let close = get(pairs, open, open)
+    execute "normal! gvc" . open . "\<C-r>\"" . close . "\<Esc>"
 endfunction
-vnoremap gi :call SelectionSurroundWith()<CR>
+vnoremap gi :<C-u>call SelectionSurroundWith()<CR>
 "
 " (visual) gi" := surround selection with quotes (")
-" (visual) gi{ := surround selection with braces (")
+" (visual) gi{ := surround selection with braces ({})
 
 " }}}