> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/wezterm/wezterm/llms.txt
> Use this file to discover all available pages before exploring further.

# Copy and Paste Key Actions

> Key assignments for clipboard operations and text selection in WezTerm

## Overview

WezTerm provides comprehensive clipboard operations through key assignments, supporting both system clipboard and primary selection (on X11 and Wayland systems). You can copy and paste text, select text with the mouse or keyboard, and integrate with the system clipboard.

## Copying to Clipboard

### CopyTo

Copy the current selection to a clipboard destination:

```lua theme={null}
local wezterm = require 'wezterm'
local act = wezterm.action
local config = {}

config.keys = {
  {
    key = 'C',
    mods = 'CTRL|SHIFT',
    action = act.CopyTo 'Clipboard',
  },
  {
    key = 'C',
    mods = 'CTRL',
    action = act.CopyTo 'ClipboardAndPrimarySelection',
  },
}

return config
```

<ParamField path="destination" type="ClipboardCopyDestination" required>
  Where to copy the selection:

  * `'Clipboard'` - Copy to the system clipboard
  * `'PrimarySelection'` - Copy to the primary selection buffer (X11/Wayland)
  * `'ClipboardAndPrimarySelection'` - Copy to both locations
</ParamField>

<Note>
  `PrimarySelection` is supported on X11 and Wayland systems that support primary-selection-unstable-v1 protocol
</Note>

### Copy (Deprecated Alias)

For backwards compatibility, `Copy` is an alias for `CopyTo 'ClipboardAndPrimarySelection'`:

```lua theme={null}
config.keys = {
  { key = 'C', mods = 'CTRL|SHIFT', action = act.Copy },
}
```

### CopyTextTo

Copy specific text to the clipboard without requiring a selection:

```lua theme={null}
config.keys = {
  {
    key = 'E',
    mods = 'CTRL|SHIFT',
    action = act.CopyTextTo {
      text = 'echo "Hello, World!"',
      destination = 'Clipboard',
    },
  },
}
```

<ParamField path="text" type="string" required>
  The text to copy to the clipboard
</ParamField>

<ParamField path="destination" type="ClipboardCopyDestination" required>
  Where to copy the text
</ParamField>

## Pasting from Clipboard

### PasteFrom

Paste text from a clipboard source:

```lua theme={null}
config.keys = {
  {
    key = 'V',
    mods = 'CTRL|SHIFT',
    action = act.PasteFrom 'Clipboard',
  },
  {
    key = 'V',
    mods = 'CTRL',
    action = act.PasteFrom 'PrimarySelection',
  },
}
```

<ParamField path="source" type="ClipboardPasteSource" required>
  Where to paste from:

  * `'Clipboard'` - Paste from the system clipboard
  * `'PrimarySelection'` - Paste from the primary selection buffer
</ParamField>

### Paste (Deprecated Alias)

For backwards compatibility, `Paste` is an alias for `PasteFrom 'Clipboard'`:

```lua theme={null}
config.keys = {
  { key = 'V', mods = 'CTRL|SHIFT', action = act.Paste },
}
```

### PastePrimarySelection (Deprecated Alias)

Alias for `PasteFrom 'PrimarySelection'`:

```lua theme={null}
config.keys = {
  { key = 'Insert', mods = 'SHIFT', action = act.PastePrimarySelection },
}
```

## Text Selection

### SelectTextAtMouseCursor

Start a text selection at the mouse cursor position:

```lua theme={null}
config.mouse_bindings = {
  {
    event = { Up = { streak = 1, button = 'Left' } },
    mods = 'NONE',
    action = act.SelectTextAtMouseCursor 'Cell',
  },
  {
    event = { Up = { streak = 2, button = 'Left' } },
    mods = 'NONE',
    action = act.SelectTextAtMouseCursor 'Word',
  },
  {
    event = { Up = { streak = 3, button = 'Left' } },
    mods = 'NONE',
    action = act.SelectTextAtMouseCursor 'Line',
  },
}
```

<ParamField path="mode" type="SelectionMode" required>
  Selection granularity:

  * `'Cell'` - Select individual characters
  * `'Word'` - Select whole words
  * `'Line'` - Select entire lines
  * `'SemanticZone'` - Select semantic zones (e.g., URLs, file paths)
  * `'Block'` - Rectangular block selection
</ParamField>

### ExtendSelectionToMouseCursor

Extend the current selection to the mouse cursor:

```lua theme={null}
config.mouse_bindings = {
  {
    event = { Down = { streak = 1, button = 'Left' } },
    mods = 'SHIFT',
    action = act.ExtendSelectionToMouseCursor 'Cell',
  },
}
```

<ParamField path="mode" type="SelectionMode" required>
  Selection mode to use when extending
</ParamField>

### ClearSelection

Clear the current text selection:

```lua theme={null}
config.keys = {
  {
    key = 'Escape',
    mods = 'NONE',
    action = act.ClearSelection,
  },
}
```

### CompleteSelection

Complete the selection and copy it to the clipboard:

```lua theme={null}
config.mouse_bindings = {
  {
    event = { Up = { streak = 1, button = 'Left' } },
    mods = 'NONE',
    action = act.CompleteSelection 'ClipboardAndPrimarySelection',
  },
}
```

<ParamField path="destination" type="ClipboardCopyDestination" required>
  Where to copy the completed selection
</ParamField>

### CompleteSelectionOrOpenLinkAtMouseCursor

Complete the selection or open a URL if hovering over one:

```lua theme={null}
config.mouse_bindings = {
  {
    event = { Up = { streak = 1, button = 'Left' } },
    mods = 'NONE',
    action = act.CompleteSelectionOrOpenLinkAtMouseCursor 'ClipboardAndPrimarySelection',
  },
}
```

<ParamField path="destination" type="ClipboardCopyDestination" required>
  Where to copy the selection if not opening a link
</ParamField>

## Copy Mode

### ActivateCopyMode

Enter copy mode for keyboard-driven text selection:

```lua theme={null}
config.keys = {
  {
    key = '[',
    mods = 'CTRL|SHIFT',
    action = act.ActivateCopyMode,
  },
}
```

Copy mode allows you to navigate and select text using keyboard shortcuts, similar to vim's visual mode.

<Tip>
  In copy mode, use:

  * Arrow keys or `h`/`j`/`k`/`l` to move cursor
  * `v` to start selection
  * `y` to copy selection
  * `Escape` or `q` to exit
</Tip>

## Quick Select

### QuickSelect

Activate quick select mode to select and copy patterns:

```lua theme={null}
config.keys = {
  {
    key = 'Space',
    mods = 'CTRL|SHIFT',
    action = act.QuickSelect,
  },
}
```

Quick select highlights patterns (URLs, file paths, hashes) and allows you to select them with keyboard shortcuts.

### QuickSelectArgs

Customize quick select behavior:

```lua theme={null}
config.keys = {
  {
    key = 'Space',
    mods = 'CTRL|SHIFT',
    action = act.QuickSelectArgs {
      patterns = {
        'https?://\\S+',
        '\\w+@\\w+\\.\\w+',
      },
      alphabet = 'asdfghjkl;',
      action = wezterm.action_callback(function(window, pane)
        local url = window:get_selection_text_for_pane(pane)
        wezterm.open_with(url)
      end),
    },
  },
}
```

<ParamField path="patterns" type="string[]">
  Regular expressions to match. Defaults to `quick_select_patterns` config
</ParamField>

<ParamField path="alphabet" type="string">
  Characters to use for labels. Defaults to `quick_select_alphabet` config
</ParamField>

<ParamField path="action" type="KeyAssignment">
  Action to perform when a match is selected. Defaults to copying to clipboard
</ParamField>

<ParamField path="label" type="string">
  Label to show in place of "copy" when custom action is set
</ParamField>

<ParamField path="scope_lines" type="integer">
  Number of lines before and after viewport to search
</ParamField>

## Complete Example

<CodeGroup>
  ```lua Basic Copy/Paste theme={null}
  local wezterm = require 'wezterm'
  local act = wezterm.action
  local config = {}

  config.keys = {
    -- Copy to clipboard
    { key = 'C', mods = 'CTRL|SHIFT', action = act.CopyTo 'Clipboard' },
    
    -- Paste from clipboard
    { key = 'V', mods = 'CTRL|SHIFT', action = act.PasteFrom 'Clipboard' },
    
    -- Clear selection
    { key = 'Escape', mods = 'NONE', action = act.ClearSelection },
    
    -- Copy mode
    { key = '[', mods = 'CTRL|SHIFT', action = act.ActivateCopyMode },
    
    -- Quick select
    { key = 'Space', mods = 'CTRL|SHIFT', action = act.QuickSelect },
  }

  return config
  ```

  ```lua X11/Wayland Primary Selection theme={null}
  local wezterm = require 'wezterm'
  local act = wezterm.action
  local config = {}

  config.keys = {
    -- Copy to both clipboard and primary selection
    {
      key = 'C',
      mods = 'CTRL|SHIFT',
      action = act.CopyTo 'ClipboardAndPrimarySelection',
    },
    
    -- Paste from clipboard
    { key = 'V', mods = 'CTRL|SHIFT', action = act.PasteFrom 'Clipboard' },
    
    -- Paste from primary selection (middle-click behavior)
    { key = 'Insert', mods = 'SHIFT', action = act.PasteFrom 'PrimarySelection' },
  }

  config.mouse_bindings = {
    -- Middle-click paste from primary selection
    {
      event = { Up = { streak = 1, button = 'Middle' } },
      mods = 'NONE',
      action = act.PasteFrom 'PrimarySelection',
    },
  }

  return config
  ```

  ```lua Advanced Quick Select theme={null}
  local wezterm = require 'wezterm'
  local act = wezterm.action
  local config = {}

  config.keys = {
    -- Quick select URLs and email addresses
    {
      key = 'u',
      mods = 'CTRL|SHIFT',
      action = act.QuickSelectArgs {
        patterns = {
          'https?://[^\\s]+',
          '[\\w._%+-]+@[\\w.-]+\\.[\\w]{2,}',
        },
        label = 'open url',
        action = wezterm.action_callback(function(window, pane)
          local url = window:get_selection_text_for_pane(pane)
          wezterm.log_info('Opening: ' .. url)
          wezterm.open_with(url)
        end),
      },
    },
    
    -- Quick select file paths
    {
      key = 'f',
      mods = 'CTRL|SHIFT',
      action = act.QuickSelectArgs {
        patterns = {
          '(?:/[^/\\s]+)+/?',
          '\\w+\\.\\w+',
        },
        alphabet = 'asdfghjkl',
        label = 'copy path',
      },
    },
    
    -- Quick select git hashes
    {
      key = 'h',
      mods = 'CTRL|SHIFT',
      action = act.QuickSelectArgs {
        patterns = { '[a-f0-9]{7,40}' },
        label = 'copy hash',
      },
    },
  }

  return config
  ```

  ```lua Mouse Selection Bindings theme={null}
  local wezterm = require 'wezterm'
  local act = wezterm.action
  local config = {}

  config.mouse_bindings = {
    -- Single click: position cursor
    {
      event = { Down = { streak = 1, button = 'Left' } },
      mods = 'NONE',
      action = act.SelectTextAtMouseCursor 'Cell',
    },
    
    -- Double click: select word
    {
      event = { Up = { streak = 2, button = 'Left' } },
      mods = 'NONE',
      action = act.SelectTextAtMouseCursor 'Word',
    },
    
    -- Triple click: select line
    {
      event = { Up = { streak = 3, button = 'Left' } },
      mods = 'NONE',
      action = act.SelectTextAtMouseCursor 'Line',
    },
    
    -- Shift+click: extend selection
    {
      event = { Down = { streak = 1, button = 'Left' } },
      mods = 'SHIFT',
      action = act.ExtendSelectionToMouseCursor 'Cell',
    },
    
    -- Release: complete selection and copy
    {
      event = { Up = { streak = 1, button = 'Left' } },
      mods = 'NONE',
      action = act.CompleteSelection 'ClipboardAndPrimarySelection',
    },
    
    -- Middle-click: paste
    {
      event = { Up = { streak = 1, button = 'Middle' } },
      mods = 'NONE',
      action = act.PasteFrom 'PrimarySelection',
    },
  }

  return config
  ```
</CodeGroup>

## Related Actions

* [Search Actions](/lua/keyassignment/search) - Find and copy text from scrollback
* [Scrolling Actions](/lua/keyassignment/scrolling) - Navigate through output before copying
