Questions tagged [zle]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
55 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 ...
  • 546
0 votes
1 answer
20 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
21 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 ...
  • 21
1 vote
0 answers
75 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 ...
  • 169
2 votes
1 answer
104 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 ...
  • 1,976
0 votes
1 answer
44 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 '...
  • 105
4 votes
2 answers
631 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
458 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?
  • 27.4k
3 votes
2 answers
501 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 ...
2 votes
3 answers
279 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, ...
1 vote
1 answer
444 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 ...
  • 2,145
3 votes
1 answer
225 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 ?
3 votes
1 answer
574 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 ...
  • 377
0 votes
1 answer
47 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
264 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
610 views

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

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
208 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 "...
  • 61
1 vote
1 answer
65 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 ...
  • 187
2 votes
1 answer
2k 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 ...
  • 123
3 votes
0 answers
81 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 ...
  • 243
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 ...
  • 167
2 votes
1 answer
139 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 ...
  • 123
4 votes
4 answers
657 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 ...
  • 17.5k
6 votes
1 answer
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. ...
0 votes
0 answers
237 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,745
1 vote
1 answer
93 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 ...
  • 113
1 vote
2 answers
2k 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 ...
  • 123
6 votes
1 answer
4k 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 ...
  • 175
0 votes
2 answers
613 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-...
  • 319
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-...
  • 165
3 votes
1 answer
291 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'...
12 votes
2 answers
6k 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 ...
user avatar
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 ...
  • 1,116
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 ...
  • 317
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. ...
  • 129
6 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....
  • 27.5k
3 votes
1 answer
265 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
613 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 ...
  • 1,720
6 votes
5 answers
10k 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 ...
  • 702
2 votes
1 answer
542 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 # ...
  • 1,168
24 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 ...
  • 5,015
3 votes
1 answer
481 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 -...
  • 2,267
2 votes
1 answer
856 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?
  • 2,486
4 votes
1 answer
1k 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 ...
7 votes
1 answer
386 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, ...
  • 1,028
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-...
  • 68.3k