Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind delete key in vi mode

Tags:

zsh

oh-my-zsh

I am using the vi-mode plugin of oh-my-zsh. In my .zshrc, I have

bindkey '^[[3~' delete-char

where ^[[3~ is the escape code of my delete key. However, this only works in insert mode, but not in command mode. When I type

$ abcd

move the cursor to the beginning of the line and hit del in command mode, I get

$ ABCd

so apparently the character sequence of the delete key is interpreted literally. How can I make the delete key actually delete a character in command mode?

like image 781
gnebehay Avatar asked Apr 06 '17 07:04

gnebehay


People also ask

How to delete in vi Insert mode?

Once in insert mode, you can type in your text. Press ENTER at the end of each line. Use Backspace to delete to the left of the cursor. If you need to move the cursor to another line, or make a change, or pretty much anything else, you need to press ESC to get back to Command mode first.

How to set backspace in vim?

Fix Not Working Backspace in Vi/Vim To fix “not working” backspace key in the insert mode permanently, add set backspace=indent,eol,start command to vi / vim configuration file in your $HOME directory.

Which command removes the content of the line leaving you in insert mode?

Use Ctrl + O in Insert mode to run one Normal mode command, so you can delete the current line without leaving Insert mode, with Ctrl + O d d .


1 Answers

bindkey -a '^[[3~' delete-char

Zsh has a variety of different keymaps and by default, bindkey will bind keys in the normal insert mode keymap. The command mode keymap is selected with -M vicmd. -a is a shortcut for that. You can list the keymaps with bindkey -l. You'll see that there is also viopp which is used for movements after a key like c or d. There's also visual for visual selection mode.

like image 187
okapi Avatar answered Sep 20 '22 10:09

okapi