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

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

Related

_expand_alias widget seems to be missing from ZLE

I'm trying to auto-expand aliases as I type in zsh using the globalias plugin from oh-my-zsh. It was working when I first installed the plugin, but now it has broken. I think it broke after I rearranged the lines in my ~/.zshrc but I'm not sure.
I've tried to simplify the problem by removing everything except the following lines form my ~/.zshrc (I got this from a reddit thread but it also looks v similar to the function in the globalias plugin):
function expand-alias() {
zle _expand_alias
zle self-insert
}
zle -N expand-alias
bindkey -M main ' ' expand-alias
When I source this file and type a space in my prompt, I see
No such widget `_expand_alias'
I've tried googling and it seems like _expand_alias should be a built-in ZLE function, but when I look for it with zle -la | grep _expand_alias it's not there.
I'm not sure what to try next? I can't find a way to reset zsh or the built-in ZLE commands.
I solved it by adding the line autoload -Uz compinit && compinit near the start of my ~/.zshrc.
Hope this helps someone!

What is the bindkey equivalent to bind -x?

In this question, the inimitable Dennis Williamson mentions how to bind a keystroke to a command that will run in the background of the Bash shell, with bind -x. How can the same thing be done in Zsh?
(I couldn't find this in the zshzle man page, but it's possible that I overlooked it.)
You can use zle -M to display info underneath your command line. For example:
.who() {
zle -M "$(who)"
}
# Create a new widget `who` that calls our function `.who`.
zle -N who .who
# Bind said widget to alt-shift-W.
bindkey '^[W' who

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.

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