stevearc / oil.nvim

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

How To: key bind to chmod +x on current entry #405

Closed madhat2r closed 1 month ago

madhat2r commented 1 month ago

Is there a way to create a keybinding that would chmod +x on current entry?

stevearc commented 1 month ago

Sure, it's just a text find-and-replace

vim.keymap.set("n", "<leader>+x", function()
  local cursor = vim.api.nvim_win_get_cursor(0)
  local lnum = cursor[1]
  local line = vim.api.nvim_buf_get_lines(0, lnum - 1, lnum, true)[1]
  line = line:gsub(" ([r%-][w%-]).([r%-][w%-]).([r%-][w%-]). ", function(u, g, p)
    return " " .. u .. "x" .. g .. "x" .. p .. "x "
  end)
  vim.api.nvim_buf_set_lines(0, lnum - 1, lnum, true, { line })
end)
madhat2r commented 1 month ago

That is perfect Steven, thank you!