zen-mode.nvim
zen-mode.nvim copied to clipboard
Unable to autocommand ZenMode in init.lua (neovim 0.6.1)
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
Try using WinEnter
instead:
autocmd VimEnter *.md :ZenMode
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?
past vim.cmd('autocmd VimEnter *.md :ZenMode')
in the .config/nvim/after/ftplugin/markdown.lua
worked for me
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"
fromnvim_create_autocmd
, it will also no longer work. - Adding just 2 times
vim.cmd('autocmd
withVimEnter
andBufReadPost
also doesn't work.
Any idea why this could be the case?