How can I start neovim in the directory from the command line?

When I start neovim from my home directory, but pass an argument to a project folder, such as nvim ~/dev/my_project, the working directory is still in my home directory, and netrw shows all my home directory files.

How could I change this behavior, so neovim cd’s into the directory specified when starting neovim?

It’s the same as this question here: neovim - Set current working directory when opening vim - Vi and Vim Stack Exchange
But I am using lua for my configs, and am not sure how to convert this vimscript to lua.

local group_cdpwd = vim.api.nvim_create_augroup("group_cdpwd", { clear = true })
vim.api.nvim_create_autocmd("VimEnter", {
  group = group_cdpwd,
  pattern = "*",
  callback = function()

Perhaps the use of special plugins is more convenient than this chunk

1 Like