How can I add a custom key shortcut (ie: ctrl-something) in IntelliJ / Android Studio, so that it will automatically add a custom snippet that I associated to that combination? Is there a way?
You can create a live template settings>Editor>Live Templates.
Choose your category, and click on the "+" sign. You can then choose the abbreviation, add variable using the $VARIABLE$ notation and the context (Java, XML etc..).
Now you can just type the abbreviation in the editor and auto-complete it (ctrl+space, tab) and your snippet will be written.
Related
In Thymeleaf you can use parser-level comment blocks that everything between <!--/* and */--> will be removed by Thymeleaf.
<!--/* This code will be removed at Thymeleaf parsing time! */-->
Is there any way to define this type of comment and use a shortcut for it in the IntelliJ IDEA? I know we can use CTRL + /, but it generates Standard HTML/XML comments which are closed within <!-- and -->.
Well, It seems that there are no way to define a new comment style in IntelliJ IDEA. But I found a workaround by using the Live Template functionality.
You can create a live template for parser-level comment blocks and then invoke it. Follow the following path:
File -> Settings -> Editor -> Live Templates -> HTML/XML -> ADD
Copy and paste the following live-template to the Template text, and choose suitable abbreviation and description:
<!--/* $SELECTION$ */-->
There are two ways to use this live template
Type PC and then press the Tab, IntelliJ automatically creates a parser-level comment block.
Mark-up the desired codes or texts and then press Ctrl + Alt + J, and then from the shown pop-up menu you can select the parser-level comment block option.
Unfortunately you cannot set any Keymaps (shortcuts) for your Live-Templates.
In the settings window of Phpstorm, there is a dropdown box labelled scheme
What does it do?
What does it do?
You may be surprised .. but it allows you to choose another (different) Code Style scheme for this project.
PhpStorm supports globally defined schemas (by default it provides only one -- "Default") which can be used by any project and project-specific schema called "Project" which available for this project only (and stored together with other project-specific settings).
You can read more in official help page.
The Code Style is used for code formatting: be it automatic as you type / use live templates etc .. or manual reformat via Code | Reformat Code...
It's used to
choose the code style scheme to be used as the base for your custom coding style for the selected language (Source).
In other words: after selecting a scheme, you can set different formatting options, like tabs vs spaces, tab size or line breaks etc. To use those settings in your current project, you need to click Manage, select your edited scheme and click Copy to Project. After this, you can press Ctrl + Alt + L (Code > Reformat Code...) in the editor to reformat a file according to those scheme settings.
PyCharm (and the other IntelliJ IDEs) have the idea of intention actions. One that I want to customize is the "Insert documentation string stub" so that it includes type annotations. I can't type in the After section or find a menu that allows me to modify it at all - is that possible? If not, is there another plugin or something that will allow such a modification?
You can not customize intentions. But you may use Live Templates, they are very customizable: https://www.jetbrains.com/help/idea/2016.1/live-templates.html
I could not find the live templates for Java! Who can tell me how to set? Thanks.
They're inside all the nodes that are not specific to another language than Java: iterations, output, plain, surround, etc.
As JB Nizet wrote there is not a special node for Java (but you can create one). If you want your own Live Template for Java created do the following.
Open Settings window (File -> Settings)
Click on Editor -> Live Templates
Choose Template Group in which you want to add your Live Template
(you can create your own Template Group if you wish)
Click on + icon and choose Live Template
Specify the Abbreviation, Description and Template text.
Do not forget to define the context (in your case Java)
Example
Here is an example of how to create your own TODO text
Open the Setting window with Live Templates editor (as specified above).
Click on + icon and select Template Group.
Name this group Java.
Click on + icon again and select Live Template.
Specify your Live Template and DEFINE CONTEXT.
In my case writing mtodo and pressing enter will result in:
// TODO myName
You can even use variables. Write in your Template text e.g. $DATE$ and $TIME$
// TODO myName $DATE$ $TIME$
Click on Edit variables button and assign to each variable (defined by dollar sign) and expression (predefined function).
Now mtodo will result in
// TODO myName 13.10.2015 15:39
Predefined functions could be found here. The example was created using IntelliJ IDEA 15 EAP.
For those of you who have taken Postfix completion for Live templates, it is worth mentioning they are different. from not-choosing pretty good answers from #JB Niznet and #vitfo, I guess that's the case for OP writer. The document, here, says:
Postfix code completion is similar to live templates, it transforms the current expression without selecting it. For example, you can type .if after an expression to invoke the corresponding postfix completion and wrap the expression with an if statement.
You can check out a list of postfix completions:
Open the Preferences window
Click on Editor -> General -> Postfix completion
By default, there is no JAVA group in this setting page.
However, these default settings distribute on each feature group. For example, iterations:
IntelliJ IDEA 2019.2.4 (Ultimate Edition)
I have an Eclipse RCP application. I have created an Editor. There are few context menu (default), when I right click on the Editor. I have not created these menus.
Please let me know, How to remove the context menu of the Editor?
It needs different approach by which editor you extends.
Let me know What you extends, than I can answer more efficient one.
In general way:
IWorkbenchParSite#registerContextMenu(...) will be used, So find where calls that, override it. It is not recommend. Because by doing this, Menu Extensions which is contributed for your editor will not work anymore.
If you mean the system menu that appears on editor tabs and view tabs, that menu is provided by the presentation (2.1, Classic, Default, etc). There is no tweak to simply modify it.
The 2 ways to remove it would be:
write your own presentation, using
the
org.eclipse.ui.presentations.StackPresentation
API and matching extension point.
Writing a presentation is a involved
undertaking.
Change the internal classes in the
org.eclipse.ui.workbench plugin
and patch that plugin in your RCP
app.
If you use Text or StyleText you will get the system default menu (cut,copy,paste, maybe something about encoding or input). If you are not going to supply your own menu, simply create an empty SWT Menu and set it:
Menu emptyMenu = new Menu(text);
text.setMenu(emptyMenu);
Eclipse also has a text editing framework, if you need more than a basic text box you should check it out. http://wiki.eclipse.org/The_Official_Eclipse_FAQs#Text_Editors