As title. For example if I have this:


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


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


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


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 you have read our privacy policy.

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