Skip to content
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

Remapping <CR> in normal mode #9

Open
TamaMcGlinn opened this issue Sep 19, 2023 · 3 comments
Open

Remapping <CR> in normal mode #9

TamaMcGlinn opened this issue Sep 19, 2023 · 3 comments

Comments

@TamaMcGlinn
Copy link

TamaMcGlinn commented Sep 19, 2023

Well-behaved plugins don't define mappings (except for buffertypes they define themselves). They put suggested mappings in the readme, for users to copy into their configuration themselves. Or they allow an option to enable some set of keybindings, but the default should be not to define keymappings. The idea being that if you just install a bunch of plugins without further configuration, they won't conflict, and also that no plugin will overwrite an existing user mapping without some sort of opt-in from the user.

nvim-gpt.lua has:

nnoremap <silent> <CR> <Cmd>GPT<CR>
vnoremap <silent> <CR> :GPTCode<CR>
(...)
" to prevent this mapping interfere with quickfix selection:
" autocmd CmdwinEnter * nnoremap <CR> <CR>
" autocmd BufReadPost quickfix nnoremap <CR> <CR>

But adding those two autocmd's (uncommented) to my vimrc.vim (at the start, at the end, or both) has not removed the mappings. Nor do I see how that is supposed to work.

I see the readme does mention no_default_keymaps = true being available, but I'm still trying to figure out how to use that. I guess you mean to add something like this to a lua vimrc:

require('nvim-gpt').setup({no_default_keymaps = true})
require'nvim-gpt'.setup {opts = {no_default_keymaps = true}}

But that doesn't work either.

@TamaMcGlinn
Copy link
Author

Also, why do you only close GPT windows when exiting vim, if the default mapping was used? Shouldn't this line be outside the if in lua/nvim-gpt.lua line 25?

vim.cmd [[ autocmd VimLeave * GPTClose ]]

@TamaMcGlinn
Copy link
Author

TamaMcGlinn commented Sep 19, 2023

Ah, finally found my mistake. I was calling setup() in another config file as well. The correct invocation is:

require'nvim-gpt'.setup {
    no_default_keymaps = true,
}

But of course that doesn't work if you have another place where you call it without passing no_default_keymaps.

Leaving this open solely to suggest that the logic be inverted, so that mappings are opt-in instead of opt-out.

@TamaMcGlinn
Copy link
Author

TamaMcGlinn commented Oct 10, 2023

Also note that this causes the quickfix list to be broken, as <CR> has a clear meaning in those buffers. There are probably many other buffertypes that similarly already define some meaning for <CR>, so we should really not remap it for all buffertypes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant