Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🛠 Better command line editing tools for Zsh

License

NotificationsYou must be signed in to change notification settings

marlonrichert/zsh-edit

Zsh Edit is a set of handy utilities for making life easier on the Zsh command line.

Requirements

Tested to work with Zsh 5.8 and newer.

Installating & updating

I recommend usingZnap or installing the plugin manually. You can alsoinstall it using any 3rd-party framework or plugin manager you like, but I won't document that here.

Using Znap

Aust add this to your.zshrc file:

znapsource marlonrichert/zsh-edit

To update, runznap pull.

Manually

  1. Clone the repo:
    % git clone --depth 1 https://github.com/marlonrichert/zsh-edit.git
  2. Source the plugin in your.zshrc file:
    source<your plugins dir>/zsh-edit/zsh-edit.plugin.zsh
  3. Restart your shell:
    exec zsh

To update:

%cd<your plugins dir>/zsh-edit% git pull

bind Command

Bind shell commands directly to keyboard shortcuts. What's more, when using these, your current command line will beleft intact.

bind'^[:''cd ..'bind'^[-''pushd -1' \'^[=''pushd +0'

List duplicate keybindings in the main keymap or another one.

bind -dbind -dM viins

List unused keybindings in the main keymap or another one.

bind -ubind -uM emacs

Look up which combination of keys could generate an escape sequence listed bybind orbindkey.

%bind -n'^[[5~''^[^[OA'"^[[5~"    PageUp"^[^[OA"   Alt-Up

Key Bindings

Zsh Edit adds the keyboard shortcuts below to yourmain andemacs keymaps.

  • By default, theemacs keymap is yourmain keymap.
  • However, if you usevi mode, then yourmain keymap will be theviins keymap.

All key bindings can be modified throughZsh'sbindkeycommand,after sourcingZsh Edit.

⚠️ Note:

  • Not all terminals support all key bindings.
  • In some terminals, instead ofAlt, you'll have to pressEsc orCtrl[.
  • In many terminals,Home,End,PgUp andPgDn scroll the terminal buffer anddon't send any keystrokes to the shell. To use these keys in the shell, you'll have to hold an additional modifierkey, usuallyShift. Refer to your terminal's documentation and/or settings for more info.
Commandemacs keymapmain keymap
Redo (reverse Undo)Alt/
Recover last line aborted withCtrlC orCtrlGCtrlAltG
Replace allCtrl]
Reverse yank popAltY
Repeat word upAlt.
Repeat word downAlt,
Repeat word leftCtrlAlt-
Repeat word rightAltShift-
BackwardsubwordCtrlAltBCtrlCtrlAlt
ForwardsubwordCtrlAltFCtrlCtrlAlt
Backward shell wordAltBAltShift
Forward shell wordAltFAltShift
Beginning of lineCtrlAHomeCtrlX
End of lineCtrlEEndCtrlX
Beginning of bufferAlt<PgUpCtrlX
End of bufferAlt>PgDnCtrlX
Backward delete character
Forward delete character
Backward killsubwordCtrlHCtrlAltCtrl
Forward killsubwordCtrlAltDCtrlAltCtrl
Backward kill shell wordCtrlWAltShift
Forward kill shell wordAltDAltShift
Backward kill lineCtrlUCtrlShiftCtrlX
Forward kill lineCtrlKCtrlShiftCtrlX

Replace All Occurences of a Character

PressCtrl] followed by two characters and each substring consisting of one ormore occurences of the first character will be replaced entirely with the second character. This isuseful, for example, if you pasted a list of files separated by line breaks into the command line,but you need them to be separated with spaces instead.

If you've just pasted something or the region is active, only the pasted or selected text isaffected. This way, you can find-and-replace selectively. Otherwise, this widget always operateson the whole command line.

Clipboard Viewer

Whenever you useyank (^Y inemacs),vi-put-after (p invicmd) orvi-put-after (P invicmd) to paste a kill into the command line,Zsh Edit will listthe contents of your kill ring (including the cut buffer) below your command line.

Additionally,Zsh Edit adds a new widgetreverse-yank-pop, which lets you cycle in theopposite direction. It is bound to^[Y in theemacs keymap.

Subword Movement

Zsh's widgetsforward-word,backward-word,kill-word andbackward-kill-wordfail to stop on many of the positions that we humans see as word boundaries:

# Zsh with default WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>' moves/deletes way too much:#              >       >             >             >          >% ENV_VAR=valuecommand --option-flag camelCaseWord~/dir/*.ext# <             <       <             <             <# Zsh with  WORDCHARS='' is bit better, but skips punctuation clusters & doesn't find subWords:#    >   >     >         >      >    >               >     >% ENV_VAR=valuecommand --option-flag camelCaseWord~/dir/*.ext# <   <   <     <         <      <    <               <     <

Zsh Edit adds new widgets with better parsing rules that can find all the word boundaries that matter to us as humans.Additionally, it adds smarter movement: If the cursor is inside a word, it will move to the beginning or end of thatsame word, not the next one. This way, you can quickly toggle between the beginning and the end of each word.

For example:

# Zsh Edit with WORDCHARS=''#   >   >     >       >  >     >    >     >   >   >  >  >      >% ENV_VAR=valuecommand --option-flag camelCaseWord~/dir/?*.ext# <   <   <     <       < <      <    <    <   <    < <      <

To stop a character from being treated as a subword separator, simply add it to$WORDCHARS. For example, by treating~,* and? as word characters, you can get more precise subword movement in path strings:

# Zsh Edit with WORDCHARS='~*?'#  > >   >  >   >%cd~/dir/?*.ext# <  < <   <  <

If you don't want to change your$WORDCHARS globally, you can instead use the following:

zstyle':edit:*' word-chars'~*?'

This will change$WORDCHARS only for the widgets provided by Zsh Edit.

Author

© 2020-2025Marlon Richert

License

This project is licensed under the MIT License. See theLICENSE file for details.

Sponsor this project

 

Contributors4

  •  
  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp