Comments (10)
Yes, the first solution works. The override function will be scheduled in the main event-loop, and the loop is after NvChad's on_attach func call, if I understood correctly.
The second one works as well, in lspconfig.lua
I setup lua_ls
again, providing your attach
func.
Hey but though they both work, this isn't intuitive at all. To override NvChad's key map, I have to use schedule
which I have never seen before. I can imagine people who encounter problems like mine will have to find this issue to get the answer. Or override on_attach
func calls. Plus overriding lua_ls
's on_attach
means that I need to set up lua_ls
again, like:
lspconfig.lua_ls.setup {
on_attach = on_attach, -- Override on_attach
...
}
And this will override NvChad's default lua_ls
settings as wel, especially the library imports. So I have to copy NvChad's lua_ls.setup{ ... }
to get them work again.
Compared to v2.5, in v2.0 I didn't need to solve this problem at all, 'cause v2.0 didn't set up the key maps in on_attach
.
Is it possible to make a change in the future?
from nvchad.
please add mappings which are set on_attach to lspattach event, make an autocmd
from nvchad.
Thanks for reply, but it's not making effect.
In my mappings.lua
:
local map = vim.keymap.set
local nomap = vim.keymap.del
local autocmd = vim.api.nvim_create_autocmd
autocmd("LspAttach", {
callback = function()
-- Override keymaps provided by NvChad
nomap("n", "gd")
nomap("n", "gr")
nomap("n", "gi")
map("n", "gd", "<cmd> Telescope lsp_definitions <CR>", { desc = "LSP defininitions"})
map("n", "gr", "<cmd> Telescope lsp_references <CR>", { desc = "LSP references"})
map("n", "gi", "<cmd> Telescope lsp_implementations <CR>", { desc = "LSP implementations"})
end
})
In :Telescope keymap
, I can still see two "gd" entries are set, and using the "gd" key combination still pops up the QuickFix list.
from nvchad.
@fishBone000 that isnt enough, u should add the {bufnr} opt! like we did for lsp
from nvchad.
It's still not working...
autocmd("LspAttach", {
callback = function(args)
-- Override keymaps provided by NvChad
-- Commented out because Nvim warns about "no such key map"
-- Is this autocmd really taking precedence over NvChad's on_attach func?
-- nomap("n", "gd", { buffer = args.buf })
-- nomap("n", "gr", { buffer = args.buf })
-- nomap("n", "gi", { buffer = args.buf })
map("n", "gd", "<cmd> Telescope lsp_definitions <CR>", { buffer = args.buf, desc = "LSP defininitions"})
map("n", "gr", "<cmd> Telescope lsp_references <CR>", { buffer = args.buf, desc = "LSP references"})
map("n", "gi", "<cmd> Telescope lsp_implementations <CR>", { buffer = args.buf, desc = "LSP implementations"})
end
})
from nvchad.
hmmm ig there's some race condition , this should work
autocmd("LspAttach", {
callback = function(args)
vim.schedule(function()
write here
end)
end,
})
or make custom onattach which loads our first and yours, in order
local function attach(client, bufnr)
on_attach(client, bufnr)
map("n", "gd", "<cmd> Telescope lsp_implementations <CR>", { buffer = bufnr, desc = "bruh" })
end
from nvchad.
@fishBone000 you only override via autocmd cuz those are "LSP" related mappings and are attached to the buffer on lspattach, i dont think why do you expect your mapping code to work on startup without putting it in lspattach.
I wanted to keep things simple + no abstraction, you are free to not use out onattach and just declare your mappings.
you can completely opt out of our default lspconfig too, just remove it from the config function of your lspconfig spec
from nvchad.
I know why my code didn't work earlier and I can modify my code to not use the NvChad default config, as you have shown me earlier.
It's just that, for a simple functional change as adding a new key map, in our case here I need to something big like reading NvChad's code to find out why my code is overridden. I expect one to approach sth small by doing small things, and approach sth big by doing big things, not approach small things by doing big things. Not that I want to say reading NvChad code and modifying one's own code is a big stuff, nor do I feel too lazy to do that, it's just not matched to sth small as adding a new key map. It's more like a UX stuff. Imagine if u r working on a proj, and suddenly want to add a key map to make things faster, and: oops, it just doesn't work, and you need to check NvChad's code for why.
from nvchad.
that isnt a downside, making a new abstracted syntax for this would confuse more :/
i'll just mention in the mappings page before hand that the lsp mappings must be overriden onattach.
from nvchad.
Nah, ain't saying you should add abstraction, just I think some measures to improve this should be taken, from my aspect of view.
i'll just mention in the mappings page before hand that the lsp mappings must be overriden onattach.
Yes, I think users will know this overriding stuff in this way and won't scratch their head like me.
Thanks for your help!
from nvchad.
Related Issues (20)
- Attention! Do you want all chadrc theming options in base46 table? Urgent Feedback needed. HOT 31
- clean install on rocky linux doesnt work. HOT 1
- Please provide support to toggle in tablinebuff with buffer numbers given by NvChad HOT 1
- NVChad 2.0 Theme Switcher Not Saving Theme HOT 1
- When deleting currently opened file, nvim-tree takes the whole width HOT 8
- Trouble installing on WSL Ubuntu HOT 2
- <leader>/ doesn't work in normal and visual mode HOT 1
- Disable all proprietary keybindings HOT 5
- plugins.lua does not install plugins despite following instructions HOT 1
- Grammar autocompletion in NvChad HOT 1
- vscode normal theme in nvchad HOT 5
- DRAFT - fix for "undefined field `fs_stat`" from lua_ls
- Better ways for the user to "unmap" key mappings for plugins shipped with `nvchad` HOT 11
- tsserver LSP not attaching at all after installing and updating lspconfig HOT 2
- Fields cannot be injected into the reference of `ChadrcConfig` for `plugins`. To do so, use `---class` for `M`. warning in chadrc.lua HOT 1
- reopen same file,buffer will changed,how to dissabled this action HOT 7
- Show dotfiles in nvim-tree by default HOT 7
- The LSP Config will cause the c/c++ preprocessor syntax to be inoperative HOT 1
- Error after running migration script on Linux HOT 1
- Mason ignoring ensure_installed when running MasonInstallAll HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nvchad.