How to make PhpStorm automatically highlight selection
Asked Answered
H

2

10

I cannot find a way to make PhpStorm highlight the appearances of a selected word/string in a file automatically at the time of the selection.

Example - say I have this code (the logic doesn't matter):

$app = new App(); //this is an app var of type "App" that contains our Application
$application_ranks = $app_array['app_rankings'];    //some operation

Now, I make a selection - say I select the first "app" part.

PhpStorm behavior with BrowseWordAtCaret plugin installed (no highlighting whatsoever):

enter image description here

Sublime Text 2 behavior (incomplete):

enter image description here

Notepad++ behavior (close, but still not perfect):

enter image description here

PhpDesigner 8 behavior (works as expected):

enter image description here

To save your time, I am aware of the "Highlight Usages" feature which pretty much does the same thing - the problem though is that this works only for variables/classes/function names/function calls etc, while what I am after is for this to work for ANY selected sequence of characters, regardless if it is a variable or a comment or a function or whatever. Like if you pressed Ctrl+F (Find).

I did try the BrowseWordAtCaret plugin for PhpStorm suggested in this post but it still doesn't provide this functionality.

Is it possible to somehow achieve this? I am quite bewildered that something so simple (and basic - maybe even fundamental for coding in my opinion) is so hard to achieve on an editor this full of capabilities and so much devoted to provide a great user experience etc.

Thanks for your time!

Halvorsen answered 20/11, 2015 at 14:28 Comment(3)
"I am quite bewildered that something so simple..." It could be simple .. but is it actually needed like that by users (lots of users)? Why core devs should implement something that nobody (better say -- very little number of users) will be using but requires a lot of time and resources (and possible additional customisation settings) to be implemented. I'm using BrowseWordAtCaret plugin and it does the fine job for me. At the same time -- your "perfect" solution looks terrible for my liking (every second word is highlighted...)Infuscate
But to answer the actual question -- AFAIK there is nothing that would do such highlighting (all current solutions seems to be based on identifiers and/or whole word matching only) which makes Ctrl+F (Find on page) your best friend (especially for partial word matches).Infuscate
@Infuscate "Every second word is highlighted" - yes, this exactly is the point of the whole fuss :P I don't see what's so terrible in this - quite the contrary. Still, you would be able to make it filter the results if you wanted (to match case, to search only for variable names, to ignore comments, etc). Anyway, I do not believe that the number of users using this is little, and this - the fact that "every second word is highlighted" - is dead useful in a lot of occasions. Plus it saves you a lot of time and concentration, compared to using "find".Halvorsen
H
13

Not the perfect solution, yet close enough:

Top Menu -> View -> Highlight Word at Caret

or alternatively:

Settings -> Editor -> General -> Appearance - Highlight Word at Caret

Note that this is a BrowseWordAtCaret plugin option, so it requires the installation of the plugin. To install it, go to Settings -> Plugins -> Browse Repositories -> BrowseWordAtCaret -> Install.

This will still not highlight the word if it's part of another string, but it will highlight it in all other occasions. Example:

PhpStorm:

enter image description here

PhpDesigner:

enter image description here

Halvorsen answered 23/11, 2015 at 10:58 Comment(0)
G
3

Edit in 2021:

  1. Go to: Preferences | Editor | Code Editing

  2. Find the following section in General: Highlight on Caret Movement

  3. Check the following checkbox: Highlight usages of element at caret

Note, this does not work as OP asks, in fact there's no current way to make the IDE work like that.

The BrowseWordAtCaret plugin comes close but only works on full words. You have to configure it to auto-highlight as well: Preferences | Editor | General | Appearance.

Gaily answered 16/5, 2018 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.