How to write short codes in brackets? - emmet

Just like in sublime you can type foo.bar, press Tab, and you'll get <foo class="bar"></foo>. There's also foo#bar (for id instead of class).
How can we do this in Brackets editor?

This plugin is called Emmet.
Run Brackets.
Select File > Extension Manager...
Find “Emmet” extension and click “Install” button
(source)
Here is the list of all supported platforms.

Related

How to use Option in Intellij Keymaps?

I am trying to add Option-i | u for "Find usages" as shown in this dialog (Note that the "i" is lowercase - shift is not depressed):
But after having selected OK and then going back into Actions we see that the setting did not "take":
Note: I do have custom keymap entries to use Option- for accessing Main Menu items. But why is Option not working in this case? Is there a workaround?
On macOS, "Option" is used for typing special characters, thus when editor is focused and you hit Option-I the shortcut you assigned won't work (it will type a character instead).
However, when no editing field is selected, the shortcut should work (e.g. from tool windows).

Add a custom shortcut to IntelliJ IDE

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.

How to convert $SELECTION$ to snake case(for example) using live templates?

How to convert selected code to snake case for example (or camel case or something other standart expression from live template variable options)
The answer was provided in this comment on the JetBrains forum
There is "String Manipulation" plugin that lets you to convert the
case of selected text via the right click menu or via custom
shortcuts assigned at Settings/Preferences > Keymap.
You can install the plugin via Settings/Preferences > Plugins > Browse
repositories.

How can I enter a literal <TAB> character in IntelliJ/IDEA/PyCharm?

My configuration indents with four spaces, and I want to keep that. Occasionally (e.g. in a Makefile) I want to input a literal TAB character.
How can I force the IntelliJ-IDEs to input a tab or space, when it would not do so when I hit tab or space in that instance?
You seem to be asking two questions here:
1. How do I force IntelliJ IDE to input a tab, when it would not do so when I hit tab?
and
2. How do I force IntelliJ IDE to input a space, when it would not do so when I hit space?
I don't understand how the second case can arise. However, I have provided a solution to it as well.
Case 1. Insert a tab character when an IntelliJ IDE wants to replace it with spaces due to configuration
Solution
Use search and replace.
Details
Place the cursor where you want the tab to be
Press the X key
Select the X you just typed
From the main menu, choose Edit | Find | Replace to bring up the search and replace pane
Make sure there is an X in the search field
Enter \t in the replace field
Be sure the option Regex is checked
Be sure the option In Selection is checked
Click the Replace button
Case 2. Insert a space character when an IntelliJ IDE won't just let you type one (???)
Solution
Use search and replace.
Details
Place the cursor where you want the space to be
Press the X key
Select the X you just typed
From the main menu, choose Edit | Find | Replace to bring up the search and replace pane
Make sure there is an X in the search field
Enter a single space into the replace field
Be sure the option In Selection is checked
Click the Replace button
Install the plugin for Makefile support: https://plugins.jetbrains.com/plugin/9333-makefile-support
When I tried it today, this automatically use hard tabs in the editors for Makefile files.
Open another text editor, type a tab, and then copy and paste into the PyCharm editor. In MacOSX this worked for me using both Sublime Text 2 and TextEdit.
I can't think of any "direct" way. Probably the easiest way that I can think of is to write a Live Template to do it. See the help page on Live Templates for more information. When you write it, you may need to copy and paste a tab character in from another application.
However, when I tried it, IDEA saw it as just empty text and would not save it. So I used a variable with the "capitalize" function to capitalize a tab character.
Here's the template I created that you can paste into your templates. Now I type tab, hit the Tab key and I get a tab character. Of course you can change the abbreviation.
<template name="tab" value="$TAB$" description="Enter a tab Character" toReformat="false" toShortenFQNames="true">
<variable name="TAB" expression="capitalize(" ")" defaultValue=" " alwaysStopAt="false" />
<context>
<option name="OTHER" value="true" />
</context>
</template>
You could extend the idea to have multiple ones that enter multiple tabs. For example tab to enter 1 tab, tab2 for 2 tabs, etc.
Screenshot of it after use:
There may also be a way to hack a macro to do it. You could then assign the macro to a keyboard shortcut. I'll see if I can figure something out and update this if I do.
Use the menu option: Edit -> Convert Indents -> To Tabs.
Whenever I edit a makefile I do the "to tabs" conversion before I save the file.
UPDATE: Really sadly, I think the generated character still gets converted to spaces... Am checking...
There is an Action in JetBrains IDEs to enter a Tab character.
Here are the steps to use the Tab character action: (discovered in PyCharm 2020.3)
Double-tap the Shift key OR Help -> Find Action...
Type the 3 characters tab
Click on the action that is called Tab and shows the icon for the Tab character...
It remembers the last action you did, so if you have several tabs to add, you can get into a quick process by doing ShiftShift then Return each time.
Answer based on #Morfic's comment to the question. I think this is the cleanest and most sensible reply here so I figured it deserves a place as an answer (and needless to say, it worked for me).
If they're different types of files you could configure File -> Settings -> Editor -> Code style -> Tabs and Indents for each one to use either space or tab depending on how you want it.
One way to do this is to copy a TAB character from another text editor, then right click in your PyCharm file and use Copy / Paste Special -> Paste as Plain Text (Ctrl+Alt+Maj+V)
I guess this was not available in older PyCharm versions, because no other answer proposed it. Regular paste (Ctrl+V) doesn't work (replaced by spaces), but this one works. The function will also bypass other automatic formatting.
Inspired of Clare's suggestion,
assign the left tab key after finding 'tab' action.
At Actions tab, search by 'tab' and move your up/down arrow key and place there.
Then type Ctrl+1, you will see a popup. Select as follows and click OK.
Then, you might be asked "Do you want to remove other assignments?" if Tab key was already assigned. Click Leave because your usage won't conflict with the existing setup.

Where is the live templates for Java in Intellij-IDEA?

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)