m4xshen / hardtime.nvim

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

j/k function keymap blocks navigation #52

Closed serranomorante closed 11 months ago

serranomorante commented 11 months ago

Describe the bug Out of pure ignorance on my part, why does this keymap work correctly:

vim.keymap.set({ "n", "x" }, "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { noremap = true, expr = true, desc = "Move down by display lines" })
vim.keymap.set({ "n", "x" }, "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { noremap = true, expr = true, desc = "Move up by display lines" })

while this one completely blocks j/k navigation:

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

Both keymaps work correctly without hardtime.nvim!

Config options

To Reproduce Steps to reproduce the behavior:

  1. Use the second presented keymap
  2. Try to navigate with j/k

Expected behavior Both keymaps should be valid to use on hardtime.

m4xshen commented 11 months ago

Thanks for the feedback!