zen-mode.nvim icon indicating copy to clipboard operation
zen-mode.nvim copied to clipboard

Method For Quitting When Closing ZenMode Window?

Open FOSSilizedDaemon opened this issue 3 years ago • 4 comments

Hello,

I use nvim for mostly writing not coding and am interested in using this plugin to have a more word processor feel when writing. The one big annoyance I have with using this plugin is that when I close the ZenMode window or use :q to exit it just toggles the ZenMode window instead of exiting from nvim. Is there any way to make it so that nvim exits instead of just toggling the window?

FOSSilizedDaemon avatar Jun 09 '22 21:06 FOSSilizedDaemon

What if you write :qa?

Hubro avatar Jul 28 '22 12:07 Hubro

Hi @FOSSilizedDaemon, It's a bit of a hack but you can stick the following into your into your Zen Mode 🧘 config:

require("zenmode").setup({
    -- Your existing config:
    ...

    -- At the end of the file add this:
    on_open = function(_)
        vim.cmd("cabbrev <buffer> q let b:quitting = 1 <bar> q")
        vim.cmd("cabbrev <buffer> wq let b:quitting = 1 <bar> wq")
    end,
    on_close = function()
        if vim.b.quitting == 1 then
            vim.b.quitting = 0
            vim.cmd("q")
        end
    end,
})

This temporarily redefines :q and :wq to set the 'quitting' variable to 1. And if the 'quitting' variable is set to one, then the on_close function quits neovim for you.

CodedCraft avatar Jul 30 '22 13:07 CodedCraft

I had tried "autocmd WinLeave wqall" added in the command line options when using nvim as a word processor. The issues with this is if you open another window, for example opening up spell check, it will close the all the buffers.

I think the above would work if it could be turned on and off. Maybe adding a command that will enable the aboveZenModeWordProcess and then you could start vim with nvim +"ZenModeWordProcess" +"ZenMode"

BerkeleyTrue avatar Dec 15 '23 07:12 BerkeleyTrue