m4xshen / hardtime.nvim

Establish good command workflow and quit bad habit
MIT License
1.38k stars 26 forks source link

Hints containing modifier do not trigger #41

Closed dtomvan closed 1 year ago

dtomvan commented 1 year ago

Describe the bug When defining a hint with a key combination containing a modifier, for example <C-W>, it will not trigger.

Config options Consider the following hint:

hints = {
    ['<C-W>[hjkl]'] = {
        message = function(keys)
            return 'Use <A-' .. keys:sub(7) .. '> instead of ' .. keys
        end,
        length = 2,
    },
}

Expected behavior When typing <C-W>h, the hint "Use instead of h" should be shown.

Screenshots N/A

Additional context N/A

m4xshen commented 1 year ago

3 problems:

  1. - is a magic characters so you need to escape it. (see Programming in Lua)
  2. The length is the length of the final matched string, so it should be 6.
  3. key:sub(7) should be key:sub(6) to get the final character of the string.
["<C%-W>[hjkl]"] = {
   message = function(keys)
      return "Use <A-" .. keys:sub(6) .. "> instead of " .. keys
   end,
   length = 6,
},

This should work.

m4xshen commented 1 year ago

Btw, I am really happy to know that there are people using the custom hint configuration!

Please consider sharing your custom hints in the discussion. I am curious about what other people have created!

dtomvan commented 1 year ago

3. key:sub(6) should be key:sub(7) to get the final character of the string.

<C-W>h
123456 <<<

Nope, it is really 6. Thanks for helping, though. It works now!

Also, thank you so much for adding all of the builtin hints. They are really useful and must've taken a long time to come up with and write.