Switch vim surround code

This commit is contained in:
Talia 2020-05-07 15:04:17 +02:00
parent 7b63c642cf
commit 94f7990b8d

80
vimrc
View file

@ -235,6 +235,29 @@ elseif has("win32")
nnoremap <leader><space> :e %:p:h<CR> nnoremap <leader><space> :e %:p:h<CR>
end 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 <SID>surround(l:type, a:left, a:right)
endf
function! s:surround(type, left, right)
if a:type ==? 'char'
exec 'normal! `>a'.a:right.'`<i'.a:left
elseif a:type ==? 'line'
exec 'normal! `<`>$A'.a:right.'`<`>I'.a:left
elseif a:type ==? 'block'
exec 'normal! `<`>A'.a:right.'`<`>I'.a:left
end
endf
" --- AUTO CLOSE --- " --- AUTO CLOSE ---
function! s:autoClose_HelperOpen(open, close) function! s:autoClose_HelperOpen(open, close)
@ -571,13 +594,56 @@ inoremap <C-Space> <C-[>0v$:<C-U>exec "'<,'>!".g:exe_prg<CR>
vnoremap < <gv vnoremap < <gv
vnoremap > >gv vnoremap > >gv
vnoremap <leader>" <C-[>`>a"<C-o>`<"<C-[>:call ShiftSelection(1)<CR>`>l " --- START OF SURROUND MAPPINGS ---
vnoremap <leader>' <C-[>`>a'<C-o>`<'<C-[>:call ShiftSelection(1)<CR>`>l function! s:dquote_op(type)
vnoremap <leader>( <C-[>`>a)<C-o>`<(<C-[>:call ShiftSelection(1)<CR>`>l normal `[m<`]m>
vnoremap <leader>[ <C-[>`>a]<C-o>`<[<C-[>:call ShiftSelection(1)<CR>`>l call <SID>surround(a:type, '"', '"')
vnoremap <leader>{ <C-[>`>a}<C-o>`<{<C-[>:call ShiftSelection(1)<CR>`>l endf
vnoremap <leader>< <C-[>`>a><C-o>`<<<C-[>:call ShiftSelection(1)<CR>`>l nnoremap <leader>" :<C-U>set operatorfunc=<SID>dquote_op<CR>g@
vnoremap <leader>` <C-[>`>a`<C-o>`<`<C-[>:call ShiftSelection(1)<CR>`>l vnoremap <leader>" :<C-U>call <SID>vsurround('"', '"')<CR>
function! s:squote_op(type)
normal `[m<`]m>
call <SID>surround(a:type, "'", "'")
endf
nnoremap <leader>' :<C-U>set operatorfunc=<SID>squote_op<CR>g@
vnoremap <leader>' :<C-U>call <SID>vsurround("'", "'")<CR>
function! s:paren_op(type)
normal `[m<`]m>
call <SID>surround(a:type, "(", ")")
endf
nnoremap <leader>( :<C-U>set operatorfunc=<SID>paren_op<CR>g@
vnoremap <leader>( :<C-U>call <SID>vsurround("(", ")")<CR>
function! s:pracket_op(type)
normal `[m<`]m>
call <SID>surround(a:type, "[", "]")
endf
nnoremap <leader>[ :<C-U>set operatorfunc=<SID>bracket_op<CR>g@
vnoremap <leader>[ :<C-U>call <SID>vsurround("[", "]")<CR>
function! s:brace_op(type)
normal `[m<`]m>
call <SID>surround(a:type, "{", "}")
endf
nnoremap <leader>{ :<C-U>set operatorfunc=<SID>brace_op<CR>g@
vnoremap <leader>{ :<C-U>call <SID>vsurround("{", "}")<CR>
function! s:angle_op(type)
normal `[m<`]m>
call <SID>surround(a:type, "<", ">")
endf
nnoremap <leader>< :<C-U>set operatorfunc=<SID>angle_op<CR>g@
vnoremap <leader>< :<C-U>call <SID>vsurround("<", ">")<CR>
function! s:backtick_op(type)
normal `[m<`]m>
call <SID>surround(a:type, "`", "`")
endf
nnoremap <leader>` :<C-U>set operatorfunc=<SID>backtick_op<CR>g@
vnoremap <leader>` :<C-U>call <SID>vsurround("`", "`")<CR>
" --- END OF SURROUND MAPPINGS ---
nnoremap <S-l> :L<cr> nnoremap <S-l> :L<cr>
noremap <space> : noremap <space> :