0

Say I have a nnoremap and I want to pass the path of parent directory of current file to it, so the command can use this information. I have read this answer: How can I see the full path of the current file? but Still don't know how to do it?

I just found that % almost do the job, but it returns path to current file.

NeoZoom.lua
  • 1,442
  • 14
  • 31

1 Answers1

1

OK, after some try-and-error I resolved this problem. To get the path to parent dir:

%:p:h

Notice that the :p is needed to get the full path, without it you might end up with nothing, i.e. it's possible you cannot find the parent folder.

For example, my usage:

nnoremap <nowait><silent> <Tab>
                        \ :Fern %:h -drawer -width=36 -toggle -reveal=%<CR>

As you can see it is used directly inside the command, without any parentheses, single/double quotes, curly braces around it.

NeoZoom.lua
  • 1,442
  • 14
  • 31