m4xshen / hardtime.nvim

Establish good command workflow and quit bad habit
MIT License
1.35k stars 27 forks source link

Not picking up j/k repeating when using LazyVim distro #74

Closed JamesMowery closed 7 months ago

JamesMowery commented 7 months ago

Repeated h/j key presses are not being picked up when using LazyVim. Any advice on how to resolve?

JamesMowery commented 7 months ago

I was able to resolve by doing the following in my hardtime.lua plugin (per issue with another distro):

return {
  "m4xshen/hardtime.nvim",
  command = "Hardtime",
  event = "BufEnter",
  dependencies = {
    "MunifTanjim/nui.nvim",
    "nvim-lua/plenary.nvim",
  },
  keys = {
    { "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"' },
    { "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"' },
  },
  opts = {},
}

Are there any other change to LazyVim I need to make to ensure no conflicts with this issue and potentially any others?

JamesMowery commented 7 months ago

Update: The above change actually did not resolve the issue. Getting the following issue with the command box popping up on LazyVim when using j and k in a file now. Very strange.

Screenshot_20240120_225153

Screenshot_20240120_225431

m4xshen commented 7 months ago

v:count || mode(1)[0:1] == "no" ? "j" : "gj"

This kind of mapping only work for Vim-style mapping when using :map. For Lua you should convert this into a function.

Example:

vim.keymap.set({ "n", "x" }, "j", function()
   return vim.v.count > 0 and "j" or "gj"
end, { noremap = true, expr = true })
vim.keymap.set({ "n", "x" }, "k", function()
   return vim.v.count > 0 and "k" or "gk"
end, { noremap = true, expr = true })
spa5k commented 4 months ago

For someone coming to this later on, this works without problem -

{
    'm4xshen/hardtime.nvim',
    dependencies = { 'MunifTanjim/nui.nvim', 'nvim-lua/plenary.nvim' },
    opts = {},
    command = 'Hardtime',
    event = 'BufEnter',
    keys = {
        { 'n', 'j',  '<cmd>Hardtime<CR>', desc = "Hardtime" },
        { 'n', 'k',  '<cmd>Hardtime<CR>', desc = "Hardtime" },
        { 'n', 'gj', '<cmd>Hardtime<CR>', desc = "Hardtime" },
        { 'n', 'gk', '<cmd>Hardtime<CR>', desc = "Hardtime" },
    },
},