Skip to main content
added 106 characters in body
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

Both bash and zsh give you a choice of vi-like or emacs-like bindings, with emacs being the default. In zsh, unlike bash, if you setthe VISUAL or EDITOR environment variables are set to anything that contains vi then zsh turns on vi-like bindings. In zsh, many useful commands only have a default binding in emacs mode. Put bindkey -e in your .zshrc to use emacs-like bindings regardless of the contents of those variables.

Both bash and zsh give you a choice of vi-like or emacs-like bindings, with emacs being the default. In zsh, unlike if you set VISUAL or EDITOR to vi then zsh turns on vi bindings. In zsh, many useful commands only have a default binding in emacs mode. Put bindkey -e in your .zshrc to use emacs-like bindings.

Both bash and zsh give you a choice of vi-like or emacs-like bindings, with emacs being the default. In zsh, unlike bash, if the VISUAL or EDITOR environment variables are set to anything that contains vi then zsh turns on vi-like bindings. In zsh, many useful commands only have a default binding in emacs mode. Put bindkey -e in your .zshrc to use emacs-like bindings regardless of the contents of those variables.

Source Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k

Emacs vs vi bindings

Both bash and zsh give you a choice of vi-like or emacs-like bindings, with emacs being the default. In zsh, unlike if you set VISUAL or EDITOR to vi then zsh turns on vi bindings. In zsh, many useful commands only have a default binding in emacs mode. Put bindkey -e in your .zshrc to use emacs-like bindings.

Insert last word

Alt+. to insert the last shell word of the previous command works out of the box in zsh just like bash.

written by GPT

That's your problem.

Looking in your configuration file, I see you've tried to make it work differently, but I'm not sure what you wanted to achieve. If you want something different from ksh/bash/zsh's Alt+., I suggest you ask a new question here.

bindkey '^[.' insert-last-word is already the default setting. You're getting an error message because of zle -N insert-last-word: that defines insert-last-word as a widget (i.e. something that can be bound to a key) which invokes the function of the same name. But there is no function by that name. insert-last-word already exists as a built-in widget.

Zsh has some useful related commands which are not bound by default.

  • copy-prev-shell-word copies a word from the same command line. You get the last word by default, or the nth earlier word with a numeric argument (e.g. ESC 2 ESC + to copy the next-to-last word if you've bound the command with bindkey '^[+' copy-prev-shell-word).
  • copy-earlier-word extends insert-last-word with a facility to get a word other than the last one. This one is a loadable function, so you need to load it, then make a widget for it and then you can bind it to a key.
    autoload -U copy-earlier-word
    zle -N copy-earlier-word
    bindkey '^[,' copy-earlier-word
    

Cursor motion keys

See Home key not working in terminal

Word motion

forward-word and such does respect WORDCHARS. If you want word motion to stop at slashes, remove / from $WORDCHARS.

If you'd like more flexibility, zsh ships with a word-style widget set. It makes word motion obey the current word style, with a widget select-word-style to change that. You can also bind keys to word motion commands with a specific word style.

Cache of completions

Both bash and zsh maintain a cache of the locations of commands in the search path ($PATH). In both shells, if you install a new executable earlier in the path than an existing one with the same name, the shell will remember the old location until you tell it to update the cache with the hash command.

In zsh, annoyingly, negative results are also cached. So if you install a new executable, you need to tell zsh to reload the list of commands with rehash or hash -rf.

Zsh tips for a bash convert

  • Zsh's default configuration is very barebones — it's basically unchanged from over 30 years ago. zsh-newuser-install gives you a few basics but there is much more that's available if you only know where to find it. There are a few zsh configuration management frameworks that activate features in batches and give you easy access to third-party plugins. Their downside is that instead of trying to understand zsh, you end up trying to understand that framework and zsh. YMMV.
  • What are the practical differences between Bash and Zsh?
  • Why zsh is cooler than your shell
  • Import bash history to zsh