-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: cd and tcd doesn't change directories #407
Comments
I'm very confused by this bug report. You're mentioning using Could you provide the exact steps you are taking, the exact commands you are running, and what the output is? |
Hi @stevearc What I mean by this is: So say I opened up vim in ~/Documents/Projects/app1, if I :tcd upwards, pwd should show ~/Documents/Projects |
This should absolutely be the case. If you run
I will be shocked if the second Again, I'm not quite sure what this has to do with oil.nvim? |
I have a similar problem. |
Yes, when I run your following 4 commands, it does EXACTLY what I need! However, in oil.nvim, not so much. And similar to @eric-marin , |
In that case I will ask for what is requested in the bug report form:
|
For me, the bug only occurs when I open a file directly from dashboard-nvim, so it might be a dashboard issue. |
-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify('./.repro', ':p')
-- set stdpaths to use .repro
for _, name in ipairs({ 'config', 'data', 'state', 'runtime', 'cache' }) do
vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end
-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
'git',
'clone',
'--filter=blob:none',
'--single-branch',
'https://github.com/folke/lazy.nvim.git',
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
'folke/tokyonight.nvim',
{
'stevearc/oil.nvim',
config = function()
require('oil').setup({
-- add any needed settings here
{
default_file_explorer = true,
columns = {
'icon',
},
keymaps = {
['<C-v>'] = 'actions.select_vsplit',
['<C-s>'] = 'actions.select_split',
['<C-f>'] = 'actions.preview_scroll_up',
['<C-b>'] = 'actions.preview_scroll_down',
['<C-i'] = 'actions.cd',
['<C-o'] = 'actions.tcd',
},
preview = {
-- Width dimensions can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
-- min_width and max_width can be a single value or a list of mixed integer/float types.
-- max_width = {100, 0.8} means "the lesser of 100 columns or 80% of total"
max_width = 0.9,
-- min_width = {40, 0.4} means "the greater of 40 columns or 40% of total"
min_width = { 40, 0.4 },
-- optionally define an integer/float for the exact width of the preview window
width = nil,
-- Height dimensions can be integers or a float between 0 and 1 (e.g. 0.4 for 40%)
-- min_height and max_height can be a single value or a list of mixed integer/float types.
-- max_height = {80, 0.9} means "the lesser of 80 columns or 90% of total"
max_height = 0.9,
-- min_height = {5, 0.1} means "the greater of 5 columns or 10% of total"
min_height = { 5, 0.1 },
-- optionally define an integer/float for the exact height of the preview window
height = nil,
border = 'rounded',
win_options = {
winblend = 0,
},
-- Whether the preview window is automatically updated when the cursor is moved
update_on_cursor_moved = true,
},
},
})
end,
},
-- add any other plugins here
}
require('lazy').setup(plugins, {
root = root .. '/plugins',
})
vim.cmd.colorscheme('tokyonight')
-- add anything else here Here I entered into ~/venv: img So I tried hitting the ` and the ~ and it does nothing. So I just hit enter and went inside of it. And that is when I did :pwd: But still shows that I am in ~ |
Here are my steps with the repro file you gave
Nothing surprising, everything working as intended. Can you provide equally detailed steps that you are taking, with the associated output? |
Aaaaaaaah. Okay, so this is me using it wrong. I did not know that I had to first ENTER the directory with , then use `. I thought that by pressing `, it will enter & :cd into it. My bad. |
I believe I am following the steps listed here in this issue and I'm experiencing this same issue. Perhaps I'm being dense, but I tried those steps, in a multitude of permutations, but I think I probably just have some critical misunderstanding of something here. I'm not sure if it's preferred I open a new ticket or extend this semi-recent one that is directly relevant to me. I'll start here and create a new ticket if requested. Thank you for your time and assistance. |
@lcpichette |
Ah, I apologize for my misunderstanding. I saw I think if it did have this ability, which now I understand it cannot, it oil.nvim would be a real competitor to yazi and other file managers. I definitely prefer it for file navigation and management, as I can use my other neovim plugins for enhanced searching and navigation. Oh well, thanks again! |
Update: I was able to accomplish this by adding a script to my shell's profile, and an autocmd in my init.lua. I'll post it below in case anyone's interested in using oil.nvim as their file manager.
abbr -a nv "nvimcd"
...
# Store `pwd` after we exit neovim + use it after neovim exit to `cd`
function nvimcd
set tmpfile (mktemp)
set -x NVIM_LASTDIR_FILE $tmpfile
nvim $argv
if test -f $tmpfile
set lastdir (cat $tmpfile)
rm -f $tmpfile
if test -n "$lastdir" -a -d "$lastdir"
cd $lastdir
end
end
end
# Run oil.nvim on shell start
if status --is-interactive
nvim .
end
-- Stores pwd upon exit
if vim.env.NVIM_LASTDIR_FILE then
vim.api.nvim_create_autocmd("VimLeavePre", {
callback = function()
local cwd = vim.fn.getcwd()
vim.fn.writefile({ cwd }, vim.env.NVIM_LASTDIR_FILE)
end,
})
end I also have oil run whenever I open directories: return {
...
-- OIL: Better file searching and manipulation
{
"stevearc/oil.nvim",
config = function()
require("oil").setup({
-- Customize your configuration here
view_options = {
show_hidden = true, -- Show hidden files
},
})
-- Automatically open `oil.nvim` for directories
vim.api.nvim_create_autocmd("VimEnter", {
callback = function()
local path = vim.fn.expand("%:p")
if vim.fn.isdirectory(path) == 1 then
require("oil").open()
end
end,
})
end,
},
} Here's a video showing it working: Hope this is able to help someone! Love oil, glad I was able to find a workaround to using it as my defacto file manager. |
Did you check the docs and existing issues?
Neovim version (nvim -v)
NVIM v0.10.0
Operating system/version
MacOS 14.5
Describe the bug
:cd and :tcd does not actually change directories.
Before, I am in
~/.config/nvim/lua/plugins
:with
pwd
showing thatThen, I do
:tcd
into the oil dir:.
The top right gets updated. But when I do
pwd
it is still in the same dirWhat is the severity of this bug?
breaking (some functionality is broken)
Steps To Reproduce
Expected Behavior
I expect the directory to be changed and reflected in
pwd
Directory structure
No response
Repro
Did you check the bug with a clean config?
nvim -u repro.lua
using the repro.lua file above.The text was updated successfully, but these errors were encountered: