From fc04774f4e7a3f613c5a9e57f909ef7197d8afe2 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 13 Aug 2026 13:48:25 +0100 Subject: [PATCH] Add memorable command :MDPreview {start,stop} --- lua/plugins/utilities.lua | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lua/plugins/utilities.lua b/lua/plugins/utilities.lua index 404741c..3b12709 100644 --- a/lua/plugins/utilities.lua +++ b/lua/plugins/utilities.lua @@ -50,13 +50,41 @@ return { { 'vihu/penview.nvim', ft = 'markdown', + cmd = 'MDPreview', run = function() require("penview.build").install() end, config = function() - require('penview').setup({ + local penview = require('penview') + penview.setup({ browser = 'firefox', }) + + -- :MDPreview {start,stop} previewing the current file in the browser + local commands = { start = 'PenviewStart', stop = 'PenviewStop' } + local actions = vim.tbl_keys(commands) + table.sort(actions) + + vim.api.nvim_create_user_command('MDPreview', function(opts) + local command = commands[opts.args] + if not command then + vim.api.nvim_echo({ + { + 'MDPreview: expected {' .. table.concat(actions, ',') .. '}', + "ErrorMsg" + } + }, true, {}) + return + end + vim.cmd(command) + end, { + nargs = 1, + complete = function(lead) + return vim.tbl_filter(function(action) + return vim.startswith(action, lead) + end, actions) + end, + }) end, }, }