Skip to content

Commit

Permalink
feat: make it easier to completely override the default keymappings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikavilpas committed May 21, 2024
1 parent a31a74e commit 96ff34a
Showing 1 changed file with 39 additions and 21 deletions.
60 changes: 39 additions & 21 deletions lua/yazi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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' }, '<c-v>', 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' }, '<c-x>', 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' }, '<c-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

Expand All @@ -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

0 comments on commit 96ff34a

Please sign in to comment.