Skip to content

Conversation

@AlexandrosAlexiou
Copy link
Contributor

@AlexandrosAlexiou AlexandrosAlexiou commented Mar 30, 2025

Fix E565 error when opening directories with nvim .

Neovim version: v0.12.0-dev-42+ge87d2ae383

Stack trace

Failed to run 'config' for oil.nvim
... ~/.local/share/nvim/lazy/oil.nvim/lua/oil/util.lua:178: E565: Not allowed to change text or change window
* stacktrace:
- /oil.nvim/lua/oil/util.lua:178 _in_ **rename_buffer**
- /oil.nvim/lua/oil/init.lua:812 _in_ **maybe_hijack_directory_buffer**
- /oil.nvim/lua/oil/init.lua:1396 _in_ **setup**
- ~/ config/nvim/lua/tt/_plugins/oil.lua:18_in_ **setup**
- ~/. config/nvim/lua/tt/plugins.lua:575 _in_ **config**

Description

This PR fixes an issue where oil.nvim throws an error (E565: Not allowed to change text or change window) when Neovim is started with a directory argument (e.g., nvim .).

The error occurs because during initialization, the plugin attempts to delete buffers in a context where Neovim doesn't allow buffer modifications. This fix wraps the buffer deletion operations in pcall() to safely handle these restrictions.

Steps to reproduce

  1. Lua config:
        config = function()
            require("oil").setup()

            vim.keymap.set("n", "<leader>e", function()
                require("oil").open()
            end, { desc = "Open Oil file explorer" })
        end
  1. Navigate to any directory in your terminal
  2. Run nvim .
  3. Hit <leader>e
  4. Observe the error message in oil's loading process

Changes

  • Added pcall() around buffer deletion operations in rename_buffer function
    • This allows the function to continue execution even when buffer deletion fails and ensures oil opens the correct directory

@github-actions github-actions bot requested a review from stevearc March 30, 2025 15:18
@AlexandrosAlexiou AlexandrosAlexiou force-pushed the fix/directory-open-buffer-error branch from 5622ecf to 802bac7 Compare April 1, 2025 07:18
@stevearc
Copy link
Owner

LGTM

@stevearc stevearc merged commit 685cdb4 into stevearc:master Apr 20, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants