Skip to main content

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:
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
destination
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
PrimarySelection is supported on X11 and Wayland systems that support primary-selection-unstable-v1 protocol

Copy (Deprecated Alias)

For backwards compatibility, Copy is an alias for CopyTo 'ClipboardAndPrimarySelection':
config.keys = {
  { key = 'C', mods = 'CTRL|SHIFT', action = act.Copy },
}

CopyTextTo

Copy specific text to the clipboard without requiring a selection:
config.keys = {
  {
    key = 'E',
    mods = 'CTRL|SHIFT',
    action = act.CopyTextTo {
      text = 'echo "Hello, World!"',
      destination = 'Clipboard',
    },
  },
}
text
string
required
The text to copy to the clipboard
destination
ClipboardCopyDestination
required
Where to copy the text

Pasting from Clipboard

PasteFrom

Paste text from a clipboard source:
config.keys = {
  {
    key = 'V',
    mods = 'CTRL|SHIFT',
    action = act.PasteFrom 'Clipboard',
  },
  {
    key = 'V',
    mods = 'CTRL',
    action = act.PasteFrom 'PrimarySelection',
  },
}
source
ClipboardPasteSource
required
Where to paste from:
  • 'Clipboard' - Paste from the system clipboard
  • 'PrimarySelection' - Paste from the primary selection buffer

Paste (Deprecated Alias)

For backwards compatibility, Paste is an alias for PasteFrom 'Clipboard':
config.keys = {
  { key = 'V', mods = 'CTRL|SHIFT', action = act.Paste },
}

PastePrimarySelection (Deprecated Alias)

Alias for PasteFrom 'PrimarySelection':
config.keys = {
  { key = 'Insert', mods = 'SHIFT', action = act.PastePrimarySelection },
}

Text Selection

SelectTextAtMouseCursor

Start a text selection at the mouse cursor position:
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',
  },
}
mode
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

ExtendSelectionToMouseCursor

Extend the current selection to the mouse cursor:
config.mouse_bindings = {
  {
    event = { Down = { streak = 1, button = 'Left' } },
    mods = 'SHIFT',
    action = act.ExtendSelectionToMouseCursor 'Cell',
  },
}
mode
SelectionMode
required
Selection mode to use when extending

ClearSelection

Clear the current text selection:
config.keys = {
  {
    key = 'Escape',
    mods = 'NONE',
    action = act.ClearSelection,
  },
}

CompleteSelection

Complete the selection and copy it to the clipboard:
config.mouse_bindings = {
  {
    event = { Up = { streak = 1, button = 'Left' } },
    mods = 'NONE',
    action = act.CompleteSelection 'ClipboardAndPrimarySelection',
  },
}
destination
ClipboardCopyDestination
required
Where to copy the completed selection

CompleteSelectionOrOpenLinkAtMouseCursor

Complete the selection or open a URL if hovering over one:
config.mouse_bindings = {
  {
    event = { Up = { streak = 1, button = 'Left' } },
    mods = 'NONE',
    action = act.CompleteSelectionOrOpenLinkAtMouseCursor 'ClipboardAndPrimarySelection',
  },
}
destination
ClipboardCopyDestination
required
Where to copy the selection if not opening a link

Copy Mode

ActivateCopyMode

Enter copy mode for keyboard-driven text selection:
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.
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

Quick Select

QuickSelect

Activate quick select mode to select and copy patterns:
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:
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),
    },
  },
}
patterns
string[]
Regular expressions to match. Defaults to quick_select_patterns config
alphabet
string
Characters to use for labels. Defaults to quick_select_alphabet config
action
KeyAssignment
Action to perform when a match is selected. Defaults to copying to clipboard
label
string
Label to show in place of “copy” when custom action is set
scope_lines
integer
Number of lines before and after viewport to search

Complete Example

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