0

As title. For example if I have this:

foo/bar/baz/bee

which is stored in a variable, then which function should I call to get:

foo/bar/baz

Notice that I will need to store this result back to the variable.

Thanks in advance! I also want to know whether this is possible in Lua too.

2 Answers 2

2

This is fnamemodify(var, ':h').

0

I put my self-answer here since I've dived into my problem and solved it before I saw the answer post here.

This is a workaround, in Lua:

local raw_path = 'foo/bar/baz/bee'
vim.cmd('cd '..raw_path..'/../')
local result = vim.fn.getcwd() -- normalized.
vim.cmd('cd -') -- restore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.