Closed timofurrer closed 7 months ago
I'm currently using lspconfig
to find the git ancestor, but it's not as nice.
This is what I use to open Oil in the git root of my buffer file.
vim.keymap.set("n", "_g", function()
local git_path = vim.fn.finddir(".git", ".;")
local cd_git = vim.fn.fnamemodify(git_path, ":h")
vim.api.nvim_command(string.format("edit %s", cd_git))
end, { desc = "edit .git root" })
If I wanted the keymap to also set the cwd to the git root, I would include vim.api.nvim_set_current_dir. So:
vim.keymap.set("n", "_g", function()
local git_path = vim.fn.finddir(".git", ".;")
local cd_git = vim.fn.fnamemodify(git_path, ":h")
vim.api.nvim_command(string.format("edit %s", cd_git))
vim.api.nvim_set_current_dir(cd_git)
end, { desc = "edit .git root" })
Not sure if this is along the lines of what you are looking for.
Thanks @gregdezeeuw! That is the recommended solution for this. I won't be adding a special option for this, so creating your own custom binding for it is the way to go.
Did you check existing requests?
Describe the feature
The Oil command should support a
--in-git-root
to set the cwd to the git repository root.Provide background
I want to be able to easily configure a key mapping that opens oil in the root of the git repository.
What is the significance of this feature?
strongly desired
Additional details
No response