From 51efac4b2340b33b79b80afe69f40954f32fdae8 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Tue, 9 Feb 2016 08:19:35 -0600 Subject: [PATCH] Added DidYouMean scripte Testing out vim-vinegar --- .gitmodules | 3 +++ .vim/bundle/vim-vinegar | 1 + .vim/plugin/DidYouMean.vim | 51 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 160000 .vim/bundle/vim-vinegar create mode 100644 .vim/plugin/DidYouMean.vim diff --git a/.gitmodules b/.gitmodules index 53fcbb4..fa71b3e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule ".vim/bundle/vim-dirdiff"] path = .vim/bundle/vim-dirdiff url = https://github.com/will133/vim-dirdiff.git +[submodule ".vim/bundle/vim-vinegar"] + path = .vim/bundle/vim-vinegar + url = git://github.com/tpope/vim-vinegar.git diff --git a/.vim/bundle/vim-vinegar b/.vim/bundle/vim-vinegar new file mode 160000 index 0000000..75fc382 --- /dev/null +++ b/.vim/bundle/vim-vinegar @@ -0,0 +1 @@ +Subproject commit 75fc3824bc09053f22735d6726c5cfd614c15642 diff --git a/.vim/plugin/DidYouMean.vim b/.vim/plugin/DidYouMean.vim new file mode 100644 index 0000000..28904fd --- /dev/null +++ b/.vim/plugin/DidYouMean.vim @@ -0,0 +1,51 @@ +" Vim global plugin for selecting the file you actually want to open +" Last Change: 2015-04-22 +" Maintainer: Daniel Schemala +" License: MIT + + +function! s:filter_out_swapfile(matched_files) + silent! redir => swapfile + silent swapname + redir END + let swapfile = fnamemodify(swapfile[1:], ':t') + + return filter(a:matched_files, 'v:val != swapfile') +endfunction + + +function! s:didyoumean() + if filereadable(expand("%")) + " Another BufNewFile event might have handled this already. + return + endif + try + " As of Vim 7.4, glob() has an optional parameter to split, but not + " everybody is using 7.4 yet + let matching_files = split(glob(expand("%")."*", 0), '\n') + if !len(matching_files) + let matching_files = split(glob(expand("%")."*", 1), '\n') + endif + let matching_files = s:filter_out_swapfile(matching_files) + if empty(matching_files) + return + endif + catch + return + endtry + + let shown_items = ['Did you mean:'] + for i in range(1, len(matching_files)) + call add(shown_items, i.'. '.matching_files[i-1]) + endfor + let selected_number = inputlist(shown_items) + if selected_number >= 1 && selected_number <= len(matching_files) + let empty_buffer_nr = bufnr("%") + execute ":edit " . matching_files[selected_number-1] + execute ":silent bdelete " . empty_buffer_nr + filetype detect " without this line, the filetype is not set + endif +endfunction + + +autocmd BufNewFile * call s:didyoumean()