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

Support custom keybindings/shortcuts #1041

Open
hinell opened this issue Dec 16, 2022 · 5 comments
Open

Support custom keybindings/shortcuts #1041

hinell opened this issue Dec 16, 2022 · 5 comments

Comments

@hinell
Copy link

hinell commented Dec 16, 2022

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
Copy link
Collaborator

jgehrig commented Dec 16, 2022

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
Copy link
Contributor

justinmk commented Dec 16, 2022

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
Copy link
Author

hinell commented Dec 16, 2022

@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
Copy link
Author

hinell commented Dec 16, 2022

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
Copy link

unphased commented Jan 12, 2024

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.

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

4 participants