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
Native mapping syntax | Need feedback & v2.5 🚀 #2688
Comments
Personally, it wouldn't matter much to me but I think the one that is already in place is fine |
the issue with that is that you have to learn 2 syntaxes. One for vim.keymap.set & its opts and the other for nvchad's custom mapping syntax. |
But it's already pretty intuitive and (correct me if I'm wrong) matches with whickey.nvim |
I like the old approach, which makes mapping configuration very readable. A hybrid approach of allowing both might be a good idea too. |
local map = vim.keymap.set
local mappings = {
n = {
["<C-n>"] = { "<cmd> NvimTreeToggle <CR>", "Toggle nvimtree" },
["<C-i>"] = { "<cmd> NvimTreeToggle <CR>", "Toggle nvimtree" },
["<C-b>"] = { "<cmd> NvimTreeToggle <CR>", "Toggle nvimtree" },
},
}
for mode, maps in pairs(mappings) do
for key, val in pairs(maps) do
map(mode, key, val[1], val[2])
end
end With new approach you can define any syntax you want 😁 |
I too find the current approach very good. I would most certainly refrain from putting grouping information (i.e. | word) in descriptions:
However, implementing grouping is a good idea and could be done without breaking changes using the current format -> an additional optional field passed to whichkey. |
@jotihojr | is optional but i'll include them in default mappings I agree that this would clutter whichkey a little but adding| is the only way through which we could group them in nvcheatsheet whilst still using vim.keymap.set You can still reset them tho. like this local mappings = vim.api.nvim_get_keymap("n")
local map = vim.keymap.set
for _, v in ipairs(mappings) do
-- get word before |
local desc = v.desc:match("([^|]+)%s*|")
map("n", v.lhs, v.rhs or v.callback, { desc = desc })
end or I think we could could cache the groups & their keybinds in some file for nvcheatsheet and then reset the value 🤔 |
Programmatically anything is possible, but not always advantageous. There's got to be a better way. Perhaps a PR @neovim adding optional grouping in |
I dont know C so i cant do it |
@lucario387 is there any way? 🤔 |
Will it affect the key mapping that we are passing via Lazy-vim using the keys options? |
no |
@jotihojr i think it'll be better to use group name in description as first word as it'd be better with other plugins too!! |
@siduck sorry I missed this issue. Currently I use this code to disable all default mappings. Is there a way to do that with new approach rather than having to define all the default mappings with -- Disable all default key maps
M.disabled = {}
for _, section in pairs(require('core.mappings')) do
for mode, keys in pairs(section) do
if mode == 'n' or mode == 't' or mode == 'v' or mode == 'x' or mode == 'i' then
for key, _ in pairs(keys) do
if M.disabled[mode] == nil then
M.disabled[mode] = {}
end
M.disabled[mode][key] = ''
end
end
end
end
|
@sandangel Btw do know that v3.0 might take months to finish as i'm not working on nvchad from march 10 to april 10. So no need to panick! Just use v2.0 for now. Also when v3.0 releases, take your own time to migrate to it,v2.0 can still be used local disabled = {
n = { "<C-n>", "<C-s>" },
i = { "jk" },
}
for mode, mappings in pairs(disabled) do
for _, keys in pairs(mappings) do
vim.keymap.del(mode, keys)
end
end |
@siduck It doesn't change the fact that I will need to list all the default mappings in the |
@sandangel you were doing the same before, whats the difference? I can only think of mapclear command. Btw if all things go right then you can opt out from default mappings when nvchad v3.0 releases check the last line here and then check the mappings file https://github.com/NvChad/NvChad/tree/test lazyVim and astronvim v4 have a starter config like thing in which they import their configs as plugins. By import i mean lazy.nvim's import feature. So in the above nvchad's test branch you could see, how could one use nvchad without all the custom dir stuff , just by importing nvchad as a plugin and load its stuff. This way the user has 100% control over the config :)) |
I fetched from map("n", "<C-n>", "<C-w>h", { desc = "Switch Window left" }) still exhibited the |
@CBroz1 you should remove this line from your chadrc |
I think I like the v3.0 mappings more. More native to VIM means you know more about what is going on, and it is easy to port someone's custom config to NvChad. Not sure if this should be a legit concern, but IMO, with v3, need also to make sure that the expectation is correct. Today I in v2 I tried this mapping -- NvChad custom mappings.lua
M.lspconfig = {
n = {
["<leader>ds"] = { require("telescope.builtin").lsp_document_symbols, "Document Symbols" }
}
} which I tried to copy from -- kickstart init.lua
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
callback = function(event)
vim.keymap.set('n', '<leader>ds', require('telescope.builtin').lsp_document_symbols, 'LSP [G]oto [R]eferences')
end My custom keymap didn't work for NvChad, due to "telescope.builtin" not loaded/existed yet when doing key-mapping. And I understood that. The different keymap syntax had the psychological effect of reminding me that NvChad works differently than Kickstart. If the syntax is very familiar, yet it works in one but not the other, I would have been quite confused. Just my 2 cents; I am still quite a noob at Neovim. Maybe I am just overthinking this. |
@bhuynhdev load it in a function, you dont use modules that directly cuz plugins in nvchad are lazyloaded. so do function()
require('telescope.builtin').lsp_document_symbols()
end btw such mappings are meant to be used on lspattach i.e if lsp client is attached to buffer. So if you were in v3.0 then u can just copy that kickstart code local map = vim.keymap.set
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
callback = function()
map('n', '<leader>ds', require('telescope.builtin').lsp_document_symbols, { desc = 'LSP [G]oto [R]eferences' })
-- add more mappings here which u want to load on buffers which have lsp attached
end
}) |
I got two problems with migrating:
My current config here |
@Gerodote yes one mapping category are not allowed, plugins like surround have a lot of them... i'll probably look a better way for this soon |
Hi everyone I need feedback with the new potential mapping syntax which could be used from v3.0.
Currently you all have to read this custom syntax
With the new syntax, which just uses Neovim's default
vim.keymap.set
functionSo the first word is used for group name in nvcheatsheet , You can just write a wrapper of
vim.keymap.set
to simplify things even moreso to override a default mapping or add new one, you just put the
vim.keymap.set
code incustom.mappings
.And to disable one mapping, just use
vim.keymap.del
Pros of this method
Cons
So please let me know if you like this method. Add a 👍 if you do or 👎 if you dont.
Btw do know that you can still use old syntax with some lua coding! check #2688 (comment)
The text was updated successfully, but these errors were encountered: