ChatGPT.nvim icon indicating copy to clipboard operation
ChatGPT.nvim copied to clipboard

Add option in keymap to exit ChatGPT window while in normal mode

Open Adoliin opened this issue 2 years ago • 7 comments

As of now we have this:

{
  keymaps = {
    close = { '<C-c>' }
  }
}

Which only allow us to map an exit key while in insert mode what i want is something like this:

{
  keymaps = {
    close = { '<C-c>' }
    close_normal = '<esc>'
  }
}

Adoliin avatar Mar 17 '23 04:03 Adoliin

The keymaps.close option is being set for both insert and normal mode, see:

https://github.com/jackMort/ChatGPT.nvim/blob/main/lua/chatgpt/module.lua#L189-L191

for _, keymap in ipairs(close_keymaps) do
  chat_input:map("i", keymap, function()
    chat_input.input_props.on_close()
  end, { noremap = true, silent = true })

  chat_input:map("n", keymap, function()
    chat_input.input_props.on_close()
  end, { noremap = true, silent = true })
end

I've confirmed that having the following allows me to close the window with <C-c> in both modes .

close = { "q", "<C-c>" },

cmpadden avatar Apr 03 '23 19:04 cmpadden

I think I'll speak for a lot of users when I say that I'd like the prompt to work just like in Telescope! (i.e. Esc closes entire popup in normal mode)

textzenith avatar Apr 04 '23 02:04 textzenith

@textzenith I think that would be nice too.

I don't use it, so I'm not familiar with this, but how does Telescope handle going into and out of Normal/Insert mode? Is this a feature it supports?

Would we want to exit the window with Esc in Normal mode, but not in Insert mode? This way a double press of Esc from Insert mode would exit the pop-up?

cmpadden avatar Apr 04 '23 14:04 cmpadden

@Adoliin & @textzenith this PR https://github.com/jackMort/ChatGPT.nvim/pull/139 adds the close_normal option.

Let me know if this is what you were expecting. Cheers!

cmpadden avatar Apr 06 '23 12:04 cmpadden

Yup exactly that's what I was looking for, hopefully it gets merged. Thanks for your contribution.

Adoliin avatar Apr 10 '23 07:04 Adoliin

Legend!

Yes @cmpadden, that's exactly how it works. It's a bit unintuitive at first, but it's a UX most of us have become familiar with (due to Telescope's popularity), and now it feels like a sufficiently Vimmy way to handle things.

edit: I've been thinking some more about this:

In Telescope, you can press Ctrl-C from insert mode, still. But in normal mode it doesn't work — it wants to exit Neovim. Doesn't feel right. I like that in ChatGPT.nvim you can. In command mode, you can escape just by deleting (hitting backspace) at the start of the prompt. Both Telescope and ChatGPT.nvim don't allow this. Not sure if this feels right.

textzenith avatar Apr 26 '23 12:04 textzenith

I would really like mappings for normal mode, and mappings for insert mode separately.

ariel-frischer avatar May 26 '23 06:05 ariel-frischer