소스 검색

fix simplified mapping to handle braces

Daniel Sheffield 2 주 전
부모
커밋
aa6c09d0a5
1개의 변경된 파일6개의 추가작업 그리고 4개의 파일을 삭제
  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 ({})
 
 " }}}