From 94f7990b8deda10cb392df5dfb6b71c40876439c Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Thu, 7 May 2020 15:04:17 +0200 Subject: [PATCH] Switch vim surround code --- vimrc | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 73 insertions(+), 7 deletions(-) diff --git a/vimrc b/vimrc index fc0e26a..267ed3b 100644 --- a/vimrc +++ b/vimrc @@ -235,6 +235,29 @@ elseif has("win32") nnoremap :e %:p:h end +" --- SURROUND --- + +function! s:vsurround(left, right) + if visualmode() ==# "v" + let l:type="char" + elseif visualmode() ==# "V" + let l:type="line" + elseif visualmode() ==# "" + let l:type="block" + end + call surround(l:type, a:left, a:right) +endf + +function! s:surround(type, left, right) + if a:type ==? 'char' + exec 'normal! `>a'.a:right.'`$A'.a:right.'`<`>I'.a:left + elseif a:type ==? 'block' + exec 'normal! `<`>A'.a:right.'`<`>I'.a:left + end +endf + " --- AUTO CLOSE --- function! s:autoClose_HelperOpen(open, close) @@ -571,13 +594,56 @@ inoremap 0v$:exec "'<,'>!".g:exe_prg vnoremap < >gv -vnoremap " `>a"`<":call ShiftSelection(1)`>l -vnoremap ' `>a'`<':call ShiftSelection(1)`>l -vnoremap ( `>a)`<(:call ShiftSelection(1)`>l -vnoremap [ `>a]`<[:call ShiftSelection(1)`>l -vnoremap { `>a}`<{:call ShiftSelection(1)`>l -vnoremap < `>a>`<<:call ShiftSelection(1)`>l -vnoremap ` `>a``<`:call ShiftSelection(1)`>l +" --- START OF SURROUND MAPPINGS --- +function! s:dquote_op(type) + normal `[m<`]m> + call surround(a:type, '"', '"') +endf +nnoremap " :set operatorfunc=dquote_opg@ +vnoremap " :call vsurround('"', '"') + +function! s:squote_op(type) + normal `[m<`]m> + call surround(a:type, "'", "'") +endf +nnoremap ' :set operatorfunc=squote_opg@ +vnoremap ' :call vsurround("'", "'") + +function! s:paren_op(type) + normal `[m<`]m> + call surround(a:type, "(", ")") +endf +nnoremap ( :set operatorfunc=paren_opg@ +vnoremap ( :call vsurround("(", ")") + +function! s:pracket_op(type) + normal `[m<`]m> + call surround(a:type, "[", "]") +endf +nnoremap [ :set operatorfunc=bracket_opg@ +vnoremap [ :call vsurround("[", "]") + +function! s:brace_op(type) + normal `[m<`]m> + call surround(a:type, "{", "}") +endf +nnoremap { :set operatorfunc=brace_opg@ +vnoremap { :call vsurround("{", "}") + +function! s:angle_op(type) + normal `[m<`]m> + call surround(a:type, "<", ">") +endf +nnoremap < :set operatorfunc=angle_opg@ +vnoremap < :call vsurround("<", ">") + +function! s:backtick_op(type) + normal `[m<`]m> + call surround(a:type, "`", "`") +endf +nnoremap ` :set operatorfunc=backtick_opg@ +vnoremap ` :call vsurround("`", "`") +" --- END OF SURROUND MAPPINGS --- nnoremap :L noremap :