Hot answers tagged

26 votes
Accepted

How to configure Ctrl+w as delete word in zsh

Here's a snippet from .zshrc i've been using: my-backward-delete-word() { local WORDCHARS=${WORDCHARS/\//} zle backward-delete-word } zle -N my-backward-delete-word bindkey '^W' my-backward-...
Joe's user avatar
  • 544
24 votes
Accepted

Backspace in zsh stuck

The quick answer, put this in your ~/.zshrc: bindkey -v '^?' backward-delete-char Normally '^?' (backspace) is bound to vi-backward-delete-char, which is supposed to have the behavior you observe, ...
phemmer's user avatar
  • 71.6k
17 votes

Bindkey to execute command (Zsh)

% namingthingsishard () { echo; ls; zle redisplay } % zle -N namingthingsishard % bindkey '^l' namingthingsishard % This binds control+l because I don't know what ...
thrig's user avatar
  • 34.9k
16 votes

How to configure Ctrl+w as delete word in zsh

Just for your information, I found this solution here to be far more elegant. I quote: Another option is to set WORDCHARS (non-alphanumeric chars treated as part of a word) to something that doesn'...
Anastasios Andronidis's user avatar
8 votes
Accepted

ZLE: Key bindings codes list

^ in ZSH (and many other softwares; see for example stty -a) refers to control key e.g. for control-L to clear the screen one might find in the ZSH keybindings list % bindkey | grep clear "^L" clear-...
thrig's user avatar
  • 34.9k
8 votes
Accepted

How to bind a keyboard shortcut in zsh to a program requiring stdin?

@llua's comment was indeed the trick to solve the stdin issue, thanks! My use case required yet another deviation from the linked question. I'm using ranger to change the working directory (using ...
bluenote10's user avatar
8 votes

Bindkey to execute command (Zsh)

CTRL+L to run 'ls' bindkey -s "^L" 'ls^M'
Ahmad Ismail's user avatar
  • 2,648
8 votes

How to configure Ctrl+w as delete word in zsh

None of the answers so far provide all the properties that bash has. Namely: CTRL-w deletes any non-space char. CTRL-w puts the text in the kill ring (so it can then be pasted with CTRL-y). CTRL-w ...
sitaktif's user avatar
  • 183
7 votes
Accepted

How to repeat currently typed in parameter in zsh?

!#$<Tab> works for me. Given: $ echo a Typing !#$ then pressing Tab expands !#$ to a. Tab completion also lists other options if you try an operation with :: $ echo a !#$: & -- repeat ...
muru's user avatar
  • 72.2k
7 votes
Accepted

How can I find the zsh function associated with a zle widget?

There is a special array called widgets which holds names of all widgets and functions associated to them, so try echo $widgets[accept-line] Be aware however that some widgets are defined internally ...
jimmij's user avatar
  • 46.9k
6 votes
Accepted

Alt + . (dot) shows &, instead of a previous argument

ESC-. (insert-last-word) considers any space-separated or space-separable shell token¹ a “word“, including punctuation tokens such as &. You can give it a numeric argument to grab a word other ...
Gilles 'SO- stop being evil''s user avatar
5 votes
Accepted

Move to the previous line of a multi-line command

When you press Enter (accept-line command), the current line is parsed and scheduled for execution. If the line is syntactically incomplete (e.g. echo \ or for x in foo), it isn't executed, but it's ...
Gilles 'SO- stop being evil''s user avatar
5 votes

zsh history-beginning-search-backwards doesn't position cursor as desired

Binding that to the Up key means that when it comes to editing a multi-line command, you wont be able to move the cursor up. That's why the default widget bound to Up is up-line-or-history, which ...
Stéphane Chazelas's user avatar
4 votes
Accepted

Why are some ZLE sequences being remapped to "self-insert"?

I figured it out! From the zshzle man page: In addition to these names, either 'emacs' or 'viins' is also linked to the name 'main'. If one of the VISUAL or EDITOR environment variables contain ...
shadowtalker's user avatar
  • 1,318
4 votes

How to repeat currently typed in parameter in zsh?

An alternative to bear in mind is that: you don't. After using completion to get convert IMG-long-number.jpg simply edit that into convert IMG-long-number.{jpg,png}
JdeBP's user avatar
  • 68.4k
4 votes
Accepted

zsh: populate search input with existing line contents when ^R is pressed?

If you bind ^R to history-beginning-search-backward, it comes close, but that's not a pattern search. You can bind ^R to a function that adds the current content of the line as the initial search ...
Gilles 'SO- stop being evil''s user avatar
4 votes
Accepted

How to cancel selection mode in zsh in other way than add text to $BUFFER?

To cancel what you're calling "selection mode" from a zsh zle widget, it is: zle set-mark-command -n -1 or if you prefer: REGION_ACTIVE=0 What zsh supports comes in mostly emacs and vim compatible ...
okapi's user avatar
  • 697
4 votes
Accepted

zsh: PageUp in menu completion

Menu completion invokes the menu selection code form the zsh/complist module. This module only allows a limited selection of commands, but this does include “moves the mark one screenful up/down”. ...
Gilles 'SO- stop being evil''s user avatar
4 votes
Accepted

How to use `Alt + .` in zsh with Vim bindings

On a terminal, Alt+char is normally the same as Esc char. (It's possible to configure some terminals differently.) In vi insert mode, Esc switches to command mode. In vi command mode, Esc does nothing....
Gilles 'SO- stop being evil''s user avatar
3 votes

Zsh refer to last element of current argument list and expand it

With the default Emacs bindings, it's just two keychords: ESC-2 ESC-^_ (i.e. Esc 2 Esc Ctrl+_ or Alt+2 Ctrl+Alt+_). That's the command copy-prev-word with the numeric argument 2 (the default argument ...
Gilles 'SO- stop being evil''s user avatar
3 votes
Accepted

Entering . (dot) cancels zsh incremental history search

By default, . is an ordinary character. If it behaves this way for you, it's because of something in your configuration, possibly something buried inside oh-my-zsh. A binding in the main keymap ...
Gilles 'SO- stop being evil''s user avatar
3 votes

How to repeat currently typed in parameter in zsh?

I'd use Ctrl+Alt+_ that copies the previous word (copy-prev-word widget). Once copied, you can use Backspace to edit the extension of the copy. Or use Ctrl+W to delete it as a whole. By default, Ctrl+...
Stéphane Chazelas's user avatar
3 votes

Move to the previous line of a multi-line command

Assuming you have the default emacs keybindings, try using Alt+Enter instead of plain Enter to schedule a line for execution. For me when the lines are added this way I can easily move up and down ...
the_velour_fog's user avatar
3 votes
Accepted

Get if command is multiline in a ZLE widget

The complete content of the logical input line is in BUFFER. [[ $BUFFER == *$'\n'* ]]
Gilles 'SO- stop being evil''s user avatar
3 votes
Accepted

What is the difference between `set -o emacs` vs `bindkey -e`?

bindkey -v/-e is the tcsh syntax (a bindkey builtin was added to tcsh in 5.19PL2 in 1990), while set -o vi/emacs is the ksh syntax (already there in ksh85, probably earlier as ksh had emacs/vi mode at ...
Stéphane Chazelas's user avatar
3 votes
Accepted

Using fzf in a zle key binding

If the point is to insert the output of fzf at the current cursor position, properly quoted, it should be something like: insert-quoted-fzf-output() { local output output=$(fzf</dev/tty) &&...
Stéphane Chazelas's user avatar
3 votes
Accepted

Make one normal mode command while in insert mode in zsh's vi mode

It's as simple as this: vi-cmd () { local REPLY # Read the next keystroke, look it up in the `vicmd` keymap and, if successful, # evalute the widget bound to it in the context of the `vicmd` ...
Marlon Richert's user avatar
3 votes
Accepted

zsh keybindings: make backward-kill-word act on whole quoted string

The shell word style does exactly this. autoload -U select-word-style select-word-style shell
Gilles 'SO- stop being evil''s user avatar
3 votes
Accepted

What is the "global keymap" in zsh?

The line editor has a global keymap active at any time. This is normally the emacs keymap when using Emacs mode, or either viins or vicmd when using Vi mode. You can select a different one with zle -K ...
Gilles 'SO- stop being evil''s user avatar
2 votes

zle read first word in line?

You have access to a number of variables in user-defined widgets, in particular BUFFER which contains the content of the line (or more broadly, the whole buffer, which can be multiline). How to ...
Gilles 'SO- stop being evil''s user avatar

Only top scored, non community-wiki answers of a minimum length are eligible