Questions tagged [zle]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
911 views

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

From what I have seen, both set -o emacs and bindkey -e are used to modify the behavior of your terminal line editor to emulate emacs whereas set -o vi and bindkey -v are used to emulate vi ...
1 vote
1 answer
116 views

What do these strings, '\M^?' and '^\M?', represent in zsh/ZLE?

In the documentation for the Zsh Line Editor, there is a section that says: For either in-string or out-string, the following escape sequences are recognised: \a bell character \b ...
6 votes
2 answers
1k views

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

This is a follow-up to this question: I'm trying to create a keyboard shortcut for the terminal file manager ranger, in order to jump from the zsh prompt into the file manager with a single keystroke. ...
5 votes
2 answers
1k views

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

In bash, I used this: % cat .inputrc "\e[A": history-search-backward "\e[B": history-search-forward I'd like the same behavior in .zsh, so I've tried these bindkeys: "^[[A&...
3 votes
1 answer
321 views

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

Zsh vi mode doesn't have ctrl-o behavior set by default how do I get to work like in vim ?
6 votes
5 answers
12k views

Move to the previous line of a multi-line command

When editing multi-line commands, with escaped newlines, I cannot move up lines. For example, suppose I enter echo \ one one line, then I press Enter, and then I want to edit the echo \ part of the ...
0 votes
0 answers
145 views

Zsh: make single file selection smart, stylish, and functionally correct (highlights, completions below cursor, etc)

I would like to have a near-flawless "single file selector" with zsh. So far I haven't seen one in questions as they tend to focus on zle settings for one's command line. Let's say we are ...
0 votes
1 answer
41 views

How to change meta to option (macOS) in zle emacs keymap?

Since I use both bash and zsh, I'd like to learn the zle's emacs keymap (since this is the default in bash). My problem is that macOS's option key does not work with the meta shortcuts (like M-. for ...
2 votes
0 answers
48 views

how to change prompt of zle widgets (history-incremental-backward-search)?

Is there a way to change the prompt of zle widgets such as history-incremental-backward-search? For instance I wonder if we can colorize "bck-i-search:" or change the string, or colorize the ...
1 vote
0 answers
353 views

What is the current zle keymap/mode?

For example, if I hit the right combination of keys to enter viins and walk away from the terminal and forget, how can I tell when I get back? How can I tell what the default mode is? The guide has ...
2 votes
3 answers
703 views

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

When using Ctrl+w or Alt+Backspace or Alt+d keyboard shortcuts to delete words backward/forward, I know I can define the WORDCHARS characters: WORDCHARS='~!#$%^&*(){}[]<>?.+;-' for example, ...
2 votes
1 answer
223 views

Fuzzy Search History: Show History Keeping The Lines Intact For Multi-Line Commands

I am working on a zsh widget to fuzzy search history. skim-history() { origquery=${BUFFER} output=$(history -1 1 | sd '^[ ]*[0-9]*[ ]*' '' | sk --tac --no-sort --exact) if [ $? -eq 0 ]; then ...
0 votes
1 answer
77 views

How to cancel a zle function after triggering the bindkey?

Hope you're doing well. I have the following in my .zshrc: # 1. invoke zoxide to pick dir # 2. open target dir in ranger # 3. when exiting ranger, cd into last dir zoxide_to_ranger () { eval '...
3 votes
2 answers
886 views

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

I am using zsh with bindkeys -v. Alt + . does not work as expected. It seems to repeat what is currently typed in stdin, but not entered, on the next line. This post seems to imply it does work as it ...
3 votes
1 answer
947 views

What is the "global keymap" in zsh?

In the zsh manual 18.2.2 Local Keymaps it refers to the "global keymap" thrice. Where is this term defined? How do I find out what is my current global keymap, and how would I change it?
2 votes
1 answer
818 views

Is it possible to delete a word in the forward direction with zsh?

I found that I was able to implement Ctrl+Delete in bash using "^[[3;5~": shell-kill-word inside my ~/.inputrc.  However, zsh does not use inputrc, and ZLE has no shell-kill-word option that ...
3 votes
1 answer
538 views

Why does select-word-style stop me from using backward-kill-word for leading whitespace?

If I have just some whitespace at be beginning of my zsh prompt, I can usually ^W (backward-kill-word) it away. However, as soon as I load select-word-style - even if I don't select any special style -...
25 votes
3 answers
7k views

How to configure Ctrl+w as delete word in zsh

I want to delete a word by Ctrl+W in zsh like. vim /foo/bar^W vim /foo/ And found a solution for bash, but bind is not in zsh function. Is it possible to configure ctrl-w (delete word)? How can I ...
4 votes
1 answer
2k views

How can you get the current terminal line (the one that is still editable by the user)?

I need a way to use the current line which the users typed into as variable for a shell function. my current code, which can be called by ctrl+r zle -N search bindkey "^R" search search () { read ...
13 votes
2 answers
7k views

Bindkey to execute command (Zsh)

In bash one can do the following: bind -x '"\C-l":ls' to map Ctrl+L to external (ie. system's rather than readline function) ls command to list directory contents. How to do the same in zsh, and ...
3 votes
1 answer
800 views

Using fzf in a zle key binding

I have the following function in my .zshrc function foo() { filename="$(fzf)" } zle -N foo bindkey '^X' foo now if I call foo by typing it, it works as expected, but if I call it via ...
3 votes
1 answer
344 views

How to repeat a zle widget an arbitrary number of times when the completion menu is open?

I'm using the zsh shell, and I'm trying to install a few key bindings to use keys similar to the ones I would use in a Vim buffer, when a completion menu is open. So, inside the menuselect keymap I'...
2 votes
1 answer
406 views

zsh: PageUp in menu completion

In my .zshrc I have zstyle ':completion:*' menu select=20 This way when I hit Tab twice, I receive a menu of completions (assuming there are at least 20 to choose from). I can then navigate it ...
0 votes
1 answer
54 views

How to bind _list_expansions in Zsh Line Editor

I'm trying to bind "possible completions" (currently bound to C-d) to the key M-= in Zsh. The code, therefore, should be: bindkey "\e=" _list_expansions but it has no effect!? Do you understand ...
1 vote
1 answer
265 views

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

zle widgets working by Ctrl-Right keys, Ctrl-Left keys (first widget is starting selection mode): c-sel-r-reg () { local WORDCHARS=${WORDCHARS/\/} zle select-in-word } zle -N c-sel-r-reg bindkey "...
3 votes
1 answer
2k views

zsh: Where is the `key` -> `terminfo` dictionary defined

I'm learning zsh at the moment, and configuring my ~/.zshrc. On the Archwiki, I found a snippet to change the history searching behavior: autoload -Uz up-line-or-beginning-search down-line-or-...
1 vote
1 answer
84 views

Get if command is multiline in a ZLE widget

How can I get whether the command being typed is multiline? $CONTEXT can determine when at a secondary prompt like: $ echo 'hello quote> world' But how can I determine when there's a newline ...
2 votes
1 answer
3k views

Setting new key bindings in ZSH removes default ones

I've added following code at the end of my .zshrc: export VISUAL=vim autoload edit-command-line; zle -N edit-command-line bindkey -M vicmd v edit-command-line When I restart the shell, it works ...
3 votes
0 answers
123 views

Is there any way to change $? from a zle widget?

I have a widget for mapping ^Z to fg: function ctrlz() { [[ $(jobs | wc -l) > 0 ]] && { zle -I fg } } However, since widgets can't change $?, the exit status of ...
4 votes
2 answers
3k views

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

I (ab)use Alt + . to recover the last argument in a previous command (I'm using ZSH): for example, $ convert img.png img.pdf $ llpp (alt + .) # which produces llpp img.pdf but sometimes I review a ...
2 votes
1 answer
155 views

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

Given .zshrc config: bindkey -v bindkey "^R" history-incremental-pattern-search-backward When I type foo<^R>bar at an empty prompt, it searches for the most recent command matching bar. How ...
4 votes
4 answers
749 views

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

Suppose I do something like: ln a_file_with_a_long_filename.pdf ~/path/to/a/new/hardlink/a_file_with_a_long_filename_slightly_modified.pdf Is there a way to refer to and expand ...
0 votes
0 answers
276 views

Avoid terminal scroll issue when using zle reset-prompt

I use TMOUT=10 - 10s to update time in prompt so it caused scroll always go back to current prompt. For i.e: If I scroll back serverl pages of output then 10s later, zsh scroll down when prompt was ...
1 vote
2 answers
3k views

Using putty, Left and Right keys move cursor one word, instead of one char

I have looked for a solution to this OhMyZSH! problem for a few days now, but can't find a solution. Admittedly, I do not understand how zle really works, same for bindkey. Same goes for the way ...
1 vote
1 answer
104 views

Entering . (dot) cancels zsh incremental history search

History Search Ctrl+R in my zsh cancels if I enter the dot . character. If I hit Ctrl+R the bck-i-search: prompt appears and the history is searched according to the words I enter. But as soon as I ...
8 votes
1 answer
5k views

ZLE: Key bindings codes list

I know that in bindkey '\ep' autosuggest-accept-suggested-small-word the \e refers to the ⎇ Alt key. I also know that C- refers to the ⎈ Ctrl key. Is there a list referencing ...
0 votes
2 answers
778 views

Why isn't zsh autocomplete using history behaving consistently from login to login?

After adding the following lines to my .zshrc: autoload -U up-line-or-beginning-search autoload -U down-line-or-beginning-search zle -N up-line-or-beginning-search zle -N down-line-or-beginning-...
5 votes
5 answers
1k views

How to repeat currently typed in parameter in zsh?

Sometimes we just need to type a slightly different name when using mv/cp/convert. For example, convert IMG-long-number.jpg IMG-long-number.png How can I repeat IMG-long-number.jpg before typing ...
6 votes
1 answer
1k views

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

I'm messing around with the accept-line widget and not getting the results I want. I want to inspect (and log) what is happening to accept-line by finding the underlying zsh function. My ...
4 votes
1 answer
1k views

Zsh clear command line from zsh/sched call

I try the following: clear-cmdline() { zle && zle kill-buffer sched +3 clear-cmdline } sched +3 clear-cmdline After I run this code, I enter a few letters at prompt, and wait. ...
9 votes
1 answer
4k views

Backspace in zsh stuck

In set -o vi mode in bash, when I press Esc+k to get the last entered command, and then A, I end up in the insert mode, which allows me to press backspace to start deleting the end of the last command....
3 votes
1 answer
318 views

Write warning while typing in zsh prompt

I know that it is possible to display text "outside" of the zsh prompt where you are typing. Common example is completions: myhost Wed 8 10:06 ~/sandlot $ e .py█ Press Tab, et voilá: myhost Wed 8 ...
1 vote
2 answers
659 views

zle read first word in line?

Let us say: % ls ./ _ when foo is called, where _ is the cursor position. foo(){ echo $COMMAND } zle -N foo How can COMMAND be set such that foo will write out the 'command' (as in, the first ...
2 votes
1 answer
579 views

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

I've been tinkering with my dotfiles lately, and at some point I lost use of the default ^A and ^K keymappings, which I use frequently. bindkey -L | grep '\^[AK] # bindkey -R "^A"-"^C" self-insert # ...
2 votes
1 answer
918 views

Key to comment out the current line and keep editing it in zsh

On Bash I was using ESC # after Ctrl+R to prefix a # to the found line and keep it in the terminal, something similar for zsh?
7 votes
1 answer
524 views

How can I get back into "normal" edit-mode after pressing esc in zsh (vi mode)?

I'm using zsh in vi-mode. When I go to normal mode with ESC and then back into insert mode (for example using i, a or s), the line editor kind of "protects" the part of the line in front of the char, ...
7 votes
1 answer
1k views

How can I configure ZSH's vi mode to persist the state between commands?

I am aware how to set ZSH's default line editor to use vi-like keybindings... bindkeys -v ...and even to default each new prompt to be in command mode instead of insert mod by default... zle-line-...