Tweak code-completion in JetBrains product - ide

How can I make JetBrains write code instead of me?
For example, in WebStorm I can type fori and press Enter and this will provide me with a template for a for loop.
Now I would like to have my own commands for my own code. Is it possible?
Thank you.

It's called "Live Templates".
Yes, you can create your own snippets / override bundled ones: Settings/Preferences | Editor | Live Templates.
This how-to is made for PhpStorm, but it's the same for all languages/IDEs:
https://confluence.jetbrains.com/display/PhpStorm/Live+Templates+%28Snippets%29+in+PhpStorm

Related

How to auto-generate comment using custom shortcut in IntelliJ?

I'm trying create a custom shortcut in IntelliJ to generate some predefined comments.
For example, if I write //-- and press enter, it should auto-generate:
//------------------------------------------------------------------------------//
//------------------------------------------------------------------------------//
The Postfix Completetion feature looks like it could be used for this but I didn't figure out how to set it up for this scenario. Can someone help?
If Postfix Completetion is not the answer, can I do it with another feature?
You can create a Live Template (Preferences | Editor | Live Templates). For example, a template like the following:
//------------------------------------------------------------------------------//
$END$
//------------------------------------------------------------------------------//
The $END$ indicates where the text cursor will be placed when the Live Template text is inserted. At the bottom of the Live Template settings screen you can configure in which languages/contexts the Live Template should be available.

Lazarus - How to create an own $(CustomRelativeUnitPath)

as mentioned quiet similar in the header, may someone tell me, how can I create an own custom-relative-unit-path for the lazarus IDE (version: 2.0.6) .
The IDE has alreaday some internal $(RelativePaths) but I would like to create my own ones and setting them up in the "other unit paths" and finally use them of course ^^
i wanna do somewhere like: "$(MyCustomPath) = C:\Lazarus(someotherpathhere..)"
and put $(MyCustompath) in the "other unit" line and have it work ^^
Below what I would like to see :-)
Best regards
Shpendicus
enter image description here
I think the way to do this may be to use Lazarus IDE macros.
See https://wiki.freepascal.org/IDE_Macros_in_paths_and_filenames for full documentation.
In the section IDE Macros it says
IDE macros: they can be used in almost all IDE fields, e.g. search paths, custom options, file names, run parameters. They are replaced with their value before calling external tools like the compiler or the debugger. They are case insensitive.
and the IDE macro format section includes a few examples of ones which are already defined.
Creating macros is explained here: https://wiki.freepascal.org/Macros_and_Conditionals
To set a macro up for the current project, do the following:
Go to Project | Project Options | Compiler Options | Additions and Overrides
On the righthand side, click Add and select IDE Macro from the drop-down menu
This will open an IDE Macro line in the editor below. In it, replace
MacroName by MyCustomPath and Value by whatever you like. I used D:\Lazarus2\MA
Close the Project Options pop-up
Next, in the directory that MyCustomPath points to, create a unit e.g. Test.Pas that includes a compile stopper like an ! I used
unit Test
interface
!
implementation
end.
Add Test.Pas to the project's Uses list and attempt to compile. The compiler should complain that it can't find Test.Pas.
Next, open Project | Project Options | Compiler Options | Paths and in the Other unit files box at the top insert $(MyCustomPath)
Close Project Options and compile - now the compilation should proceed until it encounters the compile-stopping ! in Test.Pas

How to find the commented code in IntelliJ IDE?

Does anyone know a way to search for all (and only) the commented code across all classes in a java project?
For example, using "Find in Path" to search for "//" is not what I want because it also returns URIs (http://......). I want a specialized way to do that.
Thanks in advance.
You can use Structural Search in IntelliJ IDEA.
Below screens as for the version 2019.1.1 (Ultimate Edition) (Works for IntelliJ IDEA 2020.3 too)
Go to Edit > Find > Search Structurally...
File type should be Java and select any path wherever you like to search.
From the top right corner click on gear icon and click on Existing Templates...
Then from Java > Comments, Javadoc and Metadata select comments
Then it will add /* $CommentContent$ */ to the Structural Search window as for the first screenshot.
This will find all the commented code (including Javadoc) from the selected path.
For more info refer : Structural search and replace
About the best you could do would be the Find In Path and use a REGEX of:
^//
That will fix your http:// problem. But it won't find comments that don't start at the beginning of a line. I suppose you could write a much more complex REGEX to find "//" but not proceeded by http: But of course comments can be in /* */ blocks too. So it all depends on how absolute you want to get.
As of intellij 2020.3, there is an inspection for commented out code in java:
Java | Code maturity | Commented out code
So if you want a list of commented out code, you can:
right+click your project, module, subfolder, directory or file where you want to search.
click analyze > inspect code
Click OK
This should open the inspection result window where all your commented out code will be grouped under Java | Code maturity | Commented out code :
If you don't want intellij to search for other issues too, you can create a new profile in File | Settings | Editor | Inspections exactly for that and select it in the analyze dialog.

Seeking plugin for displaying keyboard shortcuts in Webstorm

I'm looking for a webstorm plugin that would help me remember keyboard shortcuts. I know for a fact that this plugin exists for IntelliJ, it displays the right-shortcut every time we perform an action without using shortcuts, but I didn't find any thing like this for webstorm?
If you know (and understand) what I'm talking about, can you tell me what plugin could help me with it?
Thanks for your time,
Fabien
Key Promoter plug-in is compatible with WebStorm, you can also use Help | Find Action and type the action name, shortcut will be displayed on the right.

How to rerun programmatically the program (intellij idea plugin)

I want to programmatically rerun(There is a command for this also you can use ctrl-f5) Below is a picture of rhis button in idea
So how I can run this action by myself?
from the answer on intellij idea development forum
Hi Evgeniy,
You should use ExecutionManager.restartRunProfile() for that.
Default IJ implementation achieves that via RestartAction (the one from your screenshot).
Denis