How to remove a keybinding - zsh

So I have zsh installed and when i run the command:
bindkey | grep kill-word
I see the following results:
"^W" backward-kill-word
"^[^H" backward-kill-word
"^[D" kill-word
"^[d" kill-word
"^[^?" backward-kill-word
I want to remove some of these key bindings, how do I go about doing that?

Say you wanted to remove the lower case version of kill-word. bindkey -r will remove the given binding.
bindkey -r '\ed'

Related

How to make zsh keybind between emacs mode and vi mode?

I want to bind a key to toggle emacs mode and vi mode,which I use oh-my-zsh plugins(vi-mode).
I tried Is there a way to switch Bash or zsh from Emacs mode to vi mode with a keystroke?
I also try to bindkey like
bindkey '^[e' 'set -o emacs'
bindkey '^[v' 'set -o vi'
But it's not work for me.
Does any way to toggle vi/emacs or keybind to set keymap?
Thanks a lot !
bindkey is used for binding keys to ZLE widgets not any random command. So what you have guessed at is not going to work. You could write a custom ZLE widget to switch keymaps:
select-emacs() { set -o emacs }
zle -N select-emacs
bindkey '^[e' select-emacs
In practical terms, I wouldn't recommend this. If you want a hybrid approach, it is better to select emacs mode but bind a key to vi-cmd-mode. In fact Ctrl-X,Ctrl-V is bound to this by default. You might even bind the escape key to vi-cmd-mode - where emacs key sequences involve an initial escape press, that can mostly be replaced by Alt. If you're used to typing it with the actual escape key, you may be able to replace it by a custom widget in vi command mode.
I finally "found out" how to toggle vi and emacs mode with a singel key, e.g. [alt]+[i] in zsh
# in the .zshrc
# toggle vi and emacs mode
vi-mode() { set -o vi; }
emacs-mode() { set -o emacs; }
zle -N vi-mode
zle -N emacs-mode
bindkey '\ei' vi-mode # switch to vi "insert" mode
bindkey -M viins 'jk' vi-cmd-mode # (optionally) switch to vi "cmd" mode
bindkey -M viins '\ei' emacs-mode # switch to emacs mode
now you can toggle from emacs-mode to vi-mode and from vi-mode (both insert or normal mode) to emacs-mode

Disable Zsh history completely

I would like to disable Zsh history (arrow up) and zle history search (namely esc+p) completely. How can I achieve this?
My current .zshrc:
unsetopt hist_append
unsetopt hist_expand
HISTFILE=
HISTSIZE=SAVEHIST=0
Currently I have history buffer of one, but I'd like to have history of zero.
21-10-2016 Update:
I've added
bindkey -r "^[p"
bindkey -r "^Xr"
bindkey -r "^Xs"
bindkey -r "^[[A"
bindkey -r "^[[B"
bindkey -r "^[n"
to get rid of history features that I use (esc+p is deeply hardwired to my backbone - so difficult to unlearn).
I don't see anything in the zsh man page that completely disables history. Even setting HISTSIZE=0 seems to reset the value of HISTSIZE to 1.
You'll probably have better luck changing the key bindings with bindkey so that history features never occur. For example, bindkey -r "^[[A" for my up-arrow key (note that I actually typed a caret and two brackets, not an escape key).
I use following entries in my .zshrc:
alias disablehistory="function zshaddhistory() { return 1 }"
If function zshaddhistory is defined, it can control whether history line will be saved.
Therefore, alias disablehistory will just define function that always returns 1 (don't save).
alias disablehistory="function zshaddhistory() { return 1 }"
alias enablehistory="unset -f zshaddhistory"
enablehistory just unsets function set by previous alias.
If you want to disable history completely, permanently define zshaddhistory in your .zshrc
Try configuring your ZSH setup to run a postexec function that empties/deletes your .zhistory file. It's a hacky workaround but should probably work.

Deleting word like bash in zsh (autoload is not working)

I have the following code in my .zshrc and I have .oh-my-zshell installed.
The following line, however, does not work as it is described in other posts:
autoload -U select-word-style
select-word-style bash
Is there other options I need to add in order to make it work?
if you want '^W' bash behavior you may need to unset WORDCHARS or place them in seperate functions and bind you newly created functions.
As i am not using you example, here is my way to accomplish this, second example is also for bash compatibility using <A-Backspace> which respect WORDCHAR defined as follow
x-bash-backward-kill-word(){
WORDCHARS='' zle backward-kill-word
}
zle -N x-bash-backward-kill-word
bindkey '^W' x-bash-backward-kill-word
x-backward-kill-word(){
WORDCHARS='*?_-[]~\!#$%^(){}<>|`##$%^*()+:?' zle backward-kill-word
}
zle -N x-backward-kill-word
bindkey '\e^?' x-backward-kill-word

List of zsh bindkey commands

Where can I find a list of zsh commands that I can use with bindkey, with descriptions?
Each time that I look for name of some standard action (e.g., end-of-line), I need to google and guess that the command found is what I look for.
Related:
Interpret zsh bindkey escaped sequences (SO)
The Z-Shell Line Editor (doc)
bindkey -l will give you a list of existing keymap names.
bindkey -M <keymap> will list all the bindings in a given keymap.
If you use the zsh command line in emacs mode, then the emacs keymap is likely to be most important for you.
If you use it in vi mode, then you’d be interested in viins and vicmd.
(See the zshzle(1) man page for more details.)
Once you have a list of keybindings, you can search the official ZLE documentation for the name of the action (or “widget” in zsh parlance).
zle -al
lists all registered zle commands
Commands available for use in the line editor are referred to as widgets. The standard widgets are listed in the zshzle manpage in the STANDARD WIDGETS section. That manpage is also available from the zsh website
Zsh Line Editor Doc: https://web.cs.elte.hu/local/texinfo/zsh/zsh_10.html
Look up system current bindkey setting: $ bindkey, eg($ bindkey|grep case, looking for down-case);
$ zle -al used for list all registered zle commands;
Bind your personal key for zsh command , $ vim ~/.zshrc, add
# bindkey
bindkey "^U" backward-kill-line
bindkey "^u" backward-kill-line
bindkey "^[l" down-case-word
bindkey "^[L" down-case-word
# alt+<- | alt+->
bindkey "^[f" forward-word
bindkey "^[b" backward-word
# ctrl+<- | ctrl+->
bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
See other things: oh-my-zsh down-case-word bug: https://github.com/robbyrussell/oh-my-zsh/commit/55a9d685fd960390a4f400ac461d901049a78beb
I'm on zsh via putty. For me the bindings were different. You can find this out with CTRL+V followed by for example the left arrow. It will display the used character sequence. So for me it was:
bindkey "^[[D" backward-word
bindkey "^[[C" forward-word
bindkey "^H" backward-kill-word
After installing oh-my-zsh, I typed bindkey 'anything' then press tab, then say yes. The list of available bindkeys will be flushed out

Fish-style Autosuggestion in Zsh?

Is there a way to do the type of auto-suggestion Fish does in Zsh?
https://github.com/tarruda/zsh-autosuggestions does exactly what I wanted. If you want fish-style autopredictions in zsh, use that.
Zsh has predict, run the commands below this and then hit Ctrl-X 1 or just type predict-on to give it a try
#-*-shell-script-*-
autoload predict-on
autoload predict-off
# you may also wish to bind it to some keys...
zle -N predict-on
zle -N predict-off
bindkey '^X1' predict-on
bindkey '^X2' predict-off

Resources