From 568feb1c2d4450dc7556d01b32e33067d289e540 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 8 Mar 2018 02:45:50 -0500 Subject: move history sync to its own external repository --- .gitmodules | 3 ++ vim/pack/plugins/start/history-sync | 1 + vim/plugin/zshhistory.vim | 78 ------------------------------------- vimrc | 1 + zshrc | 20 ++-------- 5 files changed, 8 insertions(+), 95 deletions(-) create mode 160000 vim/pack/plugins/start/history-sync delete mode 100644 vim/plugin/zshhistory.vim diff --git a/.gitmodules b/.gitmodules index 3fee8d6..2b3c3de 100644 --- a/.gitmodules +++ b/.gitmodules @@ -94,3 +94,6 @@ [submodule "vim/pack/plugins/start/fzf"] path = vim/pack/plugins/start/fzf url = git://github.com/junegunn/fzf +[submodule "vim/pack/plugins/start/history-sync"] + path = vim/pack/plugins/start/history-sync + url = git://github.com/doy/vim-history-sync diff --git a/vim/pack/plugins/start/history-sync b/vim/pack/plugins/start/history-sync new file mode 160000 index 0000000..279aa75 --- /dev/null +++ b/vim/pack/plugins/start/history-sync @@ -0,0 +1 @@ +Subproject commit 279aa756157ab818df67e854e953f6e05809b4a3 diff --git a/vim/plugin/zshhistory.vim b/vim/plugin/zshhistory.vim deleted file mode 100644 index 1969fb7..0000000 --- a/vim/plugin/zshhistory.vim +++ /dev/null @@ -1,78 +0,0 @@ -" see 'vim' alias in zshrc -if $SHELL !~# 'zsh' || !exists('g:_zsh_hist_fname') - finish -endif - -let s:initial_files = {} - -augroup zshhistory - autocmd! - autocmd VimEnter * call init_zsh_hist() - autocmd BufNewFile,BufRead * call zsh_hist_append() - autocmd BufDelete * call remove_initial_file(expand("")) - autocmd VimLeave * call reorder_zsh_hist() -augroup END - -function! s:remove_initial_file (file) - if has_key(s:initial_files, a:file) - unlet s:initial_files[a:file] - endif -endfunction - -function! s:get_buffer_list_text () - redir => l:output - ls! - redir END - return l:output -endfunction - -function! s:get_buffer_list () - silent let l:output = get_buffer_list_text() - let l:buffer_list = [] - for l:buffer_desc in split(l:output, "\n") - let l:name = bufname(str2nr(l:buffer_desc)) - if l:name != "" - call add(l:buffer_list, l:name) - endif - endfor - return l:buffer_list -endfunction - -function! s:init_zsh_hist () - for l:fname in get_buffer_list() - if strlen(l:fname) > 0 - let s:initial_files[l:fname] = 1 - call histadd(":", "e " . l:fname) - endif - endfor - call delete(g:_zsh_hist_fname) -endfunction - -function! s:zsh_hist_append () - let l:to_append = expand("%:~:.") - " XXX these set buftype too late to be caught by this... - " this is broken, but not sure what a better fix is - if &buftype == '' && l:to_append !~# '^\(__Gundo\|Startify\|\[denite\]\)' - if !has_key(s:initial_files, l:to_append) - if filereadable(g:_zsh_hist_fname) - let l:hist = readfile(g:_zsh_hist_fname) - else - let l:hist = [] - endif - call add(l:hist, l:to_append) - call writefile(l:hist, g:_zsh_hist_fname) - endif - endif -endfunction - -function! s:reorder_zsh_hist () - let l:current_file = expand("%:~:.") - if filereadable(g:_zsh_hist_fname) - let l:hist = readfile(g:_zsh_hist_fname) - if !has_key(s:initial_files, l:current_file) - call filter(l:hist, 'v:val != l:current_file') - endif - call add(l:hist, l:current_file) - call writefile(l:hist, g:_zsh_hist_fname) - endif -endfunction diff --git a/vimrc b/vimrc index a7b632b..d15871c 100644 --- a/vimrc +++ b/vimrc @@ -106,6 +106,7 @@ else let g:gundo_disable = 1 endif " }}} +" history-sync " matchit {{{ packadd! matchit " }}} diff --git a/zshrc b/zshrc index e82c817..fd589cf 100644 --- a/zshrc +++ b/zshrc @@ -22,23 +22,6 @@ esac # }}} # aliases {{{ [ -f "$HOME/.sh/aliases" ] && source $HOME/.sh/aliases [ -f "$HOME/.sh/functions" ] && source $HOME/.sh/functions -mkdir -p $HOME/.cache/vim/hist -function vim { - local zsh_hist_fname - zsh_hist_fname=$HOME/.cache/vim/hist/$$ - command vim --cmd "let g:_zsh_hist_fname = '$zsh_hist_fname'" "$@" - if [[ -r $zsh_hist_fname ]]; then - while read line; do - if echo $line | grep -q "[[:space:]']"; then - line=${line/\'/\'\\\\\'\'} - line="'$line'" - fi - print -s "vim $line" - done < $zsh_hist_fname - fc -AI - rm -f $zsh_hist_fname - fi -} # }}} # completion {{{ fpath=(~/.zsh/zsh-completions/src $fpath) @@ -87,6 +70,9 @@ ZSH_HIGHLIGHT_STYLES[assign]='fg=cyan' source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=black,bold' # }}} +# vim-history-sync {{{ +source ~/.vim/pack/plugins/start/history-sync/sh/history-sync.zsh +# }}} # }}} # prompt {{{ if type fancy-prompt > /dev/null 2>&1; then -- cgit v1.2.3-54-g00ecf