Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function! RelativePath(...)
- let path = a:0 ? a:1 : expand('%:p')
- let sep = '/'
- let cwd = split(getcwd(), sep)
- let path_l = split(fnamemodify(path, ':p'), sep)
- while 1
- if empty(cwd) || empty(path_l) || path_l[0] != cwd[0]
- break
- endif
- call remove(path_l, 0)
- call remove(cwd, 0)
- endwhile
- return repeat('..'.sep, len(cwd)).join(path_l, sep)
- endfunction
Add Comment
Please, Sign In to add comment