[question] When toggling preview, how to vertical resize width of the selector?
The following idea should give an idea of what I am trying to do. The issue is that the vim.api.nvim_command("vertical resize 40") doesnt seem to work.
keymaps = {
['<C-p>'] = {
callback = function()
local oil = require("oil")
oil.open_preview({ vertical = true, split = 'botright' })
vim.api.nvim_command("vertical resize 40")
end
}
},
I am trying to go from this:
to this:
First thing to try is put the resize in a callback, because oil.open_preview (like many oil functions, unfortunately) is async.
keymaps = {
['<C-p>'] = {
callback = function()
local oil = require("oil")
oil.open_preview({ vertical = true, split = 'botright' }, function(err)
if not err then
vim.api.nvim_command("vertical resize 40")
end
end)
end
}
},
Can you also resize the preview on floating mode? Not sure how to get the preview window reference.
Sorry, I was so thrilled it worked that I forgot to reply.
Also, I got another question if you dont mind (last question I promise):
Is there a way to know whether the previewer is currently open or not?
I am trying to make <c-p> toggle the previewer on/off.
@Sebastian-Nielsen the default preview keymap should be a toggle, but to find out if the preview window is open you can just iterate through all the windows in the tab and check if any of them are the preview window. You can see where we're doing that here (with some extra logic to tell if the preview window is being managed by oil or some other plugin).
https://github.com/stevearc/oil.nvim/blob/5b6068aad7d2057dd399fac73b7fb2cdf23ccd6e/lua/oil/util.lua#L704-L718
@rafaelpirolla you can also use this to get a reference to the preview window when it's floating