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

# Selection

> Visual mode, multi-selection, and cross-directory selection in Yazi

Yazi provides multiple ways to select files for batch operations.

## Quick Selection

### Toggle Individual Files

```bash theme={null}
<Space>  # Toggle selection on current file and move to next
```

This is the fastest way to select multiple files:

* Moves cursor down automatically after toggling
* Works in normal mode
* Can be pressed multiple times rapidly

## Visual Mode

Yazi implements Vim-style visual selection with two modes:

### Select Mode

```bash theme={null}
v  # Enter visual mode (select mode)
```

In select mode:

* Move the cursor with `j`/`k` to expand selection
* Selected files are added to the selection set
* Use any navigation command to select ranges

<Steps>
  <Step title="Enter select mode">
    Press `v` on the starting file
  </Step>

  <Step title="Expand selection">
    Use `j`/`k` or other navigation keys to select more files
  </Step>

  <Step title="Exit visual mode">
    Press `<Esc>` to exit and keep the selection
  </Step>
</Steps>

### Unset Mode

```bash theme={null}
V  # Enter visual mode (unset mode)
```

Unset mode works inversely:

* Files in the range are deselected
* Useful for removing files from an existing selection

**Example workflow:**

```bash theme={null}
# Select all files
<C-a>

# Enter unset mode to deselect a range
V
5j  # Deselect 5 files
<Esc>
```

## Select All Operations

### Bulk Selection Commands

| Key     | Command                 | Description                           |
| ------- | ----------------------- | ------------------------------------- |
| `<C-a>` | `toggle_all --state=on` | Select all files in current directory |
| `<C-r>` | `toggle_all`            | Invert selection (toggle all)         |

<Tabs>
  <Tab title="Select All">
    ```bash theme={null}
    <C-a>  # Select all files
    ```

    Selects every file in the current directory. Useful for:

    * Batch operations on entire directories
    * Starting point for unset mode to exclude specific files
  </Tab>

  <Tab title="Invert Selection">
    ```bash theme={null}
    <C-r>  # Invert selection
    ```

    Toggles the selection state of all files:

    * Selected → Unselected
    * Unselected → Selected

    Useful when you want to select everything except a few files.
  </Tab>
</Tabs>

## Visual Mode Details

### How Visual Mode Works

Yazi's visual mode is implemented in `/home/daytona/workspace/source/yazi-core/src/tab/mode.rs:7`:

* **Select mode**: `Mode::Select(start, indices)` - Adds files to selection
* **Unset mode**: `Mode::Unset(start, indices)` - Removes files from selection
* **Normal mode**: `Mode::Normal` - Standard navigation

### Exiting Visual Mode

```bash theme={null}
<Esc>  # Exit visual mode and keep selection
<C-[>  # Alternative: Exit visual mode
```

The selection persists after exiting visual mode, allowing you to:

* Navigate to other directories
* Perform operations on the selected files
* Add more files to the selection later

## Cross-Directory Selection

One of Yazi's powerful features is the ability to select files across multiple directories:

<Steps>
  <Step title="Select files in first directory">
    ```bash theme={null}
    <Space>  # Toggle selection on files
    ```
  </Step>

  <Step title="Navigate to another directory">
    ```bash theme={null}
    l  # Enter subdirectory
    # or
    cd /another/path
    ```
  </Step>

  <Step title="Select more files">
    ```bash theme={null}
    <Space>  # Add more files to selection
    ```
  </Step>

  <Step title="Perform operation">
    ```bash theme={null}
    y  # Yank all selected files
    p  # Paste in destination
    ```
  </Step>
</Steps>

<Note>
  Selected files remain in the selection set even when you navigate away from their directory. This enables complex multi-directory operations.
</Note>

## Selection Indicators

### Visual Feedback

Yazi provides clear visual indicators for selection state:

| State       | Indicator        | Description                  |
| ----------- | ---------------- | ---------------------------- |
| Selected    | Highlighted      | File is in the selection set |
| Visual mode | Different color  | Visual mode is active        |
| Cursor      | Bright highlight | Current cursor position      |

## Practical Examples

### Example 1: Select Specific File Types

```bash theme={null}
# Select all .txt files
f        # Start filter
*.txt    # Filter pattern
<C-a>    # Select all filtered results
<Esc>    # Clear filter (selection persists)
```

### Example 2: Select All Except Few Files

```bash theme={null}
<C-a>    # Select all files
V        # Enter unset mode
3j       # Deselect first 3 files
<Esc>    # Exit visual mode
```

### Example 3: Multi-Directory Batch Move

```bash theme={null}
# In /source/dir1
<Space>  # Select file1
<Space>  # Select file2

# Navigate to another directory
gh       # Go home
l        # Enter another directory
<Space>  # Select file3

# Now move all selected files
x        # Cut all selected files
cd /destination
p        # Paste all files from both directories
```

## Clearing Selection

```bash theme={null}
<Esc>  # Clear selection (when not in visual mode)
```

<Warning>
  The escape key has multiple functions depending on context:

  * In visual mode: Exit visual mode (keep selection)
  * In normal mode: Clear all selections
  * During search: Cancel search
</Warning>

## Working with Selected Files

Once files are selected, you can perform any file operation:

* **Yank/Cut**: `y` or `x`
* **Delete**: `d` or `D`
* **Open**: `o` or `O`
* **Shell command**: `;` or `:`

All operations apply to the entire selection set, regardless of which directory the files are in.
