Move vim surround code into separate file

This commit is contained in:
Talia 2020-05-18 10:10:39 +02:00
parent 90742c3d01
commit fb139cbe4a
3 changed files with 85 additions and 81 deletions

View File

@ -240,29 +240,6 @@ 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)
@ -597,64 +574,6 @@ inoremap <C-Space> <C-[>0v$:<C-U>exec "'<,'>!".g:exe_prg<CR>
vnoremap < <gv
vnoremap > >gv
" --- 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>
function! s:asterisk_op(type)
normal `[m<`]m>
call <SID>surround(a:type, "*", "*")
endf
nnoremap <leader>* :<C-U>set operatorfunc=<SID>asterisk_op<CR>g@
vnoremap <leader>* :<C-U>call <SID>vsurround("*", "*")<CR>
" --- END OF SURROUND MAPPINGS ---
nnoremap <S-l> :L<cr>
noremap <space> :
noremap <C-space> @:

84
vim/surround.vim Normal file
View File

@ -0,0 +1,84 @@
" ┌──────────┐
" │ Funtions │
" └──────────┘
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
" ┌──────────┐
" │ 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>
function! s:asterisk_op(type)
normal `[m<`]m>
call <SID>surround(a:type, "*", "*")
endf
nnoremap <leader>* :<C-U>set operatorfunc=<SID>asterisk_op<CR>g@
vnoremap <leader>* :<C-U>call <SID>vsurround("*", "*")<CR>

1
vimrc
View File

@ -4,4 +4,5 @@
let &rtp=expand('<sfile>:p:h').'/vim,'.&rtp
run git.vim
run surround.vim
run shame.vim