toppair / peek.nvim

Markdown preview plugin for Neovim
MIT License
651 stars 44 forks source link

Recipe for permanently previewing an arbitrary file #59

Open snoblenet opened 7 months ago

snoblenet commented 7 months ago

Could the README.md please include a recipe for permanently previewing an arbitrary Markdown file, even if that file is not currently open in a buffer.

toppair commented 7 months ago

If you're okay with loading file into a buffer just once, then you could use a user command e.g.:

require('peek').setup({ close_on_bdelete = false, auto_load = false })

vim.api.nvim_create_user_command('PeekOpenFile', function(arg)
  vim.api.nvim_command('edit ' .. arg.args)
  require('peek').open()
  vim.api.nvim_command('bdelete')
end, { nargs = 1, complete = 'file' })

And you would use it like so: :PeekOpenFile path/to/file.md

Not ideal, but it's currently not possible to load preview without loading the file into a buffer. And I don't think something like that should / needs to be implemented.