max397574 / better-escape.nvim

Map keys without delay when typing
GNU General Public License v3.0
629 stars 19 forks source link

Disable within certain filetypes? #48

Open Machine-Maker opened 1 year ago

Machine-Maker commented 1 year ago

It'd be nice if there was a setting for a condition function to be called to see if the mapping should be "applied". My usecase specifically is disabling it within TelescopePrompts

Sam-programs commented 3 months ago

I think you can do it using a function like this:

mappings = {
    i = {
        j = {
            k = function()
                -- Escape insert mode when jk is pressed
                if vim.bo.filetype == 'Yourfiletype' then
                    -- Type 'jk' normally when inside filetype 'Yourfiletype'
                    -- <c-v> is used to avoid mappings
                    return "<c-v>j<c-v>k"
                end
                return "<esc>"
            end
        }
    }
}