dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit b6adaaab5429fb0fbcc99f5d5e32704a411a7f7f
parent 62d5a4f817999abac765bafbabc001a97ed6dc76
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Thu, 11 Apr 2019 20:42:28 +0200

Vim session management functions

I didn't like any of the available plugins so I decided to spin up my
own system. Wrote a few functions, added some mappings, all starting
with <leader>s. This should be a separate plugin eventually.


Former-commit-id: 98295eacea55ee65704467fe5f9668ee63f784da
Diffstat:
Mvim/commands.vimrc | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mvim/map.vimrc | 8+++++++-
2 files changed, 108 insertions(+), 1 deletion(-)

diff --git a/vim/commands.vimrc b/vim/commands.vimrc @@ -44,6 +44,107 @@ function! DeleteHiddenBuffers() " Vim with the 'hidden' option endfor endfunction +" Custom session management (should be plugin) {{{ +function! SaveSession() abort + let seshdir = $HOME.'/.vim/sessions/' + silent call mkdir (seshdir, 'p') + let name = input("Save as: ") + if name == "" + echo "\nNo name provided." + else + let nt_was_open = 0 + if g:nerdtree_tabs_loaded == 1 + if g:NERDTree.IsOpen() == 1 + execute "NERDTreeTabsClose" + let nt_was_open = 1 + endif + elseif g:loaded_nerd_tree == 1 + if g:NERDTree.IsOpen() == 1 + execute "NERDTreeClose" + let nt_was_open = 1 + endif + endif + + let seshfile = seshdir.name.".vim" + execute "mksession! " . seshfile + echo "\nSession saved: ".seshfile + + if nt_was_open == 1 + if g:loaded_nerd_tree == 1 + if g:nerdtree_tabs_loaded == 1 + execute "NERDTreeTabsToggle" + else + execute "NERDTree" + endif + execute "NERDTreeFocusToggle" + endif + endif + endif +endfunction +function! ListSessions() abort + let seshdir = $HOME.'/.vim/sessions/' + silent call mkdir (seshdir, 'p') + let files = globpath(seshdir, '*', 0, 1) + call filter(files, '!isdirectory(v:val)') + return files +endfunction +function! ChooseSession() abort + let files = ListSessions() + if len(files) > 0 + let inputfiles = map(copy(files), 'index(files, v:val)+1.": ".v:val') + let response = inputlist(inputfiles) + if response > 0 + return files[response-1] + else + return "" + endif + else + echo "No sessions available." + return "" + endif +endfunction +function! LoadSession() abort + let session = ChooseSession() + if session != "" + execute 'source '.session + else + echo "\nNo session selected." + endif +endfunction +function! DeleteSession() abort + let sesh = ChooseSession() + if sesh == "" + echo "\nNo session selected" + return 1 + endif + let conf = confirm("Delete ".sesh."?", "&Yes\n&No\n", 2) + if conf == 1 + if delete(sesh) == 0 + echom "Deleted ".sesh + else + echom "Couldn't delete ".sesh + endif + else + echom "No action taken." + endif +endfunction +function! CloseSession() + bufdo! bwipeout + cd + if g:loaded_nerd_tree == 1 + if g:nerdtree_tabs_loaded == 1 + execute "NERDTreeTabsClose" + else + execute "NERDTreeClose" + endif + endif + if g:loaded_tagbar == 1 + execute "TagbarClose" + endif + echom "Session closed." +endfunction +" }}} + " Custom commands command! TodoP vimgrep /TODO\C<Bslash><Bar>TO DO\C/ **/*.* | copen command! Todo vimgrep /TODO\C<Bslash><Bar>TO DO\c/ % | copen diff --git a/vim/map.vimrc b/vim/map.vimrc @@ -73,7 +73,7 @@ nnoremap <C-l> <C-W>< nnoremap <leader>dh :DeleteHiddenBuffers<CR> " Switch to alernative buffer -nnoremap <leader>s :b#<CR> +nnoremap <leader>s<leader> :b#<CR> " Show hidden symbols nnoremap <leader>hs :set list!<CR> @@ -114,3 +114,9 @@ vnoremap <leader>y "*y " This should be a plugin but for now... " time (hh:mm-hh:mm) to duration in hours nnoremap <leader>td 0f-l"aywf:l"byw0"cywf:l"dywA (=((a*60+b)-(c*60+d))/60.0 )F.r:wyw"aywcw=0.a*60 F.2xih0:s/:0h/h + +" Custom session maps +nnoremap <leader>ss :call SaveSession()<CR> +nnoremap <leader>sl :call LoadSession()<CR> +nnoremap <leader>sd :call DeleteSession()<CR> +nnoremap <leader>sq :call CloseSession()<CR>