Skip to content

Commit 47f308d

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 de7f0c7 commit 47f308d

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'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")'),
242+
\ "substitute(v:val, '^\\s*.'.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
@@ -34,13 +34,13 @@ Execute (flags, -tool options):
3434
AssertEqual count(grepper#complete('', 'Grepper -tool ', v:null), 'grep '), 1
3535

3636
Execute (relative path, empty string):
37-
AssertEqual grepper#complete('', '', v:null), ['./foo/']
37+
AssertEqual grepper#complete('', '', v:null), ['foo/']
3838

3939
Execute (relative path, whitespace only):
40-
AssertEqual grepper#complete(' ', '', v:null), [' ./foo/']
40+
AssertEqual grepper#complete(' ', '', v:null), ['foo/']
4141

4242
Execute (relative path, leading word chars):
43-
AssertEqual grepper#complete('f', '', v:null), ['./foo/']
43+
AssertEqual grepper#complete('f', '', v:null), ['foo/']
4444

4545
Execute (sub-path, ./ exact match):
4646
AssertEqual grepper#complete('./', '', v:null), ['./foo/']

0 commit comments

Comments
 (0)