stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.73k stars 32 forks source link

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

Closed adriangoransson closed 2 years ago

adriangoransson commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

stevearc commented 2 years ago

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 commented 2 years ago

Thanks, now it works just fine! :)