How do I enable this when there's a *Markdown* file is opened, and disable this otherwise? #245
-
I tried the following. This does enable no-neck-pain. However, it jumps to the left buffer that no-neck-pain uses for padding, instead of the main document. vim.api.nvim_create_autocmd({'BufEnter', 'BufWinEnter', 'BufLeave', 'BufWinLeave'}, {
pattern = { '*.md' },
command = ':NoNeckPain',
}) If relevant, if use this with bufferline. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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 disabled and we are moving to a markdown buffer I'll find a cleaner way to make it work natively by specifying filetypes! |
Beta Was this translation helpful? Give feedback.
-
A simple modification of the answer, so that neo-tree works: vim.api.nvim_create_autocmd({ 'BufEnter' }, {
pattern = '*',
callback = function()
vim.schedule(function()
if _G.NoNeckPain == nil then
return
end
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 filetype ~= 'neo-tree' and filetype ~= 'no-neck-pain' and enabled)
then
return vim.cmd('NoNeckPain')
end
end)
end,
})
return {
'shortcuts/no-neck-pain.nvim',
opts = {
mappings = {
enabled = true,
},
},
} |
Beta Was this translation helpful? Give feedback.
Hey, considering you'd like this to be triggered anytime a buffer type changes, I guess something like this would do it
it basically disables nnp if it's enabled and we are entering a non-markdown buffer, or enables it if it's…