folke / zen-mode.nvim

🧘 Distraction-free coding for Neovim
Apache License 2.0
1.66k stars 46 forks source link

Method For Quitting When Closing ZenMode Window? #54

Closed FOSSilizedDaemon closed 2 months ago

FOSSilizedDaemon commented 2 years ago

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?

Hubro commented 2 years ago

What if you write :qa?

CodedCraft commented 2 years ago

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.

BerkeleyTrue commented 9 months ago

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"

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 2 months ago

This issue was closed because it has been stalled for 7 days with no activity.