-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow opening the selected file in a vertical split
feat: allow adding custom keymaps specific to the yazi buffer The user can also modify the configuration all of the hooks, giving them a lot of power to customize the behavior of the plugin. refactor: the config's default functions are in a separate file
- Loading branch information
1 parent
ac87720
commit 1bb74ca
Showing
8 changed files
with
109 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,40 @@ | ||
local openers = require('yazi.openers') | ||
|
||
local M = {} | ||
|
||
---@return YaziConfig | ||
function M.default() | ||
---@type YaziConfig | ||
return { | ||
open_for_directories = false, | ||
chosen_file_path = '/tmp/yazi_filechosen', | ||
events_file_path = '/tmp/yazi.nvim.events.txt', | ||
open_file_function = function(chosen_file) | ||
vim.cmd(string.format('edit %s', chosen_file)) | ||
end, | ||
open_file_function = openers.open_file, | ||
set_keymappings_function = M.default_set_keymappings_function, | ||
hooks = { | ||
---@diagnostic disable-next-line: unused-local | ||
yazi_opened = function(_preselected_path) end, | ||
---@diagnostic disable-next-line: unused-local | ||
yazi_closed_successfully = function(_chosen_file) end, | ||
yazi_opened_multiple_files = function(chosen_files) | ||
-- show the items in the quickfix list | ||
vim.fn.setqflist({}, 'r', { | ||
title = 'Yazi', | ||
items = vim.tbl_map(function(file) | ||
return { | ||
filename = file, | ||
lnum = 1, | ||
text = file, | ||
} | ||
end, chosen_files), | ||
}) | ||
|
||
-- open the quickfix window | ||
vim.cmd('copen') | ||
end, | ||
yazi_opened = function() end, | ||
yazi_closed_successfully = function() end, | ||
yazi_opened_multiple_files = openers.send_files_to_quickfix_list, | ||
}, | ||
|
||
floating_window_scaling_factor = 0.9, | ||
yazi_floating_window_winblend = 0, | ||
} | ||
end | ||
|
||
---@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 | ||
|
||
-- select the current file in yazi and close it (enter is the default | ||
-- keybinding for selecting a file) | ||
vim.api.nvim_feedkeys( | ||
vim.api.nvim_replace_termcodes('<enter>', true, false, true), | ||
'n', | ||
true | ||
) | ||
end, { buffer = yazi_buffer }) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local M = {} | ||
|
||
---@param chosen_file string | ||
function M.open_file(chosen_file) | ||
vim.cmd(string.format('edit %s', chosen_file)) | ||
end | ||
|
||
function M.open_file_in_vertical_split(chosen_file) | ||
vim.cmd(string.format('vsplit %s', chosen_file)) | ||
end | ||
|
||
---@param chosen_files string[] | ||
function M.send_files_to_quickfix_list(chosen_files) | ||
vim.fn.setqflist({}, 'r', { | ||
title = 'Yazi', | ||
items = vim.tbl_map(function(file) | ||
return { | ||
filename = file, | ||
lnum = 1, | ||
text = file, | ||
} | ||
end, chosen_files), | ||
}) | ||
|
||
-- open the quickfix window | ||
vim.cmd('copen') | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters