Skip to content

Commit

Permalink
feat: allow opening the selected file in a horizontal split
Browse files Browse the repository at this point in the history
  • Loading branch information
mikavilpas committed Apr 13, 2024
1 parent 1bb74ca commit f3847fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Using lazy.nvim:
These are the default keybindings that are available when yazi is open:

- `<c-v>`: open the selected file in a vertical split
- `<c-s>`: open the selected file in a horizontal split

## About my fork

Expand All @@ -108,5 +109,6 @@ So far I have done some maintenance work and added a bunch of features:
- feat: allow customizing the method of opening the selected file in neovim
- feat: can send multiple opened files to the quickfix list
- feat: can open a file in a vertical split
- feat: can open a file in a horizontal split

If you'd like to collaborate, contact me via GitHub issues.
14 changes: 11 additions & 3 deletions lua/yazi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ 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

local function select_current_file_and_close_yazi()
-- 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

vim.keymap.set({ 't' }, '<c-v>', function()
config.open_file_function = openers.open_file_in_vertical_split
select_current_file_and_close_yazi()
end, { buffer = yazi_buffer })

vim.keymap.set({ 't' }, '<c-s>', function()
config.open_file_function = openers.open_file_in_horizontal_split
select_current_file_and_close_yazi()
end, { buffer = yazi_buffer })
end

Expand Down
4 changes: 4 additions & 0 deletions lua/yazi/openers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ function M.open_file_in_vertical_split(chosen_file)
vim.cmd(string.format('vsplit %s', chosen_file))
end

function M.open_file_in_horizontal_split(chosen_file)
vim.cmd(string.format('split %s', chosen_file))
end

---@param chosen_files string[]
function M.send_files_to_quickfix_list(chosen_files)
vim.fn.setqflist({}, 'r', {
Expand Down

0 comments on commit f3847fd

Please sign in to comment.