Get rid of `realpath` dependency #1

Open
opened 9 months ago by scy · 0 comments
scy commented 9 months ago
Owner

user938271 responded to my Stack Exchange question with a Vimscript-only solution. I think it still needs to have some kinks worked out, but it’s basically this (written to be Vim 8.0 compatible):

function! relatifile#vimrelative(path, curfile)
	let head_of_curfile = fnamemodify(a:curfile, ':h') . '/'
	if stridx(a:path, head_of_curfile) == 0
		return substitute(a:path, head_of_curfile, '../', '')
	endif
	return '../' . relatifile#vimrelative(a:path, fnamemodify(a:curfile, ':h'))
endfunction

It also needs some changes to match the relatifile#relative(names, dir) signature.

user938271 [responded](https://vi.stackexchange.com/a/28854/33217) to my Stack Exchange question with a Vimscript-only solution. I think it still needs to have some kinks worked out, but it’s basically this (written to be Vim 8.0 compatible): ```viml function! relatifile#vimrelative(path, curfile) let head_of_curfile = fnamemodify(a:curfile, ':h') . '/' if stridx(a:path, head_of_curfile) == 0 return substitute(a:path, head_of_curfile, '../', '') endif return '../' . relatifile#vimrelative(a:path, fnamemodify(a:curfile, ':h')) endfunction ``` It also needs some changes to match the `relatifile#relative(names, dir)` signature.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.