Created
October 23, 2013 17:26
-
-
Save jferris/7122963 to your computer and use it in GitHub Desktop.
Improve Vim's `:cd` command to tab-complete all directories on `cdpath` and not just the current working directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! Cd(path) | |
execute "cd " . a:path | |
edit . | |
endfunction | |
function! CompleteDirInCdPath(ArgLead, CmdLine, CursorPos) | |
let paths = split(globpath(&cdpath, '*'), '\n') | |
let result = [] | |
for path in paths | |
if isdirectory(path) | |
let result += [fnamemodify(path, ':t')] | |
endif | |
endfor | |
return join(result, "\n") | |
endfunction | |
command! -nargs=1 -complete=custom,CompleteDirInCdPath Cd call Cd(<q-args>) | |
cabbr cd Cd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just came across this looking for something else, wanted to point out vim already has support for this using
'cdpath'
, check:h 'cdpath'