Skip to content

Editor-style selection and editing for Zsh: Shift/Shift+Ctrl selection, mouse-integration, type-to-replace, and clipboard-aware copy/cut/paste/replace behavior.

License

Notifications You must be signed in to change notification settings

Michael-Matta1/zsh-edit-select

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zsh Edit-Select

Modern text selection and editing for Zsh command line. Select text with Shift + Arrow keys, type-to-replace, paste-to-replace, mouse selection integration, and clipboard integration for copy/cut/paste like in GUI text editors.

Demo


Table of Contents


Overview

Zsh Edit-Select brings familiar text editor behaviors to your Zsh command line:

  • Shift selection — Select text using Shift + Arrow keys
  • Type-to-replace — Type over selected text to replace it
  • Paste-to-replace — Paste clipboard content over selections
  • Mouse integration — Works with text selected by mouse
  • Clipboard integration — Works with X11 and Wayland
  • Standard shortcuts — Ctrl+A (select all), Ctrl+C (copy), Ctrl+X (cut), Ctrl+V (paste)

Ready to Use: The plugin works immediately after installation with sensible defaults. Use the command edit-select config to customize clipboard backend, mouse behavior, and keybindings.


Features

Keyboard Selection

Select text using familiar keyboard shortcuts:

Shortcut Action
Shift + ←/→ Select character by character
Shift + ↑/↓ Select line by line
Shift + Home/End Select to line start/end
Shift + Ctrl + ←/→ Select word by word
Ctrl + A Select all text (including multi-line commands)

Mouse Selection Integration

The plugin intelligently integrates mouse selections:

When Mouse Replacement is Enabled (default):

  • ✅ Copy mouse selections with Ctrl+C
  • ✅ Cut mouse selections with Ctrl+X
  • ✅ Type to replace mouse selections
  • ✅ Delete mouse selections with Backspace
  • ✅ Paste over mouse selections with Ctrl+V

When Mouse Replacement is Disabled:

  • ✅ Copy mouse selections with Ctrl+C (still works)
  • ❌ Other operations only work with keyboard selections

Note: Configure mouse behavior with edit-select config → Option 2

⚠️ Important Note on Mouse Selection: If your command contains multiple occurrences of the exact same selected text, mouse selection will replace/delete the first matching occurrence in the buffer—not necessarily the one you visually selected. For more reliable selection, especially with duplicate text, use Shift + Arrow keys instead of mouse selection.

Type-to-Replace and Paste-to-Replace

Type or paste while text is selected to replace it automatically.

Works with both keyboard and mouse selections (when mouse replacement is enabled).

Copy, Cut, and Paste

Standard editing shortcuts:

  • Ctrl + C (or Ctrl+Shift+C): Copy selected text
  • Ctrl + X: Cut selected text
  • Ctrl + V: Paste (replaces selection if any)

Automatic Clipboard Detection

The plugin automatically detects your display server:

Display Server Tools Used
Wayland wl-copy / wl-paste
X11 xclip
macOS pbcopy / pbpaste

Quick Start

1. Install the Plugin

Oh My Zsh: (for other plugin managers check Installation)

git clone https://github.com/Michael-Matta1/zsh-edit-select.git \
  ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-edit-select

Add to your .zshrc:

plugins=(... zsh-edit-select)

Manual:

git clone https://github.com/Michael-Matta1/zsh-edit-select.git \
  ~/.local/share/zsh/plugins/zsh-edit-select

# Add to ~/.zshrc:
source ~/.local/share/zsh/plugins/zsh-edit-select/zsh-edit-select.plugin.zsh

2. Install Clipboard Tools

Wayland:

# Debian/Ubuntu
sudo apt install wl-clipboard

# Arch Linux
sudo pacman -S wl-clipboard

# Fedora
sudo dnf install wl-clipboard

X11:

# Debian/Ubuntu
sudo apt install xclip

# Arch Linux
sudo pacman -S xclip

# Fedora
sudo dnf install xclip

3. Configure Your Terminal

Some terminals need configuration to support Shift selection. See Terminal Setup for details.

4. Restart Your Shell

source ~/.zshrc

Important: You may need to fully close and reopen your terminal (not just source ~/.zshrc) for all features to work correctly, especially in some terminal emulators.

You're ready! Try selecting text with Shift + Arrow keys.

5. (Optional) Customize Settings

The plugin works immediately with sensible defaults, but you can customize:

  • Clipboard backend (Wayland/X11/auto-detect)
  • Mouse replacement behavior
  • Keybindings (Ctrl+A, Ctrl+V, Ctrl+X)

Run the interactive configuration wizard:

edit-select config

Installation

Oh My Zsh
  1. Clone the repository:
git clone https://github.com/Michael-Matta1/zsh-edit-select.git \
  ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-edit-select
  1. Add to your .zshrc:
plugins=(
  # ... other plugins
  zsh-edit-select
)
  1. Restart your terminal or run:
source ~/.zshrc
zgenom

Add to your .zshrc:

zgenom load Michael-Matta1/zsh-edit-select
sheldon

Run:

sheldon add zsh-edit-select --github Michael-Matta1/zsh-edit-select
Manual Installation
  1. Clone the repository:
git clone https://github.com/Michael-Matta1/zsh-edit-select.git \
  ~/.local/share/zsh/plugins/zsh-edit-select
  1. Add to your .zshrc:
source ~/.local/share/zsh/plugins/zsh-edit-select/zsh-edit-select.plugin.zsh
  1. Restart your terminal or run:
source ~/.zshrc

Configuration

Configuration Wizard

Launch the interactive configuration wizard:

edit-select config

The wizard provides:

  1. Clipboard Integration — Choose Wayland, X11, or auto-detect
  2. Mouse Replacement — Enable/disable mouse selection integration
  3. Key Bindings — Customize Ctrl+A, Ctrl+V, Ctrl+X shortcuts
  4. View Configuration — See current settings
  5. Reset to Defaults — Restore factory settings

All changes are saved to ~/.config/zsh-edit-select/config and persist across sessions.

Mouse Replacement Modes

Configure how the plugin handles mouse selections:

Enabled (default):

  • Full integration: type, paste, cut, and delete work with mouse selections
  • Best for users who want seamless mouse+keyboard workflow

Disabled:

  • Mouse selections can be copied with Ctrl+C
  • Typing, pasting, cutting, and deleting only work with keyboard selections
  • Best for users who prefer strict keyboard-only editing

Change the mode:

edit-select config  # → Option 2: Mouse Replacement

Note: If you have mouse replacement enabled, the repositioning of the text cursor (caret) when clicking with the mouse may become slower on some systems when working with long multi-line commands (typically more than 5 lines). If you care more about fast mouse-click cursor positioning than about the mouse-replacement feature, you can disable mouse replacement using the wizard.

Clipboard Integration

The plugin auto-detects your clipboard backend, but you can override it:

Auto-detect (recommended): Automatically uses the right tool for your display server.

Note: If no clipboard tool is detected, the plugin will still work for text selection and keyboard-based operations, but copy/cut/paste will be disabled.

Manual configuration:

edit-select config  # → Option 1: Clipboard Integration

Choose:

  • Wayland — Uses wl-copy/wl-paste
  • X11 — Uses xclip

Keybinding Customization

Customize the main editing shortcuts:

edit-select config  # → Option 3: Key Bindings

Default bindings:

  • Ctrl + A — Select all
  • Ctrl + V — Paste
  • Ctrl + X — Cut

Alternative presets:

  • Ctrl + Shift + A/V/X — For terminals with Kitty protocol
  • Custom — Enter your own key sequences
Custom Keybinding Notes

⚠️ Important: When using custom keybindings (especially with Shift modifiers), you may need to configure your terminal emulator to send the correct escape sequences.

For Kitty:

If you want to use Ctrl + Shift + X for cut, add this to your kitty.conf:

map ctrl+shift+x send_text all \x1b[88;6u

For Other Terminals:

  • WezTerm — Use similar key remapping in wezterm.lua
  • Alacritty — Use key bindings in alacritty.yml
  • VS Code Terminal — Add to keybindings.json

Terminal Setup

Step 1: Configure Copy Shortcut

⚠️ CRITICAL: Before adding these mappings, you MUST remove or comment out any existing ctrl+shift+c mappings in your terminal config (such as map ctrl+shift+c copy_to_clipboard in Kitty). These will conflict and prevent the plugin from working correctly.

Using Ctrl+Shift+C (Default)

To use Ctrl + Shift + C for copying, add the following to your kitty.conf:

map ctrl+shift+c send_text all \x1b[67;6u

Using Ctrl+C for Copying (Reversed)

If you prefer to use Ctrl + C for copying (like in GUI applications) and Ctrl + Shift + C for interrupt:

# Ctrl+C sends the escape sequence for copying
map ctrl+c send_text all \x1b[67;6u


# Ctrl+Shift+C sends interrupt (default behavior)
map ctrl+shift+c send_text all \x03

For Other Terminals:

  • WezTerm — Use similar key remapping in wezterm.lua
  • Alacritty — Use key bindings in alacritty.yml

Alternative: Without Terminal Remapping

If your terminal doesn't support key remapping, you can add the following to your ~/.zshrc to use Ctrl + / for copying:

x-copy-selection () {
  if [[ $MARK -ne $CURSOR ]]; then
    local start=$(( MARK < CURSOR ? MARK : CURSOR ))
    local length=$(( MARK > CURSOR ? MARK - CURSOR : CURSOR - MARK ))
    local selected="${BUFFER:$start:$length}"
    print -rn "$selected" | xclip -selection clipboard
  fi
}
zle -N x-copy-selection
bindkey '^_' x-copy-selection

You can change the keybinding to any key you prefer. For example, to use Ctrl + K:

bindkey '^K' x-copy-selection

Note: The ^_ sequence represents Ctrl + / (Ctrl + Slash), and ^K represents Ctrl + K. You can find other key sequences by running cat in your terminal and pressing the desired key combination.

Bonus Feature: If no text is selected, this manual keybinding will copy the entire current line to the clipboard.


Step 2: Enable Shift Selection Keys

Some terminals intercept Shift key combinations by default. Here's how to configure popular terminals:

Kitty

Add to kitty.conf:

# Enable Shift selection
map ctrl+shift+left no_op
map ctrl+shift+right no_op
map ctrl+shift+home no_op
map ctrl+shift+end no_op

WezTerm

Add to wezterm.lua:

return {
  keys = {
    { key = 'LeftArrow', mods = 'CTRL|SHIFT', action = 'DisableDefaultAssignment' },
    { key = 'RightArrow', mods = 'CTRL|SHIFT', action = 'DisableDefaultAssignment' },
  },
}

VS Code Terminal

The escape sequences used follow the ANSI/VT terminal protocol.

Add to keybindings.json:

[
    {
        // Make Ctrl+C sends copy sequence to terminal (CSI 67 ; 6 u)
        "key": "ctrl+c",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u001b[67;6u" },
        "when": "terminalFocus"
    },
    {
        // Make Ctrl+Shift+C sends interrupt signal (ETX control character)
        // This is equivalent to the traditional Ctrl+C interrupt behavior
        "key": "ctrl+shift+c",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u0003" },
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+shift+left",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u001b[1;6D" },
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+shift+right",
        "command": "workbench.action.terminal.sendSequence",
        "args": { "text": "\u001b[1;6C" },
        "when": "terminalFocus"
    }
]

Alacritty

Alacritty doesn't need a tweak to enable Shift/Shift+Ctrl selection, but you will need to configure the copy shortcuts for the clipboard the same as the other terminals.


Step 3: Verify Key Sequences

To check what your terminal sends:

  1. Run cat (without arguments)
  2. Press the key combination
  3. The terminal will display the escape sequence

Use this sequence for custom keybindings in the configuration wizard and replace the "text" values in the configuration of VS Code Terminal.


Platform Compatibility

Mouse Selection Replacement Feature

The Mouse Selection Replacement feature (automatically detecting and replacing mouse-selected text) has varying support across platforms:

✅ Fully Supported

  • X11 - Complete PRIMARY selection support (recommended for best experience)
  • wlroots-based Wayland compositors - Sway, Hyprland, River, Wayfire
  • KDE Plasma Wayland - Full PRIMARY selection support

⚠️ Limited/No Support

  • GNOME Wayland (Mutter) - No PRIMARY selection support
  • macOS - No PRIMARY selection concept in the system
  • Other Wayland compositors - Support varies

Recommendation

For the most stable and robust experience with all plugin features, X11 is recommended. While Wayland support is improving, PRIMARY selection implementation is inconsistent across compositors.

If Mouse Selection Replacement doesn't work on your platform, disable it with edit-select config → Option 2.

Testing Coverage

This plugin has been thoroughly and heavily tested on Kitty Terminal on X11 and briefly on other popular terminals.

If you encounter issues on other terminals or platforms, please open an issue with your terminal name, OS, and display server.

Core Features (Available on All Platforms)

These features work universally regardless of platform:

  • ✅ Shift+Arrow keys for text selection
  • ✅ Ctrl+A (Cmd+A) to select all
  • ✅ Ctrl+C (Cmd+C) to copy
  • ✅ Ctrl+X (Cmd+X) to cut keyboard selection
  • ✅ Ctrl+V (Cmd+V) to paste
  • ✅ Delete/Backspace to remove keyboard selection
  • ✅ Type or paste to replace keyboard selection

Key Bindings Reference

Selection Keys

Key Combination Action
Shift + ← Select one character left
Shift + → Select one character right
Shift + ↑ Select one line up
Shift + ↓ Select one line down
Shift + Home Select to line start
Shift + End Select to line end
Shift + Ctrl + ← Select to word start
Shift + Ctrl + → Select to word end
Ctrl + A Select all text

macOS: Use Shift + Option instead of Shift + Ctrl for word navigation

Editing Keys

Key Combination Action
Ctrl + C Copy selected text
Ctrl + X Cut selected text
Ctrl + V Paste (replaces selection if any)
Delete Delete selected text (selection mode only)
Backspace Delete selected text (selection mode only)
Any character Replace selected text

Common Issues - Quick Fixes

Problem Quick Fix
Shift selection doesn't work Configure your terminal (see Terminal Setup)
Copy doesn't work Install clipboard tool: wl-clipboard or xclip
Mouse replacement slow Disable it: edit-select config → Option 2
Ctrl+C copies instead of interrupting Remap in terminal to use Ctrl+Shift+C for copy
Can't paste with Ctrl+V Check terminal keybinding conflicts or use config wizard
Configuration wizard doesn't launch Check plugin installation and file permissions

Troubleshooting

Shift selection doesn't work

Solution: Configure your terminal to pass Shift key sequences. See Terminal Setup.

Verify: Run cat and press Shift+Left. You should see an escape sequence like ^[[1;2D.

Clipboard operations don't work

Solution: Install the required clipboard tool:

  • Wayland: wl-clipboard
  • X11: xclip

Verify: Run wl-copy <<< "test" or xclip -i <<< "test" to check if the tool works.

Mouse replacement not working

Solution:

  1. Check if mouse replacement is enabled: edit-select config → View Configuration
  2. Ensure your terminal supports mouse selection (most do)
  3. Try selecting text with your mouse, then typing—it should replace the selection

If Backspace (or Delete) does not remove a mouse-selected region, this is often due to platform limitations with PRIMARY selection (or lack thereof on macOS). Try one of the following:

  • Disable Mouse Replacement: edit-select config → Option 2, or set EDIT_SELECT_MOUSE_REPLACEMENT=disabled in your config file.
  • Use Shift + Arrow keys for selection, which the plugin fully supports.

Ctrl+C doesn't copy

Solution: Configure your terminal to remap Ctrl+C. See Kitty or VS Code Terminal sections.

Alternative: Use Ctrl+Shift+C for copying, or configure a custom keybinding with edit-select config, or use the 'Without Terminal Remapping' method if your terminal doesn't support key remapping.

Configuration wizard doesn't launch

Symptoms: Running edit-select config shows "file not found" error

Solution:

  1. Check the plugin was installed correctly
  2. Verify edit-select-wizard.zsh exists in the plugin directory
  3. Ensure the file has read permissions:
    chmod +r ~/.oh-my-zsh/custom/plugins/zsh-edit-select/edit-select-wizard.zsh
  4. Try sourcing your .zshrc again: source ~/.zshrc
  5. Fully close and reopen your terminal

License

This project is licensed under the MIT License.


Acknowledgments

Began as a fork (Michael-Matta1/zsh-shift-select) of jirutka/zsh-shift-select to add the ability to copy selected text, because the jirutka/zsh-shift-select plugin only supported deleting selected text and did not offer copying by default.

This feature was frequently requested by the community, as shown in issue #8 and issue #10.

Since then, the project has evolved with its own new features, enhancements, bug fixes, design improvements, and a fully changed codebase, and it now provides a full editor-like experience.


References

About

Editor-style selection and editing for Zsh: Shift/Shift+Ctrl selection, mouse-integration, type-to-replace, and clipboard-aware copy/cut/paste/replace behavior.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages