From 96ff34ab383ae93609112e4e84b7dacd20114614 Mon Sep 17 00:00:00 2001 From: Mika Vilpas Date: Tue, 21 May 2024 18:55:51 +0300 Subject: [PATCH] feat: make it easier to completely override the default keymappings There's still a bit of manual work involved, and I think in the future it might be necessary to add some smarter way of overriding only some of the keymappings. Not sure what the best way to do this would be. Partial overrides could also be added. --- lua/yazi/config.lua | 60 +++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/lua/yazi/config.lua b/lua/yazi/config.lua index 942dada..fb2ad81 100644 --- a/lua/yazi/config.lua +++ b/lua/yazi/config.lua @@ -22,37 +22,22 @@ function M.default() } end +--- This sets the default keymappings for yazi. If you want to use your own +--- keymappings, you can set the set_keymappings_function in your config. Copy +--- this function as the basis. ---@param yazi_buffer integer ---@param config YaziConfig function M.default_set_keymappings_function(yazi_buffer, config) vim.keymap.set({ 't' }, '', function() - config.open_file_function = openers.open_file_in_vertical_split - config.hooks.yazi_opened_multiple_files = function(chosen_files) - for _, chosen_file in ipairs(chosen_files) do - config.open_file_function(chosen_file, config) - end - end - M.select_current_file_and_close_yazi() + M.open_file_in_vertical_split(config) end, { buffer = yazi_buffer }) vim.keymap.set({ 't' }, '', function() - config.open_file_function = openers.open_file_in_horizontal_split - config.hooks.yazi_opened_multiple_files = function(chosen_files) - for _, chosen_file in ipairs(chosen_files) do - config.open_file_function(chosen_file, config) - end - end - M.select_current_file_and_close_yazi() + M.open_file_in_horizontal_split(config) end, { buffer = yazi_buffer }) vim.keymap.set({ 't' }, '', function() - config.open_file_function = openers.open_file_in_tab - config.hooks.yazi_opened_multiple_files = function(chosen_files) - for _, chosen_file in ipairs(chosen_files) do - config.open_file_function(chosen_file, config) - end - end - M.select_current_file_and_close_yazi() + M.open_file_in_tab(config) end, { buffer = yazi_buffer }) end @@ -68,4 +53,37 @@ function M.select_current_file_and_close_yazi() ) end +---@param config YaziConfig +function M.open_file_in_vertical_split(config) + config.open_file_function = openers.open_file_in_vertical_split + config.hooks.yazi_opened_multiple_files = function(chosen_files) + for _, chosen_file in ipairs(chosen_files) do + config.open_file_function(chosen_file, config) + end + end + M.select_current_file_and_close_yazi() +end + +---@param config YaziConfig +function M.open_file_in_horizontal_split(config) + config.open_file_function = openers.open_file_in_horizontal_split + config.hooks.yazi_opened_multiple_files = function(chosen_files) + for _, chosen_file in ipairs(chosen_files) do + config.open_file_function(chosen_file, config) + end + end + M.select_current_file_and_close_yazi() +end + +---@param config YaziConfig +function M.open_file_in_tab(config) + config.open_file_function = openers.open_file_in_tab + config.hooks.yazi_opened_multiple_files = function(chosen_files) + for _, chosen_file in ipairs(chosen_files) do + config.open_file_function(chosen_file, config) + end + end + M.select_current_file_and_close_yazi() +end + return M