Edit

Share via


Selecting text in Windows Terminal

Selecting text is straightforward in Windows Terminal, but the terminal offers many additional features that make text selection even better.

Mouse support

Left-click and drag your mouse to create a selection. Double-click expands the selection by word, whereas triple-click expands by line.

If you hold the Alt key, you create a block selection (as opposed to a line selection). Block selections create a rectangular region that doesn't wrap to the end of the line.

If you hold the Shift key, you can explicitly expand the selection to a specific point on the terminal without the need to click and drag.

Once you have a selection, you have a few options. A single left-click clears your selection. If you want to use the selection, you can right-click to copy the selected text to your clipboard and clear the selection. If you right-click again, the contents of your clipboard are pasted into the terminal.

Note

Windows Terminal supports mouse input in Windows Subsystem for Linux (WSL) applications as well as Windows applications that use virtual terminal (VT) input. This support means applications such as tmux and Midnight Commander recognize when you select items in the terminal window. If an application is in mouse mode, you can hold down Shift to make a selection instead of sending VT input.

Keyboard support

You can create a selection by using the selectAll or markMode actions. The selectAll action selects all the text in the buffer. The markMode action toggles a special mode where a selection is created at the cursor's position in the terminal. When in mark mode, you can use the following non-configurable key bindings to move the cursor around:

Key binding Result
Arrow keys Move by character in the specified direction
Ctrl+Left Move to the beginning of the previous or existing word
Ctrl+Right Move to the end of the next or existing word
Home Move to the beginning of the line
End Move to the end of the line
Pgup Move up by a page (viewport)
Pgdn Move down by a page (viewport)
Ctrl+Home Move to the beginning of the buffer
Ctrl+End Move to the end of the buffer
Enter Copy the active selection

When in mark mode, you can use Tab or Shift+Tab to navigate to the next or previous hyperlink in the buffer. Windows Terminal can automatically detect hyperlinks if experimental.detectUrls is enabled.

Regardless of being in mark mode, you can expand an existing selection using the following non-configurable key bindings:

Key binding Result
Shift + Arrow keys Expand by character in the specified direction
Ctrl+Shift+Left Expand to the beginning of the previous or existing word
Ctrl+Shift+Right Expand to the end of the next or existing word
Shift+Home Expand to the beginning of the line
Shift+End Expand to the end of the line
Shift+Pgup Expand up by a page (viewport)
Shift+Pgdn Expand down by a page (viewport)
Ctrl+Shift+Home Expand to the beginning of the buffer
Ctrl+Shift+End Expand to the end of the buffer

Use the toggleBlockSelection action to transform the existing selection into a block selection.

Any selection you create or modify by using the keyboard also displays selection markers to indicate which end of the selection is actively being moved. You can use the switchSelectionEndpoint action to begin moving the other end of the selection.

Once you have a selection, you have a few options. You can use the ESC key to clear the selection. Alternatively, most key input clears the selection and passes the key event directly to the underlying shell. If you want to use the selected text, you can use the copy action to copy it to your clipboard.

Copying selected text

As mentioned earlier, you can copy selected text with a right-click or the copy action. However, you can customize several settings for copying text:

  • Copying formatted text
    • Use the copyFormatting global setting to also copy the formatting of the selected text itself to the clipboard. This setting lets you copy the terminal's font information, such as foreground color, background color, and font.
    • If you want to limit copying the formatting to certain key bindings or commands, modify the copyFormatting parameter on a copy action.
  • Copying without dismissing text selection
    • Set the dismissSelection parameter in the copy action to false to copy text without dismissing the text selection.
  • Copying as a single line
    • Use the singleLine parameter in the copy action to copy text as a single line.
  • Copying with control sequences
    • Use the withControlSequences parameter in the copy action to include ANSI escape code control sequences in the copied text.
  • Removing trailing whitespace from block selections
    • Use the trimBlockSelection global setting to remove the trailing whitespace from a block selection.

Use the copyOnSelect global setting to automatically copy newly selected text to your clipboard. With this setting enabled, if a selection is present, right-clicking the terminal copies and pastes the selected text to your terminal.

Note

If you enable copyOnSelect, modifying the selection by using the keyboard doesn't automatically copy the newly selected text. You need to manually copy the text by using the copy action or by right-clicking the terminal.

Customizing the appearance of selections

Color schemes let you customize the selection color by using the selectionBackground property in a color scheme. Alternatively, you can override the selection color for a specific profile by using the selectionBackground profile setting.

Customizing word delimiters

As mentioned earlier, double-clicking and using Ctrl+Shift + Arrow keys (or Ctrl + Arrow keys when in mark mode) allow you to navigate by word. However, words can be separated by more than just whitespace. You can customize these word boundaries by using the wordDelimiters global setting.