folke / zen-mode.nvim

🧘 Distraction-free coding for Neovim
Apache License 2.0
1.72k stars 50 forks source link

How to Exit ZenMode With ':q'? #35

Closed FOSSilizedDaemon closed 3 months ago

FOSSilizedDaemon commented 3 years ago

I noticed that zen-mode simply untoggles itself when exiting a buffer running zen-mode with :q. This seems to be common in Goyo-like plugins, but as I use zen-mode for mainly writing this leads to me having to exit twice. Is there any official way to have :q and ZQ and such exit zen-mode instead of toggling it?

folke commented 3 years ago

You could do :qa instead?

ghost commented 3 years ago

I had the same problem as @FOSSilizedDaemon: when I execute :q, rather than exiting zen mode, I wish to quit the buffer (and hide it, as I use set hidden). Using :qa doesn't solve the problem because it will close all buffers and close vim (instead of just quitting the buffer I'm editing).

To get this to work, I learned from this related code for the goyo plugin, and added this code to the zen mode callbacks:

require("zen-mode").setup {
  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,
}

@folke why doesn't zen mode automatically exit plugins with :q? I think that would be useful so that :q still works the same as in regular buffers, and then :ZenMode is the command used to toggle zen mode.


P.S. The easiest solution is to just use :bdelete instead of :q, however with that I get a segmentation fault in my current nvim configuration. I won't open an new issue for that segmentation error because I couldn't reliably reproduce it with a mini.vim configuration.

github-actions[bot] commented 3 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 3 months ago

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