In most other editors, I can select a portion of the text I want to run find and replace on and then hit the ctrl + h combination. A screen pops up asking me what to find and what to replace. How do I do this in PHPStorm?
If you are using the Default keymapping (you can also use the keymaps for Eclipse, Visual Studio, etc) press Ctrl+r to show the Replace Toolbar. If you already have a selection then the option In Selection will already be checked, otherwise you can check it and then do your selection (if you select first and check the option second it will unselect the text after checking the option).
The feature is called Replace in the Keymap configuration if you wish to change the shortcut.
You can also press Shift+F6 to directly rename variables if that's what you want to do.
Highlight the code selection you wish to work on
( you can use alt + arrow up if your looking for a cool way to do that)
Press Ctlr + r on PC or Command + r on a Mac
In the upper options window, insert the values you wish to replace
Select the "in selection" check box
Press Replace/Replace all button
Related
In Sublime, I commonly use my cursor to select multiple lines, then use Command + Shift + L to select each line with multiple cursors.
I'm unable to find any documentation or pre-built option within PHPStorm that can handle this.
Does anyone have a solution? Thanks!.
TLDR: ⌥ + Shift + Drag does what you want. On keymap you can also select the Sublime key binding template for general familiarity.
Overview
A great overview of multiple cursors in Jetbrains products and 4 minutes well spent (some minor variants may be present in the exact bindings, but not hard to work out) is:
https://www.youtube.com/watch?v=JBkGOPR3-nA
Three answers to your question:
1. Out of the box
⌥ + Shift + Drag does what you want.
Also relevant:
Press ⌥ (Option) twice, and then without releasing it, press up or down arrow keys. That will add a caret at the start of each line.
There are many more variations:
https://www.jetbrains.com/help/rider/Multicursor.html
https://blog.jetbrains.com/phpstorm/2014/03/working-with-multiple-selection-in-phpstorm-8-eap/
2. Keymap templates
If you go to preferences -> keymap you will find a dropdown with a list of templates. You can select Sublime Text or Sublime Text (OS). This is not always perfect because other plugins can override the key bindings in sometimes opaque ways, so not every single binding ports; but it should bring you a whole bunch of familiarity.
3. Custom
You can create your own key and mouse bindings for any PHPStorm action by going to preferences -> keymap and right clicking on the action; or searching for an action and then right clicking, etc.
I have this task that I need to complete fast as possible. I have coupon codes (over 1000), I going to create an array out of it. To do that fast as possible I need to be able select multiples lines and edit them at the same time. I am using Atom as my editor choice. I tried to search online for answers but non found.
ST55672
SE82673
SS85074
SD65675
SH75676
to:
"ST55672",
"SE82673",
"SS85074",
"SD65675",
"SH75676",
PS. Im using Mac
1. Atom Commands
Select all text (Cmd+A on Mac, Ctrl+A elsewhere), then use the shortcut to “split the selection into lines” (Cmd+Shift+L on Mac, Ctrl+Shift+L elsewhere). Both commands are also available from the command palette.
PS: like many other keyboard shortcuts, these also work in Sublime Text
2. RegEx Search & Replace
Search for ^(.*)$ and replace with "$1",.
Notice for windows users:
multiline cursor works using these keys in the following order :
CTRL + ALT +
and ↓, or ↑, or a mouse "Click" any where you need
select all lines
Go to selection menu on the top bar (win & Linux)
select split selection into lines
Is there an option highlighting all strings matching the actual selection in PhpStorm (like in SublimeText) ?
You can use Ctrl + Shift + F7 for this in PhpStorm.
This will highlight all usages of selected text.
Using built-in functionality: select text and hit Ctrl + F that will bring "Find in page" functionality: it will highlight all matches of selected text in this document. But it's not always convenient as you have to hit extra keys and have "find in page" bar open...
You can install and use BrowseWordAtCaret plugin that will automatically highlight word under caret in whole document (regardless of it's nature -- variable or just plain text) + you can easily navigate between all matches.
P.S.
You have mentioned that "I'm used to regularly change the name of an object property, an array key or a parameter name at multiple places in same document."
Consider using Refactor | Rename for variables/class members/etc -- it works across multiple files.
I was wondering if there is a shortcut to Paste from the clipboard & at the same time cut the selection to be pasted somewhere else.
Elaborating the Question:
I find myself often swapping values among various sections of code. As a primitive example:
var a = "two";
var b = "one";
To swap them, I would:
cut the value of a
Paste it next to the value of b
cut the original value of b
paste that back as the value of a
I was wondering id there is a shortcut to combine step 2 & 3 of this process.
Sublime Text provides a tool for doing exactly(?) what you wish.
Double click "one" (to select it)
Hold ctrl and double click "two" (both are selected now)
press ctrl + t to swap selections
Otherwise you may wish to register a new key binding for your custom operation. You can do this via Preferences -> Key bindings (User).
Use Permute Selection > Reverse:
highlight two value
hold control
highlight one value
Edit > permute selection > reverse
Not exactly, but something is kinda there to help in such situations. There is a Clipboard History built-in Sublime Text (atleast in 3, not sure 2). Just copy the text you are replacing, then press <C-k><C-v>. This will popup a small window with clipboard's history. Select the previous copied text to replace currently selected text.
This option is available under Edit -> Paste from History.
HTH
You can do it too with a clipboard history https://github.com/colinta/SublimeClipboardManager
Copy: oneCopy: twoPaste-previous in twoPaste-next in one
The good thing is that clipboard history can be helpful in more situations
The situation is: in my html-file I have a lot of "href" attributes to be filled with specific links. And I can get multiple cursors on every needed place.(via Ctrl+D, or Alt+Enter).
Now it would be very helpful if I could switch between this cursors with tab(like emmet plugin does with self-generated html-content, if you know what I'm talking about).
You can have multi cursor, and switch between them in using :
Ctrl + F3
or
Ctrl + Shift + F3
You can get the behavior I believe you want by selecting all the "href" attributes using ctrl+d. If you are selecting all of them, you cna run the find_all_under command (alt + f3 in windows, unsure of other platforms but you can search for the command). Then, bookmark the cursor positions (ctrl+f2 in windows). You can then use f2 to cycle through the bookmarks. You could bind the appropriate command to tab if you want also, though you would have to do some work do you don't break normal tab behavior.
As a side note, I believe emmet simply inserts a snippet, so it defines various locations for the cursor to jump to through the built in snippet behavior.
#Jahnux solution may be more ideal since you wouldn't have to select initially, but I believe you would have to move the cursor back to the "href" attribute for continuing to the next token.
You may also want to investigate simply using the find functionality, though perhaps you have run into some limitations with that.