Guest User

Untitled

a guest
Nov 17th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. function! RelativePath(...)
  2. let path = a:0 ? a:1 : expand('%:p')
  3. let sep = '/'
  4. let cwd = split(getcwd(), sep)
  5. let path_l = split(fnamemodify(path, ':p'), sep)
  6. while 1
  7. if empty(cwd) || empty(path_l) || path_l[0] != cwd[0]
  8. break
  9. endif
  10. call remove(path_l, 0)
  11. call remove(cwd, 0)
  12. endwhile
  13. return repeat('..'.sep, len(cwd)).join(path_l, sep)
  14. endfunction
Add Comment
Please, Sign In to add comment