PhpStorm 2017.3 Help

Cutting, Copying and Pasting

On this page:

Basics

PhpStorm provides a number of handy Clipboard operations. You can copy, cut, and paste selected text, a path to a file, or a reference to a symbol or a line of code.

Because PhpStorm uses the system Clipboard, you can copy and paste between applications. So doing, when pasting Clipboard entries, PhpStorm removes any formatting from the text and any special symbols from the String values.

The Paste command smartly understands what is being inserted. If you paste a reference to a symbol, it is analyzed for possible imports, references, etc. So doing, PhpStorm provides the necessary brackets and places the caret at the appropriate insertion point. The Paste Simple command helps paste any Clipboard entry as a plain text, without any analysis.

PhpStorm enables Clipboard stacking, which means that you can store multiple Clipboard entries and access them with a single shortcut. The number of entries that can be kept in the Clipboard stack is customizable on the Editor page of the Settings/Preferences dialog.

Copying a selected fragment of text

Do one of the following:

  • On the main menu, choose Edit | Copy.
  • Press Ctrl+C.
  • Click the Copy button copy on the toolbar.
Note that the Ctrl+D keyboard shortcut clones a line at the caret or a selected arbitrary fragment of text.

In the PHP context, you can select and copy variable names both with and without a $ sign. This behavior is configured through the Select variable name without $ sign on double click checkbox on the Smart Keys page of the Settings dialog (File | Settings | Editor | General | Smart Keys for Windows and Linux or PhpStorm | Preferences | Editor | General | Smart Keys for macOS).
When this check box is selected, only the variable name that follows the $ sign is selected on double click or pressing Ctrl+W. This is helpful if you often need to copy variable names without $: just double-click and copy the selection.
If you still need a variable name with $ selected, place the cursor before the $ sign and double click it or press Ctrl+W.

Copying the path to a file

When you copy the path to a file, the absolute path to a file is copied to the clipboard.

To copy the path to a file, do one of the following:

  • Open the desired file in the editor, then choose Edit | Copy Path on the main menu or press Ctrl+Shift+C.
  • Select the desired file in the Project tool window and choose Copy Path on the context menu of the selection.

Copying the relative path to a file

When you copy the relative path to a file, the partial path to the file is copied to the clipboard. By default, this path is relative to the project's content root folder. If a folder below the content root is marked as Source or Test Source, the path is relative to this source folder instead.

To copy the relative path to a file, do the following:

  • Select the desired file in the Project tool window and choose Copy Relative Path on the context menu of the selection.

Copying the reference to a line or a symbol

  1. Open the desired file in the editor.
  2. Place the caret at a certain line of code.
  3. Do one of the following:
    • On the main menu, choose Edit | Copy Reference.
    • On the context menu of the line at caret, choose Copy Reference.
    • Press Ctrl+Shift+Alt+C.

    PhpStorm creates a string in the format that depends on a symbol at caret. For example:

    \MyNamespace\Catcher for a PHP class

    \MyNamespace\Catcher::$name for a PHP variable

    \MyNamespace\Catcher::set_experience for a PHP method

Cutting a selected fragment of text

  1. Select the desired fragment in the editor.
  2. Do one of the following:
    • On the main menu, choose Edit | Cut.
    • Press Ctrl+X.
    • Click the Cut button cut on the toolbar.

Paste modes

In the PHP context, you can paste fragments of code in two modes:

  • In the Paste Simple mode, the fragment is inserted without escaping single quotes ('), double quotes ("), backslashes (\), and <a href></a>.
  • In the Paste mode, PhpStorm escapes single quotes ('), double quotes ("), backslashes (\), and <a href></a> in the inserted fragment.

For example, if you insert <a href="http://www.google.com/">go google</a> into <?php public $a = "|"; ?>, where | indicates the cursor position, the result differs depending on the paste mode.

Paste Simple modePaste mode
<?php public $a = "<a href="http://www.google.com/">go google</a>"; ?>
<?php public $a = "<a href=\"http://www.google.com/\">go google</a>"; ?>

Pasting the last entry from the clipboard

Depending on the chosen paste mode, do one of the following:

  • To apply the Paste Simple mode, place the caret in the location where you want to paste the content and choose Edit | Paste Simple on the main menu or press Ctrl+Shift+Alt+V.
  • To apply the Paste mode, place the caret in the location where you want to paste the content and choose Edit | Paste on the main menu, or press Ctrl+V, or click the Paste button paste on the toolbar.

Pasting a specific entry from the clipboard

  1. On the main menu, choose Edit | Paste from History or press Ctrl+Shift+V.
  2. In the Choose Content to Paste dialog box select the desired entry from the list of recent Clipboard entries.
  3. Click Paste to paste the content using the Paste mode or hover your mouse over this button to display the available paste mode options. Depending on the chosen paste mode, do one of the following:
    • Paste: select this option to apply the Paste mode.
    • Paste Simple: select this option to apply the Paste Simple mode.

The depth of the Clipboard stack is configured in the Limits section on the Editor page of the Settings/Preferences dialog box. When the specified number is exceeded, the oldest entry is removed from the list.

Last modified: 3 November 2017

See Also