2

I want to bind Control+Backspace in insert mode to delete a word. I'm able to bind Control+Del in both insert and normal modes, but I can only seem to bind Control+Del in normal mode. I've checked many other posts and none of the fixes worked for me.

  • terminal vim
  • Kubuntu 21.10
  • Konsole 21.08.1

Even on 21.04 at some point after upgrading packages, Control+Backspace in insert or normal to delete a word stopped working.

I can confirm this does not work on archlinux with XTerm either.

Different things I have tried:

silent !stty -ixon  
set encoding=utf-8
set fileencoding=utf-8
"let &t_TI = "\<Esc>[>4;2m"
"let &t_TE = "\<Esc>[>4;m"
"let &t_TI = ""
"let &t_TE = ""
:fixdel

I'm not sure what happened, but it used to work. This is my previous vimrc:

" (used to work before upgrading)
noremap! <C-BS> <C-w>
noremap! <C-h> <C-w>
inoremap <C-w> <C-\><C-o>dB
inoremap <C-BS> <C-\><C-o>db

This is what I have currently:

"delete previous word
"works-
nnoremap ^H db       

"does not work(aggregate of different things i tried)-
inoremap <C-^?> sdsldkjfddjfkd
inoremap <C-BS> sdsldkjfddjfkd
inoremap <C-kBS> sdsldkjfddjfkd
inoremap <C-D> sdsldkjfddjfkd
inoremap <C-kD> sdsldkjfddjfkd
inoremap ^H sdsldkjfddjfkd
inoremap ^_^H sdsldkjfddjfkd
inoremap ^_^? sdsldkjfddjfkd
inoremap ^V^V^V^H sdsldkjfddjfkd
inoremap ^V^H sdsldkjfddjfkd
inoremap <C-h> sdsldkjfddjfkd

"this one works in insert mode, sending this text when pressing only backspace
inoremap ^V^? sdsldkjfddjfkd

"delete next word-working
inoremap <C-kDel> <C-o>dw
nnoremap <C-kDel> dw

vim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 21 2021 08:39:53)
Included patches: 1-2434, 3402-3403, 3409, 3428
Modified by [email protected]
Compiled by [email protected]
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         +tag_binary
+arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        +termguicolors
-balloon_eval      -footer            +multi_lang        +terminal
+balloon_eval_term +fork()            -mzscheme          +terminfo
-browse            +gettext           +netbeans_intg     +termresponse
++builtin_terms    -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              -perl              +title
-clientserver      +job               +persistent_undo   -toolbar
-clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     +keymap            +postscript        +vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      +langmap           +profile           +virtualedit
+comments          +libcall           -python            +visual
+conceal           +linebreak         +python3           +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          +rightleft         +wildignore
+cursorshape       -lua               -ruby              +wildmenu
+dialog_con        +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       -X11
-dnd               +mouse             -sound             -xfontset
-ebcdic            -mouseshape        +spell             -xim
+emacs_tags        +mouse_dec         +startuptime       -xpm
+eval              +mouse_gpm         +statusline        -xsmp
+ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+extra_search      +mouse_netterm     +syntax            -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Wdate-time -g -O2 -ffile-prefix-map=/build/vim-MtnJpP/vim-8.2.2434=. -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-Bsymbolic-functions -flto=auto -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lm -ltinfo -lselinux -lacl -lattr -lgpm -L/usr/lib/python3.9/config-3.9-x86_64-linux-gnu -lpython3.9 -lcrypt -ldl -lm -lm 

neofetch
OS: Kubuntu 21.10 x86_64 
Host: 82AU Lenovo Legion 5 15IMH05 
Kernel: 5.13.0-19-generic 
Uptime: 3 hours, 34 mins 
Packages: 2338 (dpkg) 
Shell: bash 5.1.8 
DE: Plasma 5.22.5 
Terminal: konsole 

If the new version specifies a new way to bind these keys, how do we do it

Also, I am completely okay with Control+h in insert mode deleting a word back too; that's how it's currently working in normal mode.

Note: on konsole, keybindings are set to Default(XFree 4). The &t_TI option to disable modifyOtherKeys didn't do anything.

In vim, Control+Del sends ^[3;5~ while Control+Backspace sends ^H.

In konsole: Control+Del sends ^[[3;5~ while Control+Backspace sends ^H.

Control+Backspace works in vim-gtk(gvim) on the same machine. Should I manually configure konsole to send another sequence on pressing Control+Backspace? or is it sttys fault? or xmodmap? or vim?

2
  • Terminal input processing is annoying. Might not be easily doable -- I haven't figured it out anyway. If you prefer ctrl-backspace, I recommend just using gVim if you can. Commented Oct 19, 2021 at 10:01
  • @Zoe yep i caved and just bound it to <kbd>ctrl</kbd> + <kbd>\</kbd>. i dont want to downgrade to a previous version of vim(vim 7), because I run (k)ubuntu 21.10 and archlinux so i need keybindings to be uniform. gvim wouldve suited my needs, but i only use terminal vim on archlinux for battery-friendly editing BTW thanks @D.\ Ben\ Knoble for formatting the post, will keep it in mind next time
    – User
    Commented Oct 21, 2021 at 6:03

1 Answer 1

0

<C-H> still works in xfce4-terminal, and in the default Mac Terminal program to bind <C-Backspace>.

I am using the following version of Vim.

$ vim --version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Aug 02 2022 21:22:22)
Included patches: 1-135
Compiled by Arch Linux
Huge version with GTK3 GUI.  Features included (+) or not (-):

In xfce4-terminal, in Edit>Preferences>Compatibility>Backspace Generates, I set the value to auto, but I suspect <C-H> would also work. On my Mac, I had to specify in Terminal>Profiles>Keyboard, that <C-Backspace> should be interpreted as \010, which happens to be <C-H> typed in the keyboard.

You can test if this is a terminal problem or a vim problem by typing <C-V><C-Backspace> in your terminal bash prompt (if you are using bash, might be different for zsh or other shells). You should see ^H or another output. If you see nothing, your terminal is set up incorrect, so that it cannot read <C-Backspace>. Go into settings/preferences for the terminal application and try to see if you can change the terminal mapping for <C-Backspace>. If you see something other than ^H, use that output in your vim mappings. If you see ^H, and still cannot map it in vim, I am stumped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.