oil.nvim icon indicating copy to clipboard operation
oil.nvim copied to clipboard

Add argument to open Oil in Preview-Mode

Open jdsee opened this issue 2 years ago • 2 comments

Did you check existing requests?

  • [X] I have searched the existing issues

Describe the feature

It would be great if open had an argument for enabling preview mode as soon as Oil opens.

Suggestion:

oil.open({
  dir = '...',
  preview = true,
})

Provide background

I couldn't find a way to open Oil with preview-mode activated initially.

I tried the following but preview triggers too early this way:

require('oil').open()
require('oil.actions').preview()

What is the significance of this feature?

nice to have

Additional details

Edit: This is just an issue for opening Oil for the first time in a session. So maybe it would be better to offer an option for setup to enable preview by default.

jdsee avatar Mar 28 '24 18:03 jdsee

It will be great If can support open in preview mode. Meanwhile, I'm using this to achieve it.

vim.keymap.set('n', '-', function()
  require('oil').open()

  require('oil.util').run_after_load(0, function()
    oil.select({ preview = true })
  end)
end)

musicq avatar Apr 11 '24 16:04 musicq

This is what I'm using as a workaround to try opening the preview only after its available

vim.keymap.set('n', '-', function()
  oil.open()

  -- Wait until oil has opened, for a maximum of 1 second.
  vim.wait(1000, function()
    return oil.get_cursor_entry() ~= nil
  end)
  if oil.get_cursor_entry() then
    oil.open_preview()
  end
end)

airkoala avatar May 10 '24 02:05 airkoala