Skip to content

How do I enable this when there's a *Markdown* file is opened, and disable this otherwise? #245

Answered by shortcuts
stevenxxiu asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, considering you'd like this to be triggered anytime a buffer type changes, I guess something like this would do it

vim.api.nvim_create_autocmd({ "BufEnter" }, {
    pattern = "*",
    callback = function()
        vim.schedule(function()
            local filetype = vim.api.nvim_buf_get_option(0, "filetype")
            local enabled =  _G.NoNeckPain.state ~= nil and _G.NoNeckPain.state.enabled

            if (filetype == "markdown" and not enabled) or (filetype ~= "markdown" and enabled) then
                return vim.cmd("NoNeckPain")
            end
        end)
    end,
})

it basically disables nnp if it's enabled and we are entering a non-markdown buffer, or enables it if it's…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by stevenxxiu
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants