Improved autoclose + new mappings

* Autoclose now does pairs of the same character, like "" or ``
* New mappings for surrounding visual selection with opening/closing pairs
This commit is contained in:
Talia 2017-11-13 16:00:55 +01:00
parent 4a022485c9
commit b9f51cd5b4

36
vimrc
View file

@ -117,6 +117,14 @@ function! s:autoClose_HelperClose(open, close)
end end
endfunc endfunc
function! s:autoClose_HelperDouble(open)
if getline(".")[col(".")-1] ==# a:open " Step over
return "\<Right>"
else
return a:open.a:open."\<left>"
end
endfunc
function! s:autoClose_HelperEnter() function! s:autoClose_HelperEnter()
if exists("b:autoClose_Pairs") if exists("b:autoClose_Pairs")
let next_c = getline(".")[col(".")-1] let next_c = getline(".")[col(".")-1]
@ -138,8 +146,12 @@ function! s:autoClose_AddPair(open, close) "TODO: Improve with expand('<sfile>')
end end
let b:autoClose_Pairs[a:open] = a:close let b:autoClose_Pairs[a:open] = a:close
exe "inoremap <buffer> <expr> ".a:open." <SID>autoClose_HelperOpen('".a:open."', '".a:close."')" if a:open!=#a:close
exe "inoremap <buffer> <expr> ".a:close." <SID>autoClose_HelperClose('".a:open."', '".a:close."')" exe "inoremap <buffer> <expr> ".a:open." <SID>autoClose_HelperOpen('".a:open."', '".a:close."')"
exe "inoremap <buffer> <expr> ".a:close." <SID>autoClose_HelperClose('".a:open."', '".a:close."')"
else
exe "inoremap <buffer> <expr> ".a:open." <SID>autoClose_HelperDouble('".a:open."')"
end
inoremap <buffer> <expr> <enter> <SID>autoClose_HelperEnter() inoremap <buffer> <expr> <enter> <SID>autoClose_HelperEnter()
endfunc endfunc
@ -202,6 +214,16 @@ function! StringReverse(str)
return join(reverse(split(str, ".\\zs")), "") return join(reverse(split(str, ".\\zs")), "")
endfunc 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 === " === GENERAL COMMANDS ===
command! L lopen | set number | set norelativenumber command! L lopen | set number | set norelativenumber
command! LAddLine call LocationAddLine(expand("%"), line("."), getline(".")) command! LAddLine call LocationAddLine(expand("%"), line("."), getline("."))
@ -236,10 +258,16 @@ nnoremap k gk
nnoremap Y y$ nnoremap Y y$
" --- OTHER --- " --- OTHER ---
" Don't exit visual mode when shifting " Don't exit visual mode when "shifting"
vnoremap < <gv vnoremap < <gv
vnoremap > >gv vnoremap > >gv
vnoremap <leader>" <C-[>`>a"<C-o>`<"<C-[>:call ShiftSelection(1)<CR>gv
vnoremap <leader>' <C-[>`>a'<C-o>`<'<C-[>:call ShiftSelection(1)<CR>gv
vnoremap <leader>( <C-[>`>a)<C-o>`<(<C-[>:call ShiftSelection(1)<CR>gv
vnoremap <leader>[ <C-[>`>a]<C-o>`<[<C-[>:call ShiftSelection(1)<CR>gv
vnoremap <leader>{ <C-[>`>a}<C-o>`<{<C-[>:call ShiftSelection(1)<CR>gv
nnoremap <S-l> :L<cr> nnoremap <S-l> :L<cr>
noremap <space> : noremap <space> :
noremap <C-space> @: noremap <C-space> @:
@ -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("(", ")")
call s:autoClose_AddPair("[", "]") call s:autoClose_AddPair("[", "]")
call s:autoClose_AddPair('"', '"')
endfunction endfunction
function! s:RubyComment(a) 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("(", ")")
call s:autoClose_AddPair("{", "}") call s:autoClose_AddPair("{", "}")
call s:autoClose_AddPair('"', '"')
endfunction! endfunction!
" --- HTML Stuff --- " --- HTML Stuff ---