Switch vim surround code
This commit is contained in:
parent
7b63c642cf
commit
94f7990b8d
1 changed files with 73 additions and 7 deletions
80
vimrc
80
vimrc
|
@ -235,6 +235,29 @@ elseif has("win32")
|
|||
nnoremap <leader><space> :e %:p:h<CR>
|
||||
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 ---
|
||||
|
||||
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 <leader>" <C-[>`>a"<C-o>`<"<C-[>:call ShiftSelection(1)<CR>`>l
|
||||
vnoremap <leader>' <C-[>`>a'<C-o>`<'<C-[>:call ShiftSelection(1)<CR>`>l
|
||||
vnoremap <leader>( <C-[>`>a)<C-o>`<(<C-[>:call ShiftSelection(1)<CR>`>l
|
||||
vnoremap <leader>[ <C-[>`>a]<C-o>`<[<C-[>:call ShiftSelection(1)<CR>`>l
|
||||
vnoremap <leader>{ <C-[>`>a}<C-o>`<{<C-[>:call ShiftSelection(1)<CR>`>l
|
||||
vnoremap <leader>< <C-[>`>a><C-o>`<<<C-[>:call ShiftSelection(1)<CR>`>l
|
||||
vnoremap <leader>` <C-[>`>a`<C-o>`<`<C-[>:call ShiftSelection(1)<CR>`>l
|
||||
" --- START OF SURROUND MAPPINGS ---
|
||||
function! s:dquote_op(type)
|
||||
normal `[m<`]m>
|
||||
call <SID>surround(a:type, '"', '"')
|
||||
endf
|
||||
nnoremap <leader>" :<C-U>set operatorfunc=<SID>dquote_op<CR>g@
|
||||
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>
|
||||
noremap <space> :
|
||||
|
|
Loading…
Reference in a new issue