stevearc / oil.nvim

Neovim file explorer: edit your filesystem like a buffer
MIT License
4.07k stars 121 forks source link

bug: cd and tcd doesn't change directories #407

Closed esn89 closed 5 months ago

esn89 commented 5 months ago

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 that before

Then, I do :tcd into the oil dir:

after.

The top right gets updated. But when I do pwd it is still in the same dir

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

    'stevearc/oil.nvim',
    opts = {},
    dependencies = { 'nvim-tree/nvim-web-devicons' },
    config = function()
        require('oil').setup({
            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,
}

Expected Behavior

I expect the directory to be changed and reflected in pwd

Directory structure

No response

Repro

return {
    'stevearc/oil.nvim',
    opts = {},
    dependencies = { 'nvim-tree/nvim-web-devicons' },
    config = function()
        require('oil').setup({
            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,
}

Did you check the bug with a clean config?

stevearc commented 5 months ago

I'm very confused by this bug report. You're mentioning using :tcd to change directories, but you're running pwd in the shell (:!pwd) instead of getting vim's cwd (:pwd or :=vim.fn.getcwd()). I also don't see how oil plays into this at all if you're just issuing vim commands.

Could you provide the exact steps you are taking, the exact commands you are running, and what the output is?

esn89 commented 5 months ago

Hi @stevearc

What I mean by this is: I had expected that the :tcd would also change the directory from where I opened up neovim.

So say I opened up vim in ~/Documents/Projects/app1, if I :tcd upwards, pwd should show ~/Documents/Projects

stevearc commented 5 months ago

This should absolutely be the case. If you run

I will be shocked if the second pwd doesn't show the parent directory of the first.

Again, I'm not quite sure what this has to do with oil.nvim?

eric-marin commented 5 months ago

I have a similar problem. Sometimes when i use the Oil keymap for actions.cd it does nothing

esn89 commented 5 months ago

@stevearc

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 , actions.cd does nothing for me as well.

stevearc commented 5 months ago

In that case I will ask for what is requested in the bug report form:

  1. a complete repro.lua file that is a full, minimal config. A template is provided to make it easy for you.
  2. steps for recreating the state of the filesystem that you are using
  3. clear step-by-step instructions for reproducing the bug
eric-marin commented 5 months ago

For me, the bug only occurs when I open a file directly from dashboard-nvim, so it might be a dashboard issue.

esn89 commented 5 months ago

@stevearc

cat repro.lua

-- 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 And oil says that I am in venv.

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:

img

But still shows that I am in ~

stevearc commented 5 months ago

Here are my steps with the repro file you gave

  1. cd /private/tmp
  2. mkdir -p testdir
  3. nvim -u repro.lua .
  4. :pwd

    /private/tmp

  5. scroll to testdir/ and <CR> to enter the directory
  6. Use ` shortcut to cd to the current directory
  7. :pwd

    /private/tmp/testdir

  8. :!pwd

    /private/tmp/testdir

Nothing surprising, everything working as intended. Can you provide equally detailed steps that you are taking, with the associated output?

esn89 commented 5 months ago

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.