vim-grepper
vim-grepper copied to clipboard
Improve file/path completion, handle more cases
Hi,
First, thanks for vim-grepper, this is a great plugin.
The prompt is brilliant, and neatly fixes the problem of having to manually escape # and friends when searching. One thing that immediately threw me though was relative path completion, I typed a search pattern, followed by the first word character in a directory within which I wanted to search, and got no completion :-(
So, I looked at the code and made some changes, supported by some new test coverage, to address my new requirement.
As I'd already added some test coverage, I then went on to add a few more features, e.g. tilde expansion, fix completion of hidden files in cwd, and made some minor changes to the completions returned so it behaves a little more like vim's built in completion, e.g. complete f with foo/, not ./foo/.
Seems to be working well, though I have not battle tested these changes. Would be interested to get some feedback. Do you think these changes are even sensible?
@mhinz I've reworked these commits after I found some time to RTFM :-)
I think this PR is in a good state now, if you'd like to take a look.
I did also consider changing the default completion for the Grepper command to list all flags, but I wasn't sure about that (maybe you should have to add a dash to start completing on flags).
FWIW, here is a patch that would add it (note the hack to deal with abandoned completions):
diff --git a/plugin/grepper.vim b/plugin/grepper.vim
index 199bbb7..689c863 100644
--- a/plugin/grepper.vim
+++ b/plugin/grepper.vim
@@ -212,12 +212,12 @@ endfunction
" Completion {{{1
" grepper#complete() {{{2
function! grepper#complete(lead, line, _pos) abort
+ let flags = ['-append', '-buffer', '-buffers', '-cd', '-cword', '-dir',
+ \ '-grepprg', '-highlight', '-jump', '-open', '-prompt', '-query',
+ \ '-quickfix', '-side', '-stop', '-switch', '-tool', '-noappend',
+ \ '-nohighlight', '-nojump', '-noopen', '-noprompt', '-noquickfix',
+ \ '-noside', '-noswitch']
if a:lead =~ '^-'
- let flags = ['-append', '-buffer', '-buffers', '-cd', '-cword', '-dir',
- \ '-grepprg', '-highlight', '-jump', '-open', '-prompt', '-query',
- \ '-quickfix', '-side', '-stop', '-switch', '-tool', '-noappend',
- \ '-nohighlight', '-nojump', '-noopen', '-noprompt', '-noquickfix',
- \ '-noside', '-noswitch']
return filter(map(flags, 'v:val." "'), 'v:val[:strlen(a:lead)-1] ==# a:lead')
elseif a:line =~# '-dir \w*$'
return filter(map(['cwd', 'file', 'filecwd', 'repo'], 'v:val." "'),
@@ -228,7 +228,7 @@ function! grepper#complete(lead, line, _pos) abort
return filter(map(sort(copy(g:grepper.tools)), 'v:val." "'),
\ 'empty(a:lead) || v:val[:strlen(a:lead)-1] ==# a:lead')
else
- return []
+ return flags
endif
endfunction
@@ -645,6 +645,8 @@ function! s:parse_flags(args) abort
endif
let flags.cd = dir
break
+ elseif flag ==# '-'
+ redraw!
else
call s:error('Ignore unknown flag: '. flag)
endif
@mhinz This has now been simplified to just use Vim's built in getcompletion() function for file completions.