Skip to content

Instantly share code, notes, and snippets.

@jferris
Created October 23, 2013 17:26
Show Gist options
  • Save jferris/7122963 to your computer and use it in GitHub Desktop.
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.
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
@dhruvasagar
Copy link

Just came across this looking for something else, wanted to point out vim already has support for this using 'cdpath', check :h 'cdpath'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment