-
Notifications
You must be signed in to change notification settings - Fork 933
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
bug: default keymaps for cmp and snippets make typing difficult #2533
Comments
As a side note, the mappings for this aren't on the keymaps docs page, which made it take longer for me to figure out what was going on. |
I don't quite understand what the bug is. Can you explain in detail? Hitting The mappings for this aren't on the keymaps docs page, because these are internal mappings to |
Unfortunately, pressing <C-Enter> also does not work with the minimal repro I posted above. If you want to stay in insert mode, you can hit <C-e>, otherwise <Esc> also works. A minimal fix for it is to add a user config like the following:
You need both the Personally, I think that the current default is bad. Auto-completion should not insert random stuff that's completely unrelated to what I have written, like snippets regarding the date. It's one thing to automatically insert a partly typed variable name, it's another thing to insert an unrelated snippet. But if LazyVim devs want the current behavior, then maybe this could be added to the recipes page? In the course of figuring out how to fix this for my own configuration, I also noticed a couple of minor doc bugs. nvim-cmp appears twice on the plugins page; here is the second occurence: https://www.lazyvim.org/plugins/coding#nvim-cmp-1. And the first one has both the options and full spec out of sync with the current LazyVim code, missing at least luasnip from sources, though maybe there's other things too. |
This is not a bug. It's a default that was chosen by the maintainer and the users can freely change that behavior in their personal configuration according to their liking. Not everyone has the same preferences. Regarding the docs, there is a second instance of Since all that you describe is just personal preference, I would advise to close this issue and do whatever you want in your personal configuration. This is not a LazyVim bug after all. |
Please close this issue. This is not a bug, but a personal preference. |
I think that having good defaults is important to this project. That is really the core thing that LazyVim provides - a set of defaults and a starting point for a neovim configuration. As such, a bad default is a bug, or at the minimum having good defaults is a feature. I also think that a default which makes it so that "just type some stuff in insert mode without hitting any commands" doesn't work out of the box is a bad default. I also think that having confusing documentation, where a plugin is shown as having multiple configurations, one of which is blank and doesn't describe anything close to how it's configured, is a documentation bug. I also think that having Perhaps those other two issues ( It seems like you disagree with some of the above. I'm still not clear on why. Do you think that good defaults aren't important to this project? Or that having a good default is a feature, and not a bug? Or that this is a good default? Or that, regardless of whether it is a good default, it is somehow not our place to question it? If the project maintainers want to close this as "NOTABUG WONTFIX" I won't re-open it. |
Key You can test this by opening Neovim and entering insert mode. With kitty, the key works as expected. When using tmux with kitty, some additional tmux tweaking might be necessary. In [[keyboard.bindings]]
# accept ctrl enter
key = "Enter"
mods = "Control"
chars = "\u001b[13;5u" |
I had very similar troubles when I started using LazyVim. I ended up figuring some of it out and putting in my own config (see here). This is obviously tailored to my own preferences, and there might be better ways to accomplish the goal, but it's been working for purposed for a few months now. Please note that it really took way too long to learn how to map a new key for completion, and required a bunch of research into a plugin But I completely agree that it's a very confusing default (honestly, I think that it's antithetical to Vim's core idea of "modes," but that's probably opening a can of worms that would be unproductive to discuss in this issue). It also took way too long to learn how to fix the behavior, and required deep research into a plugin that I didn't feel like I should've had to learn about. I agree that this should be fixed as the default in LazyVim if at all possible. But even if not the default, having the option available as an extra could really make it significantly easier to pick up LazyVim for people bothered by this behavior. |
I actually kinda agree. It wasn't really an issue before for me, but now with copilot and others, there's pretty much always a completion available. My muscle memory has already adapted and I use esc or c-enter automatically. Not sure what a good way to fix this could be. Need to think about it. |
That's a very good point about copilot. The thing that was biting me was snippets, not symbols. I wonder if it's possible to configure this to work differently based on which source supplied the completion? Or even based on some confidence value supplied by the source. |
I'm new to vim, Neovim, and LazyVim, so I was also confused by the default behavior and how to change it. I managed to get my desired settings with the following saved at
return {
-- Disable default Tab Key mappings in LuaSnip
{
"L3MON4D3/LuaSnip",
keys = function()
return {}
end,
},
{
"hrsh7th/nvim-cmp",
---@param opts cmp.ConfigSchema
opts = function(_, opts)
local cmp = require("cmp")
opts.mapping = cmp.mapping.preset.insert({
-- Press Tab to autocomplete
["<Tab>"] = cmp.mapping.confirm({ select = true }),
})
end,
},
} |
How about this? |
I highly recommend remapping
I'm using this, What grinds me with Tab completion is I don't know how to dismiss the cmp and just insert a regular I use Any suggestion is appreciated. My plugin: local cmp = require("cmp")
return {
"hrsh7th/nvim-cmp",
opts = {
completion = {
completeopt = "menu,menuone,noinsert,noselect",
},
mapping = {
["<CR>"] = cmp.mapping(function(fallback)
cmp.confirm({ select = false })
fallback()
end),
["<S-Tab>"] = cmp.mapping(function(fallback)
cmp.confirm({ select = false })
fallback()
end),
["<Tab>"] = cmp.mapping(function(fallback)
-- This little snippet will confirm with tab, and if no entry is selected, will confirm the first item
if cmp.visible() then
local entry = cmp.get_selected_entry()
if not entry then
cmp.confirm({ select = false })
fallback()
-- cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else
cmp.confirm({ select = true })
end
else
fallback()
end
end, { "i", "s", "c" }),
},
},
} |
|
Thanks I did not know that, however it is still annoying because I have to |
The lazyvim config doesn't cater for tab completion. Since you added it yourself, you'll have to make custom mappings to cater for your usecase |
An option is to only switch the To choose the autocomplete. Instead of escaping copilot before a newline.
{
"nvim-cmp",
---@param opts cmp.ConfigSchema
opts = function(_, opts)
local cmp = require("cmp")
-- <CR> always newline
opts.mapping["<CR>"] = function(fallback)
cmp.abort()
fallback()
end
-- Confirm insert completion with <C-CR>
opts.mapping["<C-CR>"] = cmp.mapping.confirm({ select = true })
-- Confirm replace completion with <S-CR>, already in
-- https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/coding.lua
}, To also support terminals with If it helps anyone to get the tmux bind -n S-Enter send-keys Escape "[13;2u"
bind -n C-Enter send-keys Escape "[13;5u" kitty map shift+enter send_text all \x1b[13;2u
map ctrl+enter send_text all \x1b[13;5u |
Did you check docs and existing issues?
Neovim version (nvim -v)
v0.9.4
Operating system/version
Debian 12
Describe the bug
While typing, with the default friendly-snippets configuration from and keymaps, it will pull up snippets. If one of them is at the end of a line, you have to notice this and hit a different key from normal to avoid entering it. This substantially reduces possible input speed due to adding a round-trip through cmp before you can hit enter.
It also looks like lua/lazyvim/plugins/coding.lua is trying to configure C-CR to abort completion, but with this minimal configuration it currently inserts the first match instead.
Steps To Reproduce
Open a new file
Type something that triggers a default snippet at the end of a line (e.g. "m log m" will trigger an m/D/Y date snippet)
Hit enter
Expected Behavior
A newline appears
Repro
The text was updated successfully, but these errors were encountered: