Remapping crtl+backspace to delete previous word in insert mode!

52 views
Skip to first unread message

Anirudh Singh Bhadauria

unread,
Jan 24, 2024, 7:36:22 AMJan 24
to vim_use
Problem - Remapping crtl+backspace to delete previous word in insert mode! 

I am finding it really hard to do this, I have tried many combinations but it just doesn't work.
(however, I was able to remap just backspace to delete the previoius word, but that's not practical) Therefore, If anybody has a solution, that would be great! 

Remapping combinations that I tried so far, 
-- vim.keymap.set("i", "<C-BS>", "<C-W>", { desc = "delete whole word" })
-- vim.keymap.set("i", "<C-W>", "<C-\\><C-O>dB", { noremap = true, silent = true })
-- vim.keymap.set("i", "<C-W>", "<C-\\><C-O>db", { noremap = true, silent = true })
-- vim.api.nvim_set_keymap('i', '<BS>', '<C-\\><C-O>db', { noremap = true, silent = true }) (remaps backspace to delete the previoius word)

Thank you, 
Anirudh

Christian Brabandt

unread,
Jan 24, 2024, 7:37:36 AMJan 24
to vim...@googlegroups.com

On Mi, 24 Jan 2024, Anirudh Singh Bhadauria wrote:

> Problem - Remapping crtl+backspace to delete previous word in insert mode! 
>
> I am finding it really hard to do this, I have tried many combinations but it just doesn't work.
> (however, I was able to remap just backspace to delete the previoius word, but that's not practical) Therefore, If anybody has a solution, that would be great! 

Are you trying this in a terminal or in the gui. Ctrl-Backspace may not
universally work.

>
> Remapping combinations that I tried so far, 
> -- vim.keymap.set("i", "<C-BS>", "<C-W>", { desc = "delete whole word" })
> -- vim.keymap.set("i", "<C-W>", "<C-\\><C-O>dB", { noremap = true, silent = true })
> -- vim.keymap.set("i", "<C-W>", "<C-\\><C-O>db", { noremap = true, silent = true })
> -- vim.api.nvim_set_keymap('i', '<BS>', '<C-\\><C-O>db', { noremap = true, silent = true }) (remaps backspace to delete the previoius word)

This is neovim config. Are you using Neovim?


Thanks,
Christian
--
The fact that people are poor or discriminated against doesn't necessarily
endow them with any special qualities of justice, nobility, charity or
compassion.
-- Saul Alinsky

Anirudh Singh Bhadauria

unread,
Jan 24, 2024, 9:10:28 AMJan 24
to vim_use
Yes, I'm using nvim with lazyVim config

Christian Brabandt

unread,
Jan 24, 2024, 9:11:19 AMJan 24
to vim...@googlegroups.com

On Mi, 24 Jan 2024, Anirudh Singh Bhadauria wrote:

> Yes, I'm using nvim with lazyVim config

Then please ask in a neovim forum.


Thanks,
Christian
--
Linus? Whose that?
-- clueless newbie on #Linux

Marius Gedminas

unread,
Jan 25, 2024, 6:28:02 AMJan 25
to vim...@googlegroups.com
On Wed, Jan 24, 2024 at 04:29:34AM -0800, Anirudh Singh Bhadauria wrote:
> Problem - Remapping crtl+backspace to delete previous word in insert mode! 
>
> I am finding it really hard to do this, I have tried many combinations but it
> just doesn't work.

I've this mapping for command-line editing mode that works in vim running in
gnome-terminal:

" Ctrl-Backspace deletes word backwards
cnoremap <C-BS> <C-W>
" (gnome-terminal sends ^H for ctrl-backspace)
cmap <C-H> <C-BS>

in my .vimrc. This config also works fine for nvim in gnome-terminal.
I haven't gone out of my way to test whether the same mapping will work
in insert mode, but I don't see any reason why it wouldn't.

HTH,
Marius Gedminas
--
I have, however, attempted to stamp out burning thermite (not recommended),
neglected to note that I'd lit the fuse of a homemade grenado (not recommended)
and only noticed I was standing in a cloud of gasoline vapour after I struck a
match (also not recommended).
-- James Nicoll
signature.asc
Reply all
Reply to author
Forward
0 new messages