> ## 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.

# Search Key Actions

> Key assignments for searching terminal content and navigating search results in WezTerm

## Overview

WezTerm provides powerful search capabilities for finding text in your terminal output and scrollback history. You can search using plain text, case-sensitive matching, or regular expressions.

## Basic Search

### Search

Open the search overlay with an optional pre-filled pattern:

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

config.keys = {
  -- Open empty search
  {
    key = 'F',
    mods = 'CTRL|SHIFT',
    action = act.Search 'CurrentSelectionOrEmptyString',
  },
  -- Search for git hashes
  {
    key = 'H',
    mods = 'CTRL|SHIFT',
    action = act.Search { Regex = '[a-f0-9]{6,}' },
  },
}

return config
```

<ParamField path="pattern" type="Pattern" required>
  The search pattern to use. Can be one of:

  * `'CurrentSelectionOrEmptyString'` - Use selected text or empty (default)
  * `{ CaseSensitiveString = 'text' }` - Exact case-sensitive match
  * `{ CaseInSensitiveString = 'text' }` - Case-insensitive match
  * `{ Regex = 'pattern' }` - Regular expression pattern
</ParamField>

## Search Pattern Types

### CurrentSelectionOrEmptyString

Use the currently selected text as the search term:

```lua theme={null}
config.keys = {
  {
    key = 'f',
    mods = 'CTRL|SHIFT',
    action = act.Search 'CurrentSelectionOrEmptyString',
  },
}
```

If there's no selection, the search overlay opens empty, ready for input.

### CaseSensitiveString

Search for an exact string match:

```lua theme={null}
config.keys = {
  {
    key = 'e',
    mods = 'CTRL|SHIFT',
    action = act.Search { CaseSensitiveString = 'ERROR' },
  },
}
```

This will only match "ERROR" exactly, not "error" or "Error".

### CaseInSensitiveString

Search for a string ignoring case:

```lua theme={null}
config.keys = {
  {
    key = 'w',
    mods = 'CTRL|SHIFT',
    action = act.Search { CaseInSensitiveString = 'warning' },
  },
}
```

This will match "warning", "WARNING", "Warning", etc.

### Regex

Search using regular expressions:

```lua theme={null}
config.keys = {
  -- Find git hashes
  {
    key = 'h',
    mods = 'CTRL|SHIFT',
    action = act.Search { Regex = '[a-f0-9]{7,40}' },
  },
  -- Find URLs
  {
    key = 'u',
    mods = 'CTRL|SHIFT',
    action = act.Search { Regex = 'https?://\\S+' },
  },
  -- Find email addresses
  {
    key = 'm',
    mods = 'CTRL|SHIFT',
    action = act.Search { Regex = '[\\w._%+-]+@[\\w.-]+\\.[\\w]{2,}' },
  },
  -- Find IP addresses
  {
    key = 'i',
    mods = 'CTRL|SHIFT',
    action = act.Search { Regex = '\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b' },
  },
}
```

<Note>
  WezTerm uses Rust's regex syntax. [View the full syntax documentation](https://docs.rs/regex/latest/regex/#syntax)
</Note>

## Copy Mode Search

When in copy mode, you can use search-specific navigation actions:

### Copy Mode Search Actions

```lua theme={null}
config.key_tables = {
  copy_mode = {
    -- Open search
    { key = '/', action = act.CopyMode 'EditPattern' },
    
    -- Navigate search results
    { key = 'n', action = act.CopyMode 'NextMatch' },
    { key = 'N', mods = 'SHIFT', action = act.CopyMode 'PriorMatch' },
    
    -- Navigate by pages of matches
    { key = 'PageUp', action = act.CopyMode 'PriorMatchPage' },
    { key = 'PageDown', action = act.CopyMode 'NextMatchPage' },
    
    -- Cycle match type (case sensitive, case insensitive, regex)
    { key = 'r', mods = 'CTRL', action = act.CopyMode 'CycleMatchType' },
    
    -- Clear search pattern
    { key = 'Escape', action = act.CopyMode 'ClearPattern' },
    
    -- Accept and close search
    { key = 'Enter', action = act.CopyMode 'AcceptPattern' },
  },
}
```

<ParamField path="EditPattern" type="CopyModeAssignment">
  Open or edit the search pattern
</ParamField>

<ParamField path="NextMatch" type="CopyModeAssignment">
  Jump to the next match
</ParamField>

<ParamField path="PriorMatch" type="CopyModeAssignment">
  Jump to the previous match
</ParamField>

<ParamField path="NextMatchPage" type="CopyModeAssignment">
  Jump forward by a page of matches
</ParamField>

<ParamField path="PriorMatchPage" type="CopyModeAssignment">
  Jump backward by a page of matches
</ParamField>

<ParamField path="CycleMatchType" type="CopyModeAssignment">
  Toggle between case-sensitive, case-insensitive, and regex matching
</ParamField>

<ParamField path="ClearPattern" type="CopyModeAssignment">
  Clear the current search pattern
</ParamField>

<ParamField path="AcceptPattern" type="CopyModeAssignment">
  Accept the current pattern and close the search input
</ParamField>

## ActivateCopyMode

Enter copy mode, which provides keyboard-driven navigation and search:

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

Copy mode allows you to:

* Navigate with keyboard (vim-style bindings)
* Search and navigate results
* Select and copy text without using the mouse

## Complete Example

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

  config.keys = {
    -- Open search with current selection or empty
    {
      key = 'f',
      mods = 'CTRL|SHIFT',
      action = act.Search 'CurrentSelectionOrEmptyString',
    },
    
    -- Enter copy mode for keyboard navigation
    {
      key = '[',
      mods = 'CTRL|SHIFT',
      action = act.ActivateCopyMode,
    },
  }

  return config
  ```

  ```lua Pattern-Based Search theme={null}
  local wezterm = require 'wezterm'
  local act = wezterm.action
  local config = {}

  config.keys = {
    -- Search for common patterns
    {
      key = 'e',
      mods = 'CTRL|SHIFT',
      action = act.Search { CaseInSensitiveString = 'error' },
    },
    {
      key = 'w',
      mods = 'CTRL|SHIFT',
      action = act.Search { CaseInSensitiveString = 'warning' },
    },
    
    -- Regex searches
    {
      key = 'h',
      mods = 'CTRL|SHIFT',
      action = act.Search { Regex = '[a-f0-9]{7,40}' },
    },
    {
      key = 'u',
      mods = 'CTRL|SHIFT',
      action = act.Search { Regex = 'https?://\\S+' },
    },
  }

  return config
  ```

  ```lua Copy Mode with Search theme={null}
  local wezterm = require 'wezterm'
  local act = wezterm.action
  local config = {}

  config.keys = {
    -- Enter copy mode
    { key = '[', mods = 'CTRL|SHIFT', action = act.ActivateCopyMode },
  }

  -- Copy mode key bindings
  config.key_tables = {
    copy_mode = {
      -- Movement
      { key = 'h', action = act.CopyMode 'MoveLeft' },
      { key = 'j', action = act.CopyMode 'MoveDown' },
      { key = 'k', action = act.CopyMode 'MoveUp' },
      { key = 'l', action = act.CopyMode 'MoveRight' },
      
      -- Search
      { key = '/', action = act.CopyMode 'EditPattern' },
      { key = 'n', action = act.CopyMode 'NextMatch' },
      { key = 'N', mods = 'SHIFT', action = act.CopyMode 'PriorMatch' },
      
      -- Search navigation
      { key = 'PageDown', action = act.CopyMode 'NextMatchPage' },
      { key = 'PageUp', action = act.CopyMode 'PriorMatchPage' },
      
      -- Match type
      { key = 'r', mods = 'CTRL', action = act.CopyMode 'CycleMatchType' },
      
      -- Selection
      { key = 'v', action = act.CopyMode { SetSelectionMode = 'Cell' } },
      { key = 'V', mods = 'SHIFT', action = act.CopyMode { SetSelectionMode = 'Line' } },
      
      -- Copy and exit
      { key = 'y', action = act.Multiple {
        { CopyTo = 'ClipboardAndPrimarySelection' },
        { CopyMode = 'Close' },
      }},
      
      -- Exit
      { key = 'q', action = act.CopyMode 'Close' },
      { key = 'Escape', action = act.CopyMode 'Close' },
    },
  }

  return config
  ```

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

  config.keys = {
    -- General search
    {
      key = 'f',
      mods = 'CTRL|SHIFT',
      action = act.Search 'CurrentSelectionOrEmptyString',
    },
    
    -- Log level searches
    {
      key = 'E',
      mods = 'CTRL|SHIFT',
      action = act.Search { Regex = '(?i)\\b(error|err|fatal)\\b' },
    },
    {
      key = 'W',
      mods = 'CTRL|SHIFT',
      action = act.Search { Regex = '(?i)\\b(warn|warning)\\b' },
    },
    
    -- Development patterns
    {
      key = 'H',
      mods = 'CTRL|SHIFT',
      action = act.Search { Regex = '\\b[a-f0-9]{7,40}\\b' },  -- Git hashes
    },
    {
      key = 'U',
      mods = 'CTRL|SHIFT',
      action = act.Search { Regex = 'https?://[^\\s]+' },  -- URLs
    },
    {
      key = 'P',
      mods = 'CTRL|SHIFT',
      action = act.Search { Regex = '(?:/[^/\\s]+)+/?' },  -- File paths
    },
    {
      key = 'I',
      mods = 'CTRL|SHIFT',
      action = act.Search { Regex = '\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b' },  -- IP addresses
    },
  }

  return config
  ```
</CodeGroup>

## Search Overlay Controls

When the search overlay is active:

* **Enter** - Navigate to next match
* **Shift+Enter** - Navigate to previous match
* **Ctrl+R** - Cycle match type (case-sensitive → case-insensitive → regex)
* **Ctrl+U** - Clear the search input
* **Escape** - Close search overlay
* **Up/Down arrows** - Navigate match history

## Regular Expression Examples

Common regex patterns for searching:

```lua theme={null}
local common_patterns = {
  -- Git commit hashes (7-40 hex chars)
  git_hash = '[a-f0-9]{7,40}',
  
  -- URLs
  url = 'https?://\\S+',
  
  -- Email addresses
  email = '[\\w._%+-]+@[\\w.-]+\\.[\\w]{2,}',
  
  -- IPv4 addresses
  ipv4 = '\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b',
  
  -- File paths (Unix)
  unix_path = '(?:/[^/\\s]+)+/?',
  
  -- File paths (Windows)
  windows_path = '[A-Za-z]:\\\\[^\\s]+',
  
  -- UUIDs
  uuid = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',
  
  -- Semantic version numbers
  semver = '\\b\\d+\\.\\d+\\.\\d+\\b',
  
  -- Time stamps (HH:MM:SS)
  time = '\\b\\d{2}:\\d{2}:\\d{2}\\b',
}
```

<Tip>
  Use the `CycleMatchType` action (Ctrl+R) in the search overlay to quickly switch between case-sensitive, case-insensitive, and regex matching without retyping your pattern
</Tip>

## Related Actions

* [Copy/Paste Actions](/lua/keyassignment/copy-paste) - Copy search results
* [Scrolling Actions](/lua/keyassignment/scrolling) - Navigate to search matches
* [QuickSelect](/lua/keyassignment/copy-paste#quick-select) - Alternative pattern-based selection
