1
0
mirror of https://git.decapod.one/brethil/dotfiles synced 2024-11-01 02:11:30 +01:00
dotfiles/vim/functions.vim

88 lines
2.1 KiB
VimL
Raw Normal View History

2020-12-06 02:29:15 +01:00
""" Helper Functions
function! WinZoomToggle() abort
if ! exists('w:WinZoomIsZoomed')
let w:WinZoomIsZoomed = 0
endif
if w:WinZoomIsZoomed == 0
let w:WinZoomOldWidth = winwidth(0)
let w:WinZoomOldHeight = winheight(0)
wincmd _
wincmd |
let w:WinZoomIsZoomed = 1
elseif w:WinZoomIsZoomed == 1
execute "resize " . w:WinZoomOldHeight
execute "vertical resize " . w:WinZoomOldWidth
let w:WinZoomIsZoomed = 0
endif
endfunction
" Highlight all instances of word under cursor, when idle.
" Type z/ to toggle highlighting on/off.
nnoremap z/ :if AutoHighlightToggle()<Bar>set hls<Bar>endif<CR>
function! AutoHighlightToggle()
let @/ = ''
if exists('#auto_highlight')
au! auto_highlight
augroup! auto_highlight
setl updatetime=4000
echo 'Highlight current word: off'
return 0
else
augroup auto_highlight
au!
au CursorHold * let @/ = '\V\<'.escape(expand('<cword>'), '\').'\>'
augroup end
setl updatetime=500
echo 'Highlight current word: ON'
return 1
endif
endfunction
" Don't close window, when deleting a buffer
command! Bclose call <SID>BufcloseCloseIt()
function! <SID>BufcloseCloseIt()
let l:currentBufNum = bufnr("%")
let l:alternateBufNum = bufnr("#")
if buflisted(l:alternateBufNum)
buffer #
else
bnext
endif
if bufnr("%") == l:currentBufNum
new
endif
if buflisted(l:currentBufNum)
execute("bdelete! ".l:currentBufNum)
endif
endfunction
function! CmdLine(str)
call feedkeys(":" . a:str)
endfunction
function! VisualSelection(direction, extra_filter) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", "\\/.*'$^~[]")
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'gv'
call CmdLine("Ack '" . l:pattern . "' " )
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
function! GitStatus()
let [a,m,r] = GitGutterGetHunkSummary()
return printf('+%d ~%d -%d', a, m, r)
endfunction