From b9f51cd5b42a8605d14d9dffbb55978e8a12e027 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Mon, 13 Nov 2017 16:00:55 +0100 Subject: [PATCH] Improved autoclose + new mappings * Autoclose now does pairs of the same character, like "" or `` * New mappings for surrounding visual selection with opening/closing pairs --- vimrc | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/vimrc b/vimrc index d307a85..276fbc8 100644 --- a/vimrc +++ b/vimrc @@ -117,6 +117,14 @@ function! s:autoClose_HelperClose(open, close) end endfunc +function! s:autoClose_HelperDouble(open) + if getline(".")[col(".")-1] ==# a:open " Step over + return "\" + else + return a:open.a:open."\" + end +endfunc + function! s:autoClose_HelperEnter() if exists("b:autoClose_Pairs") let next_c = getline(".")[col(".")-1] @@ -138,8 +146,12 @@ function! s:autoClose_AddPair(open, close) "TODO: Improve with expand('') end let b:autoClose_Pairs[a:open] = a:close - exe "inoremap ".a:open." autoClose_HelperOpen('".a:open."', '".a:close."')" - exe "inoremap ".a:close." autoClose_HelperClose('".a:open."', '".a:close."')" + if a:open!=#a:close + exe "inoremap ".a:open." autoClose_HelperOpen('".a:open."', '".a:close."')" + exe "inoremap ".a:close." autoClose_HelperClose('".a:open."', '".a:close."')" + else + exe "inoremap ".a:open." autoClose_HelperDouble('".a:open."')" + end inoremap autoClose_HelperEnter() endfunc @@ -202,6 +214,16 @@ function! StringReverse(str) return join(reverse(split(str, ".\\zs")), "") endfunc +function! ShiftMarker(m,n) + let [bufn,line,column,offset]=getpos("'".a:m) + call setpos("'".a:m,[bufn,line,column+a:n,offset]) +endfunc + +function! ShiftSelection(n) + call ShiftMarker("<", a:n) + call ShiftMarker(">", a:n) +endfunc + " === GENERAL COMMANDS === command! L lopen | set number | set norelativenumber command! LAddLine call LocationAddLine(expand("%"), line("."), getline(".")) @@ -236,10 +258,16 @@ nnoremap k gk nnoremap Y y$ " --- OTHER --- -" Don't exit visual mode when shifting +" Don't exit visual mode when "shifting" vnoremap < >gv +vnoremap " `>a"`<":call ShiftSelection(1)gv +vnoremap ' `>a'`<':call ShiftSelection(1)gv +vnoremap ( `>a)`<(:call ShiftSelection(1)gv +vnoremap [ `>a]`<[:call ShiftSelection(1)gv +vnoremap { `>a}`<{:call ShiftSelection(1)gv + nnoremap :L noremap : noremap @: @@ -510,6 +538,7 @@ function! s:init_ruby_file() call s:autoClose_AddPair("{", "}") call s:autoClose_AddPair("(", ")") call s:autoClose_AddPair("[", "]") + call s:autoClose_AddPair('"', '"') endfunction function! s:RubyComment(a) @@ -543,6 +572,7 @@ function! s:init_lua_file() call s:autoClose_AddPair("[", "]") call s:autoClose_AddPair("(", ")") call s:autoClose_AddPair("{", "}") + call s:autoClose_AddPair('"', '"') endfunction! " --- HTML Stuff ---