max397574 / better-escape.nvim

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

Is it possible to map `\\` using better-escape? #98

Closed echaya closed 2 months ago

echaya commented 2 months ago

I have tnoremap \\ <cmd>q<cr> in my config to quit from terminal mode without closing it (am using toggleterm). Is there a way to map it within better-escape please? Suggestion is welcome! Thanks in advance!

max397574 commented 2 months ago

well that should work like any normal mapping if you escape it properly

reopen if it doesn't

echaya commented 2 months ago

May be it is just me lacking knowledge about lua but how to do that please? This is waht i tried but not working

    t = {
      j = {
        k = "<C-\\><C-n>",
      },
      [[\]] = {
          [[\]] = function()
              vim.cmd("q")
          end
      },
    },
max397574 commented 2 months ago

I think it should be ["\\"] = ...

echaya commented 2 months ago

I think it should be ["\\"] = ...

Thanks, ["\\"] works! Now I see:

E5108: Error executing lua: vim/_editor.lua:431: nvim_exec2(): Vim(quit):E565: Not allowed to change text or change window
stack traceback:
    [C]: in function 'nvim_exec2'
    vim/_editor.lua:431: in function 'cmd'
    D:/Dropbox/neovim/config/nvim_config.lua:692: in function 'mapping'
    ...imfiles\plugged\better-escape.nvim/lua/better_escape.lua:141: in function <...imfiles\plugged\better-escape.nvim/lua/better_escape.lua:110>
"D:/dropbox/neovim/config/nvim_config.lua" 707L, 21023B
max397574 commented 2 months ago

that's a limitations with the mappings you can put the vim.cmd.q() inside a vim.schedule(function() ... end)

echaya commented 2 months ago

that's a limitations with the mappings you can put the vim.cmd.q() inside a vim.schedule(function() ... end)

Thanks much - really appreciate it!