Skip to content

Commit c7857e0

Browse files
committed
Complete relative paths more like vim's completion
Relative path completion relies on the globpath() function, prepending a leading dot and slash when creating the path for globpath(), but this results in path completions with a leading dot and slash, unlike vim's built in file/path completion, so strip them back out before returning.
1 parent 56854d9 commit c7857e0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

plugin/grepper.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ function! grepper#complete_files(lead, _line, _pos)
237237
let [head, path] = s:extract_path(a:lead)
238238
" handle relative paths
239239
if empty(path) || (path =~ '\s$') || (path =~ '^\s*\w\+')
240-
return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')
240+
return map(
241+
\ map(split(globpath('.'.s:slash, path.'*'), '\n'), "substitute(v:val, '^\\s*.'.s:slash, '', '')"),
242+
\ 'head . v:val . (isdirectory(v:val) ? s:slash : "")'
243+
\ )
241244
" handle sub paths
242245
elseif path =~ '^.\/'
243246
return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')

test/feature/completion.vader

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ Execute (command: flags, -tool options):
3838
AssertEqual count(grepper#complete('', 'Grepper -tool ', v:null), 'grep '), 1
3939

4040
Execute (prompt: relative path, empty string):
41-
AssertEqual grepper#complete_files('x ', v:null, v:null), ['x ./foo/']
41+
AssertEqual grepper#complete_files('x ', v:null, v:null), ['x foo/']
4242

4343
Execute (prompt: relative path, whitespace only):
44-
AssertEqual grepper#complete_files('x ', v:null, v:null), ['x ./foo/']
44+
AssertEqual grepper#complete_files('x ', v:null, v:null), ['x foo/']
4545

4646
Execute (prompt: relative path, leading word chars):
47-
AssertEqual grepper#complete_files('x f', v:null, v:null), ['x ./foo/']
47+
AssertEqual grepper#complete_files('x f', v:null, v:null), ['x foo/']
4848

4949
Execute (prompt: sub-path, ./ exact match):
5050
AssertEqual grepper#complete_files('x ./', v:null, v:null), ['x ./foo/']

0 commit comments

Comments
 (0)