0

As title. I'm using NeoVim. If I use vim.fn.getcwd() in the config I will not get the correct path considering the argument, e.g. nvim ./go/deeper/into/some/folder, passed to nvim. Solutions in VimScript is welcome since I can translate it into lua one.

1
  • If you need the directory containing the first argument, try combining fnamemodify() with argc()/argv(), or v:argv if you need the full command-line.
    – D. Ben Knoble
    Apr 19, 2022 at 14:40

1 Answer 1

1

The getcwd() returns the current working directory of vim. By default it is the current working directory of the process that started vim.

In particular it is not the path of the folder of the file edited that you pass as argument to vim.

4
  • So is it possible to get the argument and combine them together?
    – Kindred
    Apr 19, 2022 at 10:44
  • I believe not while reading the .vimrc file. If you give us more information about what you would like to achieve I suppose we could guide you better on the way to achieve it. Why do you want to use the folder path of the file you pass as argument to vim? Apr 19, 2022 at 12:04
  • you could try :set acd Apr 19, 2022 at 15:53
  • @VivianDeSmedt: github.com/nyngwang/NeoRoot.lua, I'm the author. I want to skip the first step. "what you would like to achieve"... Hmmm, the best of me?
    – Kindred
    Apr 20, 2022 at 3:35

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.