From 235f4e52ef2de0f5dfc17188f3a5446918860029 Mon Sep 17 00:00:00 2001 From: srdusr Date: Thu, 9 Feb 2023 13:40:44 +0200 Subject: Add utils.vim --- autoload/utils.vim | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 autoload/utils.vim (limited to 'autoload') diff --git a/autoload/utils.vim b/autoload/utils.vim new file mode 100644 index 0000000..d4a1298 --- /dev/null +++ b/autoload/utils.vim @@ -0,0 +1,106 @@ +" Toggle Zoom +function! utils#ZoomToggle() + if exists('t:zoomed') && t:zoomed + execute t:zoom_winrestcmd + let t:zoomed = 0 + else + let t:zoom_winrestcmd = winrestcmd() + resize + vertical resize + let t:zoomed = 1 + endif +endfunction +"command! ZoomToggle call ZoomToggle() + + +"------------------------------------------------- + +" Toggle DiagnosticsOpenFloat +augroup OpenFloat + autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focusable = false,}) + +augroup END + +function! utils#ToggleDiagnosticsOpenFloat() + " Switch the toggle variable + let g:DiagnosticsOpenFloat = !get(g:, 'DiagnosticsOpenFloat', 1) + + " Reset group + augroup OpenFloat + autocmd! + augroup END + + " Enable if toggled on + if g:DiagnosticsOpenFloat + augroup OpenFloat + autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focusable = false,}) + "autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focusable = false,}) print ("vim.diagnostic.open_float enabled...") + augroup END + endif +endfunction +"command! ToggleDiagonsticsOpenFloat call ToggleDiagnosticsOpenFloat() + + +"------------------------------------------------- + +" Toggle transparency +let t:is_transparent = 0 +function! utils#Toggle_transparent_background() + if t:is_transparent == 0 + hi Normal guibg=#111111 ctermbg=black + let t:is_transparent = 1 + else + hi Normal guibg=NONE ctermbg=NONE + let t:is_transparent = 0 + endif +endfunction +"nnoremap tb :call Toggle_transparent_background() + + +"------------------------------------------------- + +" Toggle statusline +let s:hidden_all = 0 +function! ToggleHiddenAll() + if s:hidden_all == 0 + let s:hidden_all = 1 + set noshowmode + set noruler + set laststatus=0 + set noshowcmd + else + let s:hidden_all = 0 + set showmode + set ruler + set laststatus=2 + set showcmd + endif +endfunction +"nnoremap :call ToggleHiddenAll() + + +"------------------------------------------------- + +" Open last closed buffer +function! OpenLastClosed() + let last_buf = bufname('#') + if empty(last_buf) + echo "No recently closed buffer found" + return + endif + let result = input("Open ". last_buf . " in (n)ormal (v)split, (t)ab or (s)plit ? (n/v/t/s) : ") + if empty(result) || (result !=# 'v' && result !=# 't' && result !=# 's' && result !=# 'n') + return + endif + if result ==# 't' + execute 'tabnew' + elseif result ==# 'v' + execute "vsplit" + elseif result ==# 's' + execute "split" + endif + execute 'b ' . last_buf +endfunction + + +"------------------------------------------------- -- cgit v1.2.3