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.
Related
I'm in PhpStorm and I need to select some text, press some shortcut and have that text wrapped in a function call (that I would have defined somewhere in the settings beforehand).
For example:
"Hello World" would become input("Hello World").
$_GET["foo"] would become input($_GET["foo"]).
I don't know if this is even possible, but it could help me save so much time if so.
Applying regex to solve this problem is unfortunately not possible. Manually selecting what I need to wrap isn't an issue.
Will the function name be the same every time or different?
In any case: it can be done this way:
Make a Live Template of "surround template" type with the following content:
$FUN$($SELECTION$)$END$
The $SELECTION$ variable here tells that it's a surround template.
Apply correct Context (where this template can be used)
Give it an abbreviation (name used to locate & invoke it) and brief description.
Here is mine:
NOTE: replace $FUN$ by a fixed function name if the function will always be the same. You can have additional templates with different abbreviations (that will have different hardcoded function names).
To use it:
Make a selection and invoke Code | Surround with... action where you select the right template. On Windows keymap it's Ctrl + Alt + T
In action (NOTE: it's without hardcoding the function name hence me typing the myFunc part):
(HINT: you can select the desired entry in a few keypresses if the name is unique -- just start typing the name in the popup -- the standard Speed Search work here)
P.S. Code | Surround with... can have other (possibly irrelevant for you in this case) entries. To list Live Templates only, use the shortcut for Surround with Live Template... action (Ctrl + Alt + J here on my Windows keymap). You can check the shortcut or change it in the Settings/Preferences | Keymap:
This way the popup menu will be a bit shorter:
Less keypresses:
You may be able to use Macros functionality to record the invoking the popup and selecting the right entry. You can then assign a custom shortcut to that Macros: select the text, hit the shortcut and it will playback the recorded sequence.
Sadly I cannot 100% guarantee that Macros will always work nicely (sometimes/on some setups it can "eat" keypresses).
P.S. It would be much easier if the IDE would support assigning keyboard shortcuts to specific Live Templates .. but it's in the backlog and no ideas on when this might be implemented. Anyway: https://youtrack.jetbrains.com/issue/IDEA-67811 -- watch this ticket (star/vote/comment) to get notified on any progress.
P.S. You can also try Postfix completion. It's good for writing the code and not really suitable for your case (editing small parts of it), but who knows. You will have to make a custom postfix for this -- should not be an issue though.
https://www.jetbrains.com/help/phpstorm/2021.3/auto-completing-code.html#postfix_completion
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 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.
I need to change occurrences of a term only in certain places in my project.
Is there a way in Sublime Text to navigate the search results (across an entire project) and only replace the occurrences of my choice?
⌘ShiftF opens the "search and replace" for the entire project, but the Replace button only gives me the option to replace all occurrences.
If you press the ... button in the search panel, a menu will open that allows you to refine your search. You can use the Where input field with a search pattern, or some tags like <open-files>.
http://docs.sublimetext.info/en/latest/search_and_replace/search_and_replace_files.html
Other than that, if you really need human input to decide where to replace and where not to replace, you can go to the next result by pressing Enter and pasting the code manually.
Just in case you didn't know: when you make a project search a new text file opens up with all the occurrences. You can click those occurrences to navigate to the file in question.
For posterity, the functionality to search/find and replace inside the open project does exist. ⌘ShiftF and add <open project> to the Where input field.