Forráskód Böngészése

simplify my mappings to quote and bracket things

Daniel Sheffield 2 hete
szülő
commit
1f19bd5ace
1 módosított fájl, 11 hozzáadás és 16 törlés
  1. 11 16
      vim/vimfiles/vimrc

+ 11 - 16
vim/vimfiles/vimrc

@@ -69,33 +69,28 @@ scriptencoding utf-8
 
 " Copy Pasta {{{
 function! RegisterSwapDefaultWith()
+    " Swap the default register with the contents of another
     let l = nr2char(getchar())
     execute 'let @x=@' . l . '| let @' . l . '=@" | let @"=@x'
 endfunction
 nnoremap <Leader>c :call RegisterSwapDefaultWith()<CR>
-nnoremap <Leader>C :let @x=@+ \| let @+=@" \| let @"=@x<CR>
+" Swap the default register with the contents of the clipboard
+nnoremap <Leader>C :call RegisterSwapDefaultWith()<CR>+
 " }}}
 
-" Formatting {{{
 
 " Title Case
 vnoremap gt :s/\%V\v<(.)(\w*)/\u\1\L\2/g<CR>:noh<CR>
 nnoremap gT V:s/\v<(.)(\w*)/\u\1\L\2/g<CR>:noh<CR>
 
-" Quote selection
-vnoremap gi" c"<C-r>""<Esc>
-vnoremap gi' c'<C-r>"'<Esc>
-vnoremap gi` c`<C-r>"`<Esc>
-
-" Bracket selection
-vnoremap gi( c(<C-r>")<Esc>
-vnoremap gi) c(<C-r>")<Esc>
-vnoremap gi[ c[<C-r>"]<Esc>
-vnoremap gi] c[<C-r>"]<Esc>
-vnoremap gi{ c{<C-r>"{<Esc>
-vnoremap gi} c}<C-r>"}<Esc>
-
-"}}}
+" Quote {{{
+function! SelectionSurroundWith()
+    " Surround selected text with a single char
+  let l = nr2char(getchar())
+  execute "normal! c" . l . "\<C-r>\"" . l . "\<Esc>"
+endfunction
+vnoremap gi :call SelectionSurroundWith()<CR>
+" }}}
 
 " Autoformatting (to be tested) {{{
 "set formatoptions+=c