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

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.

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).

How can I expand multi-line selection to full lines in PHPStorm?

In Sublime Text I can arbitrarily select a set of lines and then use ⌘+L to expand the selection to the full lines. Is there a similar command in PHPStorm / WebStorm? (I'd like to map that command to a keyboard shortcut.)
I know PHPStorm has the option "Select Line at Caret", but that selects only one line.
Update
Nowadays (welcome 2020) Go to Preferences > Keymap. Change or add the value to
Add Carets to Ends of Selected Lines => CMD+SHIFT+L to have it behave like Sublime Text so it looks like
Old Answer
This is as close as I could get it (before 2020):
Go to Preferences > Keymap. Search for Clone Caret Above/Below.
On a Mac, it looks like this
The keys are:
CMD+SHIFT+CTRL+ARROW_UP for Clone Caret Above
CMD+SHIFT+CTRL+ARROW_DOWN for Clone Caret Below
Click on Apply and it will work
With WebStorm 11 (at least) the multi-caret keyboard shortcut is:
Ctrl then Ctrl+Arrow Up (or click & drag with the middle mouse button/scroll wheel)
then to select the full lines:
Home then Shift+End
which you could even create as a macro with a keyboard shortcut.
I used to accidentally activate the multi-caret all the time (I scroll with Ctrl+Up/Down), so I knew how to do part of it, but it took me ages to figure out that extra Ctrl tap at the beginning.
Hold down Alt + Shift and left click on the lines you want to select. This will put multiple cursors on the editor. Now you can use the Select Line at Caret option you mentioned to select all those lines.
You can find more about multiple selections here.
This is currently not possible with a selection. However, you can still do that from the keyboard. Instead of doing selections set up a shortcut for Clone Caret Above (Alt+Shift+U for me) and Clone Caret Bellow (Alt+Shift+D for me). This allows to go up or down a line and add a caret there. So instead of selecting each line, you directly move the caret there and clone it.
I am also coming from Sublime Text and missing that feature, but this worked also pretty well.

Wrapping comments with line breaks in PyCharm

I have comments that gets balloon (PEP 8: Line too long ... > 120)
I wish there was a command that will wrap the lines with few keystrokes.
Right now, even if I type Alt+Enter and press enter on Reformat file, nothing actually changes. Is there a setting or plugin I could use to accomplish the formatting easily?
Under the Edit menu, there is a Fill Paragraph option, which does what I believe you want. You can assign a key command to this in Preferences, under Appearance & Behavior -> Keymap (search for "fill").
Personally, I choose first stroke Esc, second stroke Q, because that's what I've always used in Emacs...
Firstly, reformatting won't work, not in Python at least, where whitespace is important. PyCharm's "Wrap when typing reaches right margin" option is what you're looking for. Now this will not work when you copy and paste code, but in the places where it gives you trouble, just press enter, and it will work.
To be able to auto-reformat comments (and code, for that matter) to honor a right margin after the fact, go into Project Settings under Code Style and then further under Python. Click the Wrapping and Braces tab, and check the "Ensure right margin is not exceeded" checkbox.
Now if you select a region of lines and then run the Code/Reformat Code... command, PyCharm will do its best to wrap the comments or code appropriately.
You will probably have to do some tweaking of the results to suit your stylistic taste. For example, I wish PyCharm would do aggressive filling of text in block comments, at least optionally so.
PyCharm will not reformat code such that it becomes invalid Python, so sometimes it will still leave a line longer than the margin (120 or whatever you set under Project Settings/Code Style/General).
With recent PyCharm this now is located at "Editor -> Code Style", with the checkbox named "Wrap on typing"
The Screenshot shows PyCharm version 2016.2.1 Professional.
Updated Answer:
Use "soft wraps." You can search for it in the help bar.
View > Active Editor > Use Soft Wraps
It won't work for existing text or text that's copied in, but will for any newly typed text.

Highlight BOTH matching braces into Gedit

Any way to highlight both braces on Gedit?, it's annoying when you have several braces joined and is not clear which one are you pointing.
Highlighting both braces would be a simple solution to know exactly what are the starting and ending ones.
Thanks.
Actually this feature does exist, to an extent anyway, in Gedit (2, in my case). Under preferences there is a check box in the view tab on the bottom called "Bracket Matching".
With that checked you can highlight the opposite bracket delimiter by putting your cursor over its twin. It goes both ways.
However, seeing that I use ruby, which utilizes "do/end" tags instead of curly brackets, I'm still looking for a hack for that. I'll try to remember to come back and share any more information that I find.
I have an option in my gedit 2.30 for this:
Edit -> Preferences -> Bracket Matching
At first I could't find where the preferences are located, I chose the harder option.
1. dconf-editor:
Press Ctrl + Alt + t and type dconf-editor
Go to org --> gnome --> gedit --> preferences
At bracket-matching and turn on flag
2. run in terminal:
gsettings set org.gnome.gedit.preferences.editor bracket-matching true
3. windows-way case:
In Ubuntu 18.04, Gnome 3.28 the preferences are located in the left corner near the Activities.
Preferences --> view --> Highlighting --> Highlight matching brackets
Currently (Gedit 3.14.0) it works as it has been already mentioned:
Preferences -> View thumbnail -> Highlight matching brackets
Both brackets are highlighted.
I suppose you enabled bracket matching (as in mbonnin's answer), but only one bracket is highlighted.
I made a bug report about that (see Highlight the 2 matching brackets) and it was fixed in a recent version of gedit (I think only version 3 contains this fix).

Xcode question: Quickly jump to a particular selector/class/symbol?

What is the quickest way to jump to a particular symbol/selector/class in Xcode? (I'm looking for keyboard shortcuts preferably).
Right now, I know two ways of doing this:
“Open Quickly” > Click on the Symbols dropdown menu at the top of the editor > Select the selector to jump to it.
Click on “Project Symbols” in the “Groups and Files” section on the left sidebar, and type in a name in the Search text field in the top right of the XCode window.
Is there a quicker way of doing this? (If I could even assign a shortcut to jump to the “Project Symbols”, that would suffice for me. Alternatively, if I can find a keyboard shortcut to jump to the symbol dropdown above an editor that would do it to).
For experienced Xcode programmers, what do you use to jump to a symbol?
In Xcode 3.2, the "Open Quickly" command (Shift-Control-D) lets you type in selectors and class names as well as file names. This would at least get you close to what you wanted.
Your idea about using the "Symbols" drop-down also works. You can use the keystroke Control-2 to bring up the Symbols drop-down menu, and then use the arrow keys, or start typing the name of the method that you want to reach.
Edit: In Xcode 4, the "Symbols" drop-down appears when pressing Control-6. You can change this in the Xcode settings by changing the key binding for "Standart Editor > Show Document Items".
If you're looking at the symbol in a source file and want to jump to its definition, ⌘-click it.
(command + double click) on your symbol/selector/class in any place of your implementation to jump to them
(option + double click) on framework classes/selectors to jump to their reference in help->documentation
One (arguably crude) way to do it seems to be as follows:
This is based on the fact that the Search field at the top right of the Xcode window seems to change behavior depending on what is selected in the Groups & Files sidebar.
Select “Project Symbols” in the “Groups & Files” sidebar
Press ⌥⌘F (That is Command+Option+F) to jump to the Search field
Enter the symbol to jump to, and an outline will quickly show up
(this will remain in effect until you click on something else in the Groups & Files sidebar)