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

Exit on <C-c> only when insert_only is true #25

Closed
wants to merge 1 commit into from
Closed

Exit on <C-c> only when insert_only is true #25

wants to merge 1 commit into from

Conversation

adriangoransson
Copy link

Hi, thanks for a great plugin! I just started using it and I like it a lot.

The only thing bothering me is that I use <C-c> instead of <Esc> normally to exit insert mode. With this plugin, I tend to close the input window when I really want to enter normal mode. This change treats <C-c> the same as <Esc>.

Context

☝️

Description

Map <C-c> the same as <Esc> for input, including when insert_only is enabled.

Test Plan

None.

@stevearc
Copy link
Owner

I actually think that <C-c> should default to closing the modal regardless of if insert_only is true or not. Using <C-c> to close a floating window is a pattern that shows up in other plugins as well (notably telescope). That said, I do think that the behavior should be customizable. For your purposes, this seems to work:

au FileType DressingInput lua vim.api.nvim_buf_del_keymap(0, "i", "<C-c>"); vim.api.nvim_buf_set_keymap(0, "i", "<C-c>", "<Esc>", {})

And you can of course put that in a ftplugin/DressingInput.lua file with other keybindings

@adriangoransson
Copy link
Author

adriangoransson commented Mar 17, 2022

Oh, right! I had forgot that I had that behavior specifically disabled in Telescope. Sorry about that, and thank you for the autocommand, though I cannot get it to work! :(

Error executing vim.schedule lua callback: .../share/nvim/plugged/dressing.nvim/lua/dressing/input.lua:264: Vim(lua):E5108: Error executing lua [string ":lua"]:1: E31: No such mapping                                                                                                                      
stack traceback:                                                                                                                                                                                                                                                                                             
        [C]: in function 'nvim_buf_del_keymap'                                                                                                                                                                                                                                                               
        [string ":lua"]:1: in main chunk                                                                                                                                                                                                                                                                     
        [C]: in function 'nvim_buf_set_option'                                                                                                                                                                                                                                                               
        .../share/nvim/plugged/dressing.nvim/lua/dressing/input.lua:264: in function 'cb'                                                                                                                                                                                                                    
        vim.lua:285: in function <vim.lua:285>                                                                                                                                                                                                                                                               
stack traceback:                                                                                                                                                                                                                                                                                             
        [C]: in function 'nvim_buf_set_option'                                                                                                                                                                                                                                                               
        .../share/nvim/plugged/dressing.nvim/lua/dressing/input.lua:264: in function 'cb'                                                                                                                                                                                                                    
        vim.lua:285: in function <vim.lua:285>

I'm using 0.6.1.

@adriangoransson
Copy link
Author

adriangoransson commented Mar 17, 2022

Ah, it seems that the file type is set before the keymaps are applied, so nvim_buf_del_keymap fails in the autocommand.

@stevearc
Copy link
Owner

Derp, I made that change when I tested locally, but I forgot to push it up! Let me know if you encounter any other issues with it

@adriangoransson
Copy link
Author

Thanks, now it works just fine! :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants