jonatan-branting / nvim-better-n Goto Github PK
View Code? Open in Web Editor NEWA more versatile n(ext) key in neovim, repeat movement commands.
License: MIT License
A more versatile n(ext) key in neovim, repeat movement commands.
License: MIT License
As I understand it, this makes me loose the functionality to continue the previous stored search result.
For example, if I have searched for all exact occurrences with *
for word /\<example\>
, n
will not continue searching for /\<example\>
after I have registered another action under n
.
is this correct?
Ideas:
Hi, thanks for putting your plugin online, I really like the idea.
One problem I'm having is that any keybindings registered with better_n lose their which-key description.
So for example I have many mappings that start with [ or ] (I'm using largely the AstroNvim default).
But if I register any with better_n, they get the default label "better_n_remap".
Here is the which-key menu that appears after typing "[", before enabling better_n.
And here is the same menu when better_n has been installed and some of the "[" keybindings have been registered with it:
Here is the "next git hunk" mapping in the default AstroNvim config:
maps.n["]g"] = { function() require("gitsigns").next_hunk() end, desc = "Next Git hunk" }
Is there any way to pass through the "desc" field when using better_n, in order for which-key to still be useful?
Thanks
When I use default settings, they are re-mapping [FfTf] keys to better-n functions.
However, in case of recording macros, recorded 'f' were not reproduced when macro is called.
Here is a workaround to disable keys in config:
["f"] = {cmdline = true},
["t"] = {cmdline = true},
["F"] = {cmdline = true},
["T"] = {cmdline = true},
p.s. Maybe it's worth to find another option to make clear how to disable better-n
calls and propagating original nvim calls. I've only managed to figure this out after digging into code.
Thanks
Here's my original config:
require("better-n").setup {
callbacks = {
mapping_executed = function(_mode, _key)
-- Clear highlighting, indicating that `n` will not goto the next
-- highlighted search-term
vim.cmd [[ nohl ]]
end
},
mappings = {
-- I want `n` to always go forward, and `<s-n>` to always go backwards
["#"] = {previous = "n", next ="<s-n>"},
["F"] = {previous = ";", next = ","},
["T"] = {previous = ";", next = ","},
-- Setting `cmdline = true` ensures that `n` will only be
-- overwritten if the search command is succesfully executed
["?"] = {previous = "n", next ="<s-n>", cmdline = true},
-- I have <leader>hn/hp bound to git-hunk-next/prev
["]]"] = {previous = "[[", next = "]]"},
["[["] = {previous = "[[", next = "]]"},
["]m"] = {previous = "[m", next = "]m"},
["[m"] = {previous = "[m", next = "]m"},
}
}
I don't understand how to write new version config.
I can't even use default mapping with n
during search or press *
on a word, no matter disable_default_mappings is set to true or false.
Due to fundamental changes done in #10, the options opts.mappings
and opts.callbacks
are no longer supported.
Instead, you should create repeatable mappings manually 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)
Currently there is no support for buffer local mappings, which disallows us from registering mappings which were set through for example https://github.com/nvim-treesitter/nvim-treesitter-textobjects.
This is unfortunate as binding e.g. ]f
to goto the next function is powerful, and allowing this key to be repeated is beneficial.
For example, when the cursor is at the begin of the following line:
import sys
and I press v
, f
, s
it only executes s
during visual mode, f
doesn't work.
Here's my config:
require("better-n").setup {
callbacks = {
mapping_executed = function(_mode, _key)
-- Clear highlighting, indicating that `n` will not goto the next
-- highlighted search-term
vim.cmd [[ nohl ]]
end
},
mappings = {
-- I want `n` to always go forward, and `<s-n>` to always go backwards
["#"] = {previous = "n", next ="<s-n>"},
["F"] = {previous = ";", next = ","},
["T"] = {previous = ";", next = ","},
-- Setting `cmdline = true` ensures that `n` will only be
-- overwritten if the search command is succesfully executed
["?"] = {previous = "n", next ="<s-n>", cmdline = true},
-- I have <leader>hn/hp bound to git-hunk-next/prev
["]]"] = {previous = "[[", next = "]]"},
["[["] = {previous = "[[", next = "]]"},
["]m"] = {previous = "[m", next = "]m"},
["[m"] = {previous = "[m", next = "]m"},
}
}
After #12 /
and ?
became unresponsive due to being bound.
Previously they just made use of the CmdlineLeave
-event.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.