Added DidYouMean scripte
Testing out vim-vinegar
This commit is contained in:
parent
2fc210ac5e
commit
51efac4b23
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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
|
||||
|
1
.vim/bundle/vim-vinegar
Submodule
1
.vim/bundle/vim-vinegar
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 75fc3824bc09053f22735d6726c5cfd614c15642
|
51
.vim/plugin/DidYouMean.vim
Normal file
51
.vim/plugin/DidYouMean.vim
Normal file
@ -0,0 +1,51 @@
|
||||
" Vim global plugin for selecting the file you actually want to open
|
||||
" Last Change: 2015-04-22
|
||||
" Maintainer: Daniel Schemala <istjanichtzufassen@gmail.com>
|
||||
" 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()
|
Loading…
Reference in New Issue
Block a user