oil.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. local M = {
  2. "stevearc/oil.nvim",
  3. }
  4. M.config = function()
  5. local function max_height()
  6. local height = vim.fn.winheight(0)
  7. if height >= 40 then
  8. return 30
  9. elseif height >= 30 then
  10. return 20
  11. else
  12. return 10
  13. end
  14. end
  15. require("oil").setup({
  16. keymaps = {
  17. ["<C-p>"] = false,
  18. ["g?"] = "actions.show_help",
  19. ["<CR>"] = "actions.select",
  20. ["<C-s>"] = "actions.select_vsplit",
  21. ["<C-h>"] = "actions.select_split",
  22. ["<C-t>"] = "actions.select_tab",
  23. ["<C-c>"] = "actions.close",
  24. ["<C-l>"] = "actions.refresh",
  25. ["-"] = "actions.parent",
  26. ["_"] = "actions.open_cwd",
  27. ["`"] = "actions.cd",
  28. ["~"] = "actions.tcd",
  29. ["g."] = "actions.toggle_hidden",
  30. },
  31. -- Set to false if you still want to use netrw.
  32. default_file_explorer = true,
  33. delete_to_trash = true,
  34. -- Skip the confirmation popup for simple operations (:help oil.skip_confirm_for_simple_edits)
  35. skip_confirm_for_simple_edits = true,
  36. view_options = {
  37. natural_order = true,
  38. -- Show files and directories that start with "."
  39. show_hidden = false,
  40. -- This function defines what is considered a "hidden" file
  41. is_hidden_file = function(name)
  42. local ignore_folders = { "node_modules", "dist", "build", "coverage" }
  43. return vim.startswith(name, ".") or vim.tbl_contains(ignore_folders, name)
  44. end,
  45. wrap = true,
  46. },
  47. -- Configuration for the floating window in oil.open_float
  48. float = {
  49. padding = 2,
  50. max_width = 120,
  51. max_height = max_height(),
  52. border = "rounded",
  53. win_options = {
  54. winblend = 0,
  55. },
  56. },
  57. })
  58. nmap("-", require("oil").open, { desc = "Open parent directory" })
  59. vim.api.nvim_create_autocmd("User", {
  60. pattern = "OilActionsPost",
  61. callback = function(event)
  62. if event.data.actions.type == "move" then
  63. Snacks.rename.on_rename_file(event.data.actions.src_url, event.data.actions.dest_url)
  64. end
  65. end,
  66. })
  67. end
  68. return M