Sample Header Ad - 728x90

How to enable <Ctrl+Backspace> with Tmux, Neovim and Alacritty to delete the previous word?

1 vote
0 answers
1510 views
I use the alacritty terminal, and neovim editor with tmux. At first Ctrl+Backspace (for deleting a previous) wasn't working at all in the terminal. So added the following line to alacritty.yml:
key_bindings:
  - { key: Back, mods: Control, chars: "\x17" }
And this enabled the keybinding in alacritty. And now it deletes a word in the terminal. So I added the following in my neovim keybindings:
vim.keymap.set("i", "^H", "", { desc = "Delete previous word", noremap = true, silent = true })
And this enabled it in neovim. But when I open vim in **tmux**, it doesn't work. I tried adding the following -
-key -n C-BSpace send-keys C-BSpace
-
-key -n C-BSpace send-keys ^H
-
-key -n ^H send-keys ^H
-
-key -n ^H send-keys C-BSpace
Nothing seems to work. I looked up on the web for any other answers, but I couldn't find anyone with a similar problem. So before I set the option in alacritty when I do run $ cat (or first press Ctrl+V) and then press Ctrl+Backspace it shows me ^H, but after adding that keybinding in alacritty, it doesn't do that anymore, it directly starts deleting a word before it. But neovim doesn't do the job. Also I tried $ cat on two different terminals (xfce4-terminal and terminator) and both gave me ^H. I don't know how to set the keybinding in these terminals. Just presssing on Ctrl+Backspace in these terminals just acts like a single Backspace, it does the same thing on tmux as well (when used on those terminals). **EDIT [SOLVED]**: I had a binding set for Ctrl-W in my tmux config. As one of the comments suggested: > Why do that when Ctrl-w already deletes the previous word both in insert mode in neovim and in the command line? And my answer was because I already have a binding set to Ctrl-W, so I tried removing that keybinding, and it works. My configs: alacritty.yml:
key_bindings:
  - { key: Back, mods: Control, chars: "\x17" }
nvim/init.lua:
vim.keymap.set("i", "^H", "", { noremap = true, silent = true })
These two combinations actually fixed it. But when vim converted Ctrl-Backspace to Ctrl-W, and because I had Ctrl-W set as a binding in my tmux config, I think tmux was maybe interfering with that specific binding. I am not sure. But this is how I fixed it.
Asked by an4s911 (141 rep)
Feb 17, 2024, 01:07 PM
Last activity: Feb 18, 2024, 06:35 AM