feature request: Pick window to open file into
Did you check existing requests?
- [X] I have searched the existing issues
Describe the feature
When opening a file using <CR> oil.nvim just populates the first window it can find.
It would be awesome if it were possible to pick the window the file should be loaded into.
I'd happily hit a number on my keyboard (1-9) to select the window before i hit the <CR> button or do some special key-combo to achieve this without showing any fancy stuff.
Provide background
In other plugins like Luatree the user can pick where to open the file under the cursor. right after hitting <CR> the line under each file is replaced with a Letter. hitting the letter on the keyboard then loads the file into that window:
https://github.com/stevearc/oil.nvim/assets/3583395/cface79e-b3c1-47b8-bb6f-76039998a701
What is the significance of this feature?
nice to have
Additional details
No response
Oil.nvim just need to expose api to allow user pass a winid to Oil.select.
My current workaround solution is this:
--- put this in after/ftplugin/oil.lua
local bufnr = vim.api.nvim_get_current_buf() -- oil bufnr
--- buffer local keymap
local set = function(mods, lhs, rhs)
vim.keymap.set(mods, lhs, rhs, { buffer = bufnr })
end
set('n', '<C-o>', function()
local oil = require('oil')
local entry = oil.get_cursor_entry()
if entry.type ~= 'file' then
return
end
--- pick a window by using window-picker plugin.
local win = require('window-picker').pick_window({
autoselect_one = true,
-- hint = 'floating-big-letter',
include_current_win = true,
})
if win then
local lnum = vim.api.nvim_win_get_cursor(0)[1]
local winnr = vim.api.nvim_win_get_number(win)
vim.cmd(winnr .. 'windo buffer ' .. bufnr)
vim.api.nvim_win_call(win, function()
vim.api.nvim_win_set_cursor(win, { lnum, 1 })
oil.select({
close = false,
}, function() end)
end)
return
end
end, {
desc = 'Pick win to open file',
nowait = true,
noremap = true,
})
I would also love to see an integration with window_picker!
I would also love to see an integration with
window_picker!
This is what I am thinking. I used to use this with neotree popup and I really miss it!