nvim-lua / kickstart.nvim

A launch point for your personal nvim configuration
MIT License
19.66k stars 23.53k forks source link

Unable to use Ctrl+Backspace to delete word #140

Closed ianyepan closed 1 year ago

ianyepan commented 1 year ago

I'd like to use Ctrl+Backspace to delete a word. So far I've tried:

vim.keymap.set('i', '<C-h>', '<C-w>')
vim.keymap.set('i', '<C-bs>', '<C-w>')
vim.cmd [[inoremap <C-h> <C-w>]]
vim.cmd [[inoremap <C-bs> <C-w>]]

But none of them seem to work.

Any ideas what I am doing wrong? Thanks!

diogotito commented 1 year ago

It could be your terminal emulator. Your Lua is alright. Where are you running Neovim? Ctrl and Backspace are fiddly to handle in terminal emulators.

Binding <C-bs> works in nvim-qt and Neovide (two GUI apps) but didn't work in any of the terminal emulators I tried. Binding <C-h> worked in Windows Terminal and mintty (Git Bash) but didn't work in Alacritty for me.

I was more successful binding Alt+Backspace (<M-bs>) for that. It works consistently across GUIs and terminal emulators, and has the additional benefit of being the default keybinding used to delete words in many shells, REPLs, etc. so I suggest you to try it out

vim.keymap.set('i', '<M-BS>', '<C-w>')
ianyepan commented 1 year ago

Thanks for the reply. I ended up configuring it at the terminal settings level. I am using Windows Terminal, so I just had to put these lines in the settings.json file:

{
  "keys": "ctrl+backspace",
  "command": 
  {
    "action": "sendInput",
    "input": "\u0017"
  }
}

I've thought about using alt+backspace, but I'm just too used to ctrl+backspace, especially since it's the universal "delete word" shortcut in Windows too.