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

Unable to autocommand ZenMode in init.lua (neovim 0.6.1)

Open ruvido opened this issue 2 years ago • 3 comments

Hi I'd like to automatically start ZenMode everytime a markdown file is opened. To that end I wrote to my init.lua (neovim 0.6.1):

vim.cmd [[
au FileType markdown,mkd ZenMode ]]

When a markdown is opened the plugin starts but the buffer is limited to the first page, ie I am unable to scroll down the file.

How am I supposed to call ZenMode? How can I call it together with other plugins (like Pencil)? This is my first init.lua, so hopefully the question does not sound too stupid. Thanks for your help

ruvido avatar Apr 04 '22 15:04 ruvido

Try using WinEnter instead:

autocmd VimEnter *.md :ZenMode

Hubro avatar Apr 11 '22 22:04 Hubro

in Neovim 0.7 WinEnter gives:

E5108: Error executing lua ...site/pack/paqs/start/zen-mode.nvim/lua/zen-mode/view.lua:209: Failed to switch to window 1000                                                                     
stack traceback:                                                                                                                                                                                
        [C]: in function 'nvim_set_current_win'                                                                                                                                                 
        ...site/pack/paqs/start/zen-mode.nvim/lua/zen-mode/view.lua:209: in function 'fix_hl'                                                                                                   
        ...site/pack/paqs/start/zen-mode.nvim/lua/zen-mode/view.lua:157: in function 'create'                                                                                                   
        ...site/pack/paqs/start/zen-mode.nvim/lua/zen-mode/view.lua:68: in function 'open'                                                                                                      
        ...site/pack/paqs/start/zen-mode.nvim/lua/zen-mode/view.lua:76: in function 'toggle'                                                                                                    
        [string ":lua"]:1: in main chunk 

VimEnter seemed to work then stopped, BufEnter does not work, WinBufEnter the cursor is in the wrong place. What is going on here?

David-Else avatar May 24 '22 10:05 David-Else

past vim.cmd('autocmd VimEnter *.md :ZenMode') in the .config/nvim/after/ftplugin/markdown.lua worked for me

ronateds avatar Feb 09 '23 01:02 ronateds

The layout will only be correct if I have this code in place:

vim.cmd('autocmd VimEnter *.md,*.txt :ZenMode')

vim.api.nvim_create_autocmd(
  { "VimEnter", "BufReadPost" },
  {
    pattern = { "*.md", "*.txt", },
    callback = function()
      local zen_mode = require("zen-mode")

      zen_mode.open()
    end
  }
)

It'll then work when:

  • Opening a file from the terminal (e.g. nvim README.md)
  • Opening a file within Neovim (e.g. :e README.md)

What I noticed:

  • If I remove vim.cmd('autocmd VimEnter *.md,*.txt :ZenMode'), one of the use cases above will no longer work.
  • If I remove "VimEnter" from nvim_create_autocmd, it will also no longer work.
  • Adding just 2 times vim.cmd('autocmd with VimEnter and BufReadPost also doesn't work.

Any idea why this could be the case?

alycklama avatar Apr 01 '24 15:04 alycklama