equalsraf / neovim-qt

Neovim client library and GUI, in Qt5.
https://github.com/equalsraf/neovim-qt/wiki
ISC License
1.84k stars 172 forks source link

Support custom keybindings/shortcuts #1041

Open hinell opened 1 year ago

hinell commented 1 year ago

Xterm allows you to specify custom keybindings for certain sequences (e.g. <C-S-BS>) via ~/.Xresources files.

For neovim-qt, it's currently impossible to do the same so it makes sense to make feature configurable via ~/.config/nvim/ginit.vim. The proposed API may look like: GuiKeybinding <keysequence> <string-to-emit>.

The actual use of config may look like:

if exists(':GuiTabline')
    GuiKeybinding Ctrl+Shift+BackSpace "\E[27;6;8~"
endif
jgehrig commented 1 year ago

I'm not sure I follow... Is there some reason the usual vim key binding mechanisms do not work for you?

For example, here are some key bindings I use in my vimrc:

" Shift Insert Paste (Command Mode, Insert Mode)
cmap <S-Insert> <C-R>+
imap <S-Insert> <C-R>+
nmap <silent> <Leader>t :GuiTreeviewToggle<CR>

Is there some reason the following mapping does not work for you? imap <C-BS> \E[27;6;8~

I'm not sure the intent of the \E[27;6;8~ sequence, but the binding above would insert those characters in Insert Mode.

Note: There is a bug with Shift + Backspace specifically:

259 #999

We're somewhat blocked by Neovim here... Eventually, we may be forced to apply a hacky forced mapping workaround.

justinmk commented 1 year ago

I'm not sure the intent of the \E[27;6;8~ sequence, but the binding above would insert those characters in Insert Mode.

Related:

Definitely would prefer to support this in Nvim so that GUIs don't need to reinvent this. Though I'm not sure if the exact request here is even blocked.

hinell commented 1 year ago

@justinmk Currently nvim can catch custom sequences. The problem is that not every front-end sends them. Xterm or Konsole (uses PTY) doesn't send them by deafult. it can be enabled if bound by a proper key sequences in native terminal settings (.e.g in Konsole there are profiles). e.g. for Xterm:

! ~/.Xresources
! Last-Modified: Friday, December 16, 2022
! Use `man xterm` to learn more about these configs
XTerm.VT100.faceSize: 11 
XTerm.VT100.faceName: JetBrains Mono Nerd Font
XTerm.VT100.background: #232627
XTerm.VT100.foreground: #fcfcfc

! ANSI-like escape codes!
XTerm.VT100.translations: #override \n\
        Ctrl Shift <Key>BackSpace: string("\E[27;6;10~") \n\
             Shift <Key>BackSpace: string("\E[27;6;8~")

In nvim I catch them like this:


-- ~/.config/nvim/lua/keybindings.lua
... 
nvim.keymap.set({ 'i' }, 'E[27;6;10~', ... )
hinell commented 1 year ago

Is there some reason the following mapping does not work for you?

@jgehrig It works, but I want separate bindings for ceratin commands, e.g.:

... <C-BS>   " deletes space-separated words
... <C-S-BS> " deletes (space-and-othersymbols)-separated words

The second one fails in many terminals and frontends. In Xterm it can be configured though (see above).

unphased commented 8 months ago

I invented a brand new ANSI escape code. I'm using \E[Y and \E[2Y. Notably \E[Z is shift-tab (and neovim understands this inherently) which is why I didn't use Z. To my knowledge I do not know of any existing usage of the YXWVU values for this type of xterm sequences...

So anyway yeah I think we're still blocked on being able to introduce wholly new escape sequences to neovim???

There is the note by @hinell from above,

In nvim I catch them like this: -- ~/.config/nvim/lua/keybindings.lua ... nvim.keymap.set({ 'i' }, 'E[27;6;10~', ... )

However this makes no sense because there is no escaped escape character here and I tried a bunch of combos and got nothing to work.

Edit: sorry I don't use nvim-qt, will post in nvim github.