stevearc / oil.nvim

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

bug: files can get mangle when doing search and replace that includes whitespace #388

Closed rafamadriz closed 2 weeks ago

rafamadriz commented 1 month ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

v0.9.5

Operating system/version

Arch linux 6.8.9-arch1-1

Describe the bug

If a column option is set, then renaming files with patterns that are also included is those columns, (e.g whitespace) results in files being corrupted (If rename is saved of course).

I found this while trying to replace all the whitespace in some filenames with -, so the files would be some-file instead of some file

What is the severity of this bug?

tolerable (can work around it)

Steps To Reproduce

  1. Create some test files
    touch 'file with whitespace number 1'
    touch 'file with whitespace number 2'
    touch 'file with whitespace number 3'
  2. nvim -u repro.lua .
  3. In this case I want to replace all all whitespace in file name with -
  4. Rename with :%s/\s/-/g and save
  5. Error detected while processing BufWriteCmd Autocommands for "oil://*": Error parsing oil buffers

Expected Behavior

Only the filenames gets affected by the search and replace.

This is obviously a limitation of how buffers works, nothing that can be done about it. Solution is to disable all columns so you are just left with the plain filenames. Another solution I just thought is to give the option to toggle columns on demand, so if you need to do this kind of search replace, you can toggle them in the spot instead of going to your oil config, disabling them, reloading config, and finally going back to where you were.

However I just wanted to ask if adding the columns using the inlay text feature of nvim 0.10 would be something that's possible, inlay text is not editable text, so It wouldn't be affected by this type of edge cases of bulk rename.

Directory structure

No response

Repro

-- 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
                columns = {
                    "icon",
                    "permissions",
                    "size",
                    "mtime",
                },
            })
        end,
    },
    -- add any other plugins here
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Did you check the bug with a clean config?

rafamadriz commented 1 month ago

EDIT: I just notice that I should've opened this as feature request or something, not a bug (that's just how buffers work) but can't modify it now

stevearc commented 2 weeks ago

Unfortunately this is not possible with the limitations that oil is working with. We have to have a unique ID column present in the buffer. Using extmarks could be an interesting approach, but for now there does not appear to be a way to yank and paste extmarks.