How to toggle nvim-autopairs

Sometimes I need to disable nvim-autopairs but I don’t know to do it.

I would like a function that I can put on my utils.lua and bind it to a shortcut.

Instead of toggling, I added a config to disable during macro recordings:

disable_in_macro = true,

But I still would like to create a function to toggle the plugin.

I have read the nvim-autopairs but I did not see an option to toggle the plugin momentarily, it would possibly be my poor English knowledge, please tell me if I am wrong!

if you click that link above the first thing you see is a function to toggle autopairs.

require(‘nvim-autopairs’).disable()
require(‘nvim-autopairs’).enable()

Thinking better, I guess the problem is that I searched for the word toggle when I pressed Ctrl-f in my browser. It would be interesting to have this option!

Looking at the code of the plugin, this should work:

function toggle_autopairs()
    local autopairs = require'nvim-autopairs'

    if autopairs.state.disable then
        autopairs.enable()
    else
        autopairs.disable()
    end
end
1 Like

It seems that the lua cache does not allow to reload the plugin once is unloaded, or something like that!