Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JamesMowery opened this issue Jan 21, 2024 · 8 comments
Closed

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

JamesMowery opened this issue Jan 21, 2024 · 8 comments

Comments

@JamesMowery
Copy link

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

@JamesMowery
Copy link
Author

JamesMowery commented Jan 21, 2024

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
Copy link
Author

JamesMowery commented Jan 21, 2024

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
Copy link
Owner

m4xshen commented Jan 21, 2024

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 })

@m4xshen m4xshen closed this as completed Feb 2, 2024
@spa5k
Copy link

spa5k commented Apr 20, 2024

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" },
    },
},

@jyeharry
Copy link

@spa5k I this actually maps the "n" key to gk. You're fix worked for me until I searched for something and pressed n to cycle through the occurrences, but instead my cursor was just moving up the screen. It did fix j and k not working though, but I don't think it fixed it for the reason we thought it would and since n is now broken I don't think its an ideal fix.

@jyeharry
Copy link

I've got this in my config:

return {
  {
    "m4xshen/hardtime.nvim",
    dependencies = { "MunifTanjim/nui.nvim" },
    opts = {},
    command = "Hardtime",
    event = "VeryLazy",
    keys = {
      {
        "j",
        function()
          return vim.v.count > 0 and "j" or "gj"
        end,
        mode = { "n", "x" },
      },
      {
        "k",
        function()
          return vim.v.count > 0 and "k" or "gk"
        end,
        mode = { "n", "x" },
      },
    },
  },
}

However this only seems to work after I open a second file. Upon running nvim some/file the plugin doesn't work and the j and k keys are unresponsive. After opening a second file it all works as expected. Any suggestions @m4xshen?

@jyeharry
Copy link

This is my fix:

return {
  {
    "m4xshen/hardtime.nvim",
    dependencies = { "MunifTanjim/nui.nvim" },
    opts = {},
    keys = {
      {
        "j",
        function()
          vim.cmd("Hardtime enable")
          return vim.v.count > 0 and "j" or "gj"
        end,
        mode = { "n", "x" },
      },
      {
        "k",
        function()
          vim.cmd("Hardtime enable")
          return vim.v.count > 0 and "k" or "gk"
        end,
        mode = { "n", "x" },
      },
    },
  },
}

The first press of j or k doesn't do anything, after that they work as normal until blocked by hardtime. I feel like there should be a simpler fix though. Unfortunately I'm not super familiar with exactly how to setup plugins the lazy.nvim way and since this works I'm just gonna stick with it for now.

@jyeharry
Copy link

jyeharry commented Dec 20, 2024

This solution works. It's pretty much the same solution originally provided by @JamesMowery however it may be because this solution has lazy = false in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants