Repository: LazyVim/LazyVim
File: lua/lazyvim/plugins/extras/editor/mini-files.lua (Lua)

Code before:
      if cur_directory ~= nil then
        vim.fn.chdir(cur_directory)
      end
    end

    vim.api.nvim_create_autocmd("User", {
      pattern = "MiniFilesBufferCreate",
      callback = function(args)
        local buf_id = args.data.buf_id
        vim.keymap.set(
          "n",
          opts.mappings.toggle_hidden or "g.",
          toggle_dotfiles,
          { buffer = buf_id, desc = "Toggle hidden files" }
        )
      end,
    })

    vim.api.nvim_create_autocmd("User", {
      pattern = "MiniFilesBufferCreate",
      callback = function(args)
        local buf_id = args.data.buf_id
        map_split(buf_id, opts.mappings.go_in_horizontal or "gs", "horizontal", false)
        map_split(buf_id, opts.mappings.go_in_vertical or "gv", "vertical", false)
        map_split(buf_id, opts.mappings.go_in_horizontal_plus or "gS", "horizontal", true)
        map_split(buf_id, opts.mappings.go_in_vertical_plus or "gV", "vertical", true)
      end,
    })

    vim.api.nvim_create_autocmd("User", {
      pattern = "MiniFilesBufferCreate",
      callback = function(args)
        vim.keymap.set(
          "n",
          opts.mappings.change_cwd or "gc",
          files_set_cwd,
          { buffer = args.data.buf_id, desc = "Set cwd" }
        )
      end,
    })

    vim.api.nvim_create_autocmd("User", {
      pattern = "MiniFilesActionRename",
      callback = function(event)
        require("lazyvim.util").lsp.on_rename(event.data.from, event.data.to)
      end,
    })
  end
}


Review comment (suggestion):
The first two mappings (as well as `gc` below) were suggested by mini.files documentation. I don't care for them as they conflict with existing mappings. Happy to change them to something more Lazy, but I'm not sure what they should be. Some ideas:

* `<space>|` and `<space><minus>`, overwriting the LazyVim keymappings for opening new windows in splits, but not obvious what to do with the `*_plus` versions.
*  `<C-w>v, <C-w>V, `<C-w>s` and `<C-w>S`, overwriting the standard vim keymappings for opening new windows in splits.
* `\v`, `\V`, `\s`, `\S` which is what I'll use because I have `\` mapped to `<C-w>`


Code after:
      if cur_directory ~= nil then
        vim.fn.chdir(cur_directory)
      end
    end

    vim.api.nvim_create_autocmd("User", {
      pattern = "MiniFilesBufferCreate",
      callback = function(args)
        local buf_id = args.data.buf_id

        vim.keymap.set(
          "n",
          opts.mappings.toggle_hidden or "g.",
          toggle_dotfiles,
          { buffer = buf_id, desc = "Toggle hidden files" }
        )

        vim.keymap.set(
          "n",
          opts.mappings.change_cwd or "gc",
          files_set_cwd,
          { buffer = args.data.buf_id, desc = "Set cwd" }
        )

        map_split(buf_id, opts.mappings.go_in_horizontal or "<C-w>s", "horizontal", false)
        map_split(buf_id, opts.mappings.go_in_vertical or "<C-w>v", "vertical", false)
        map_split(buf_id, opts.mappings.go_in_horizontal_plus or "<C-w>S", "horizontal", true)
        map_split(buf_id, opts.mappings.go_in_vertical_plus or "<C-w>V", "vertical", true)
      end,
    })

    vim.api.nvim_create_autocmd("User", {
      pattern = "MiniFilesActionRename",
      callback = function(event)
        LazyVim.lsp.on_rename(event.data.from, event.data.to)
      end,
    })
  end,
}