Repeat movement commands using n
in the same vein that .
repeats action commands.
nvim-better-n
attempts address a problem with Vim, which is that almost every
single binding is used by default, for (often) very niche actions. I want to be
able to reuse convenient bindings for similar things, reducing both mental
overhead as well as opening up more bindings, allowing Vim to be more
ergonomic.
It does this by rebinding n
(which is a rather convenient binding), so that
it used for multiple different movement commands, in the same vein .
repeats
action commands.
For example, if we jump to the next hunk, using ]h
, we can repeat
that command using n
, allowing for far easier "scrolling" using that motion
without coming up with a bind that is easier to repeat.
Using this binding for that motion would, without this plugin, be rather cumbersome in the cases were you wanted to press it multiple times.
It should also be noted that this frees up both ;
, and ,
for other actions,
as n
will instead handle their current task.
Install as usual, using your favourite plugin manager.
use "jonatan-branting/nvim-better-n"
require("better-n").setup(
{
-- These are default values, which can be omitted.
-- By default, the following mappings are made repeatable using `n` and `<S-n>`:
-- `f`, `F`, `t`, `T`, `*`, `#`, `/`, `?`
disable_default_mappings = false,
}
)
vim.nvim_create_autocmd("User", {
pattern = "BetterNMappingExecuted",
callback = function(args)
-- args.data.key and args.data.mode are available here
end
})
-- You create repeatable mappings like this:
local hunk_navigation = require("better-n").create(
{
next = require("gitsigns").next_hunk,
previous = require("gitsigns").prev_hunk
}
)
vim.keymap.set({ "n", "x" }, "]h", hunk_navigation.next)
vim.keymap.set({ "n", "x" }, "[h", hunk_navigation.previous)