neovimlazyvim

Lazyvim keymaps: what is the different between "cwd" and "root dir"?


I am learning lazyzim, I read the documentation on keymaps:

https://www.lazyvim.org/keymaps

I see a lot of key map that have 2 version (cwd and Root Dir), for example:

leader E    Explorer NeoTree (cwd)
leader fe   Explorer NeoTree (Root Dir)
leader ff   Find Files (Root Dir)
leader fF   Find Files (cwd)

I don't know the different between 2 versions? I know "cwd" stands for "current working directory". For example, I open nvim . at ~/projects/app1 directory, what is the different when I use 2 commands?


Solution

  • "Cwd" is short for "current working directory", that one is pretty clear.

    It is "Root Dir" that is unnecessarily ambiguous, because all file systems already have a "root directory" (/ in Unix-like systems) and that "root directory" is not the "root dir" in question. In this context, "root dir" means "the root of my current project", usually defined by looking for a .git directory or some other heuristics).

    When you cd to ~/projects/app1 in your shell and you do $ nvim ., the "current working directory" and the "(project) root directory" are identical and both the "Root Dir" variants and the "cwd" variants of those commands will have the same effect.

    After that, you can do something like :cd components to change the "current working directory" to ~/projects/app1/components for whatever reason, but the "(project) root directory" is still ~/projects/app1.

    So choosing which mapping to use depends on the context and the desired outcome:

    Note that the notion of "working directory" is native to Vim/Neovim but the notion of "(project) root directory" is not. The editor itself has no notion of "project" whatsoever so the burden of deciding what constitutes a "(project) root directory" falls on the shoulders of the various plugins that make up your "distribution".