# How Selection Mode Works for Multi-File Operations in Superfile

> Discover Superfile's selection mode for efficient multi-file operations. Transform your file panel into a checklist for bulk copy, move, delete, and compress actions using single keystrokes.

- Repository: [Yorukot/superfile](https://github.com/yorukot/superfile)
- Tags: how-to-guide
- Published: 2026-07-28

---

**Superfile’s selection mode transforms the file panel into a check-list interface that stores selected paths in a map-backed registry, enabling bulk copy, move, delete, and compress operations with single keystrokes.**

Superfile is a terminal-based file manager that eliminates repetitive strain by letting you queue multiple files for action. The **selection mode multi-file operations** capability is the core mechanism that switches the interface from single-item navigation to a multi-select checklist. According to the `yorukot/superfile` source code, this mode is governed by a state machine that tracks selected paths in an ordered map, which bulk operation handlers consume instead of the single cursor target.

## Entering and Exiting Selection Mode

The transition between normal browsing and multi-select is triggered by the **`v`** key, defined in [`src/internal/ui/helpmenu/data.go`](https://github.com/yorukot/superfile/blob/main/src/internal/ui/helpmenu/data.go) as the binding for “Change between selection mode or normal mode”.

Internally, the panel state is represented by constants declared in [`src/internal/ui/filepanel/consts.go`](https://github.com/yorukot/superfile/blob/main/src/internal/ui/filepanel/consts.go):

```go
const (
    BrowserMode = iota // normal navigation
    SelectMode         // checkbox-style multi-select
)

```

When the user presses `v`, the application toggles between these states. Exiting selection mode—either by pressing `v` again or hitting **`Esc`**—invokes `ClearSelection()`, which empties the registry and returns the panel to `BrowserMode`. The state also resets automatically when the panel loses focus or an operation completes, preventing stale selections from leaking into subsequent commands.

## How Selected Files Are Tracked Internally

Selections are stored in a dedicated map defined in [`src/internal/ui/filepanel/types.go`](https://github.com/yorukot/superfile/blob/main/src/internal/ui/filepanel/types.go). The field `selection map[string]int` uses the absolute file path as the key and an integer as the value to preserve the selection order.

This design allows Superfile to maintain a stable queue of targets without duplicating file handles in memory. The order integer ensures that range selections and “select all” operations respect the visual sequence of the file list.

## Key Bindings for Managing Selections

Once in `SelectMode`, the following inputs modify the `selection` map:

- **Space** – Toggles the item under the cursor. The logic lives in [`src/internal/ui/filepanel/utils.go`](https://github.com/yorukot/superfile/blob/main/src/internal/ui/filepanel/utils.go) inside functions like `SelectItem`, which either inserts the path with `len(p.Selection) + 1` as the order or deletes the existing entry.
- **Shift + Space** – Extends the selection from the last-selected index to the current cursor position, creating a contiguous block.
- **a** – Selects every visible item in the panel by invoking `SelectAll` in [`src/internal/ui/filepanel/update.go`](https://github.com/yorukot/superfile/blob/main/src/internal/ui/filepanel/update.go). This only functions when the panel is already in `SelectMode`.
- **Esc** or **v** – Clears the map and returns to `BrowserMode`.

The UI can optionally render checkboxes next to each entry when the `ShowSelectIcons` boolean (configured in [`src/internal/common/config_type.go`](https://github.com/yorukot/superfile/blob/main/src/internal/common/config_type.go)) is enabled.

## Executing Operations on Selected Files

Bulk actions are handled by the operation layer in [`src/internal/handle_file_operations.go`](https://github.com/yorukot/superfile/blob/main/src/internal/handle_file_operations.go). Before executing a command, the handler checks if the `selection` map is non-empty; if so, it iterates over the map keys rather than acting on the single highlighted item.

Supported operations include:

- **c** – Copy selected files to the opposite panel’s current directory.
- **m** – Move selected files to the opposite panel.
- **d** – Delete all selected entries after confirmation.
- **z** – Compress the selected set into an archive.

Each operation constructs a slice of paths from the map keys, then passes that slice to the relevant filesystem driver. After the operation finishes, Superfile automatically clears the selection to prevent accidental reuse.

## Code Example: Selection Workflow

The following Go snippets illustrate the toggle logic and bulk execution flow found in the source:

```go
// Toggle between BrowserMode and SelectMode
func toggleSelectMode(p *Panel) {
    if p.Mode == BrowserMode {
        p.Mode = SelectMode
    } else {
        p.Mode = BrowserMode
        p.ClearSelection()
    }
}

// Toggle the current item under the cursor (Space key)
func (p *Panel) SelectCurrent() {
    cur := p.Cursor()
    if _, ok := p.Selection[cur.Path]; ok {
        delete(p.Selection, cur.Path) // un-select
    } else {
        p.Selection[cur.Path] = len(p.Selection) + 1 // add with order
    }
}

// Execute a bulk copy using the selection map
func (p *Panel) CopySelected(dst string) error {
    files := make([]string, 0, len(p.Selection))
    for path := range p.Selection {
        files = append(files, path)
    }
    return fileOps.Copy(files, dst)
}

```

## Summary

- Superfile uses a `map[string]int` in [`src/internal/ui/filepanel/types.go`](https://github.com/yorukot/superfile/blob/main/src/internal/ui/filepanel/types.go) to track selected paths and their order.
- Press **`v`** to toggle `SelectMode`; use **`Space`** to toggle individual items and **`a`** to select all.
- Bulk operations (`c`, `m`, `d`, `z`) in [`src/internal/handle_file_operations.go`](https://github.com/yorukot/superfile/blob/main/src/internal/handle_file_operations.go) consume the selection map when it is non-empty.
- The selection auto-clears on panel focus loss or after an operation, ensuring predictable state management.
- Enable `ShowSelectIcons` in the configuration to render checkbox indicators in the UI.

## Frequently Asked Questions

### How do I enter selection mode in Superfile?

Press the **`v`** key. This toggles the file panel from `BrowserMode` to `SelectMode`, enabling checkbox-style multi-select as defined in [`src/internal/ui/filepanel/consts.go`](https://github.com/yorukot/superfile/blob/main/src/internal/ui/filepanel/consts.go).

### Where does Superfile store the list of selected files?

The application stores selections in a map field named `selection` inside the panel struct, declared in [`src/internal/ui/filepanel/types.go`](https://github.com/yorukot/superfile/blob/main/src/internal/ui/filepanel/types.go). The map uses file paths as keys and integers as values to preserve selection order.

### Can I select a range of files without clicking each one individually?

Yes. Hold **`Shift`** and press **`Space`** to extend the selection from the last-selected item to the current cursor position, creating a contiguous block.

### What happens to my selection after I copy or delete the files?

Superfile automatically clears the `selection` map and returns the panel to `BrowserMode` once the operation completes. This behavior prevents stale selections from persisting and accidentally affecting subsequent commands.