Shortcut to apply format for XCode? - objective-c

I Eclipse there is a shortcut to apply format which is:
Cmd + Shift + F
Is there a similar shortcut in Xcode which fixes the formats like tabs, etc.?

You probably want Editor -> Structure -> Re-Indent (Ctrl+i). I does not change the position of braces and things like that. For that, you'd need to use an external code formatting tool like Uncrustify.

Related

IntelliJ IDEA: is there a way to format java code in a canonical way?

I have two java source files. Both represent the same class (semantically), but they were formatted differently.
For example, one of them contains the following line:
return Boolean.valueOf(Boolean.getBoolean("abc"));
While in the second file it looks like 2 lines:
return Boolean.valueOf(
Boolean.getBoolean("abc"));
In both cases, when I apply formatting (Ctrl+Alt+L), these lines do not change.
Is it possible to format them in some canonical way: that is, to get the same code if the only difference is formatting?
Equivalently: is there any way to remove all ignorable whitespace? Such a 'dried-out' program would then be easily restored using 'Reformat code'.
You should be able to do this if you turn off "Wrapping and Braces | Keep when reformatting | Line Breaks" in the Java code style settings.
Go to File > Settings > Ediotor > Code Style > java
in tab Wrapping and Braces uncheck line breaks
Apply and make (Ctrl+Alt+L) again.

Intellij: how to convert indents for all files

I know how to convert indent for a single file. I go to edit -> convert indent -> space/tab.
But I want to do this for all files under a directory.
I try click on a directory and then go to edit -> convert indent, but the options are grayed out.
You can use the shortcut Ctrl+ALT+L (Windows/Linux) or ⌥⌘+L (MAC OS X) and select the Rearrange entries option to reformat the code in the current file or reformat a module or directory.
You can also Right-click a module, file, or directory from the context menu and select Reformat Code and also select the Rearrange entries option.
This will convert the indents for all files/directories selected:
This works on most of the Jetbrains IDES (iDea, PyCharm, WebStorm, RubyMine, and so on.)
It seems there is no such dedicated option in IntelliJ, but you could just work around it using a "low-level" Replace All action.
Open the Edit → Find → Replace in Files... dialog
In case you want to convert spaces to tabs, you should
Enter in the Find field (i.e. four spaces (or whatever number of spaces the project is currently indented with))
Press the Regex search modifier (Alt + X)
Enter \t in the Replace field
NB: In case you have valid strings with 4+ spaces in them, they will get replaced too. In most use cases, however, this is not happening.
In case you want to convert tabs to spaces, you should do the same as above, but swap the Find and Replace field contents
NB: Again, if you have valid strings with tabs in them, they will get replaced too. I haven't had this use case, because I've only needed to convert in the opposite direction.
You will probably also want to set a File mask in order not to replace spaces in code-irrelevant files

Making "Search Everywhere" in PHPStorm similar to Sublime Text 3 "Goto Anything"

I'm making the switch over from ST3 and I would like to replicate one of the search behaviours that I frequently used in ST3.
When I used Sublime Text 3, I would frequently press Ctrl + P to bring up the "Goto Anything" panel.
It looks like this:
As you can see, the ST3, uses fuzzy string matching to match any path and file name in your project.
So for example typing
ze vi help will match any file which contains that sequential list of characters in it's file path.
On the other hand, when you use PHPStorm for "Search Everywhere" it only searches the class name or the file name.
Is there a way to include this functionality? I would like PHPStorm to search the filepath and filename, rather than the PHP class names in the files.
If you miss a fuzzy file search like the one in Sublime, please vote for IDEABKL-6959
You can use double shift, it is called "search everywhere"
What I did, I remapped double shift to cmd+p
This feature will finally be available in version 2017.3!
As of now you can only search the path while using / - so for example if you have a file in app/http/controller/somecontroller.php you can search it via ttp/lle/con.
BUT: The feature has been implemented in the new build, which is already available in an Early Access Programm
(see https://blog.jetbrains.com/phpstorm/2017/09/phpstorm-2017-3-eap-173-2290/)
I don't know how the functionality in Sublime works exactly, but in PhpStorm you can use 3 ways of searching everywhere, as you can see here.
Cmd + O will search by class name.
Cmd + Shift + O will search by file name.
Cmd + Alt + O will search by symbol (properties, methods, etc)
If you want to search for all files with help in their path, I am pretty sure you can do a file search with Cmd + Shift + O and then type help/*.
The keys are to include the forward slash /, otherwise it will search for files containing help somewhere in their filename.
And also use the wildcard *, otherwise it will search for folder names with those characters.
Update: you can also click Shift twice, and it will allow the same kind of search, but in files, classes, symbols and even PhpStorm tools - all at a time.

IntelliJ force code formatter to join lines based on wrap settings

How can i reformat file(s) in IntelliJ and join all lines that are split.
I know that I can do that individually by selecting lines and "join lines" with CTRL + SHIFT + J
Since we changed our code formatting wrap policy recently I want to be able to join lines in all files based on the updated wrap setting. (Settings > Code Style > General > Right margin)
The only thing is that IntelliJ seems happy to split lines based on wrap setting, but will silently deny to join lines based on that setting.
Unlike the question Force code formatter in IntelliJ to join lines, I am not satisfied by splitting lines or joining manually (as the accepted answer suggests). I want IntelliJ to join lines automatically.
Bonus question: Which other editors can do this?
Disable the following code style option - Project Settings - Code Style - Wrapping and Braces - Keep when reformatting - Line breaks
IntelliJ IDEA 15
File > Settings... > Editor > Code Style > Java > Wrapping and Braces > Keep when reformatting > uncheck Line breaks
(if you want to have the same setting for another type of file, choose it from Code Style)
Go to Code > Reformat Code (Ctrl + Alt + L).

How do I indent multiple lines at once in Notepad++?

In many text editors that are aimed at programmers, if the user has a selection that spans more than 1 line and presses the TAB key, those lines are indented by 1 TAB (or a number of spaces, depending on how the editor is configured).
However, this does not seem to be the default behavior of Notepad++. Is there a way I can do this in Notepad++, or is there a plugin that I can get to allow me to do this?
Edit: Upon additional testing, SHIFT-TAB correctly un-indents the lines as expected, but only a tab simply inserts a tab wherever the carat is. This is in version 5.4.5 Unicode
The problem was with the QuickText plugin. After removing it, indent worked as normal.
Capslock + Tab to indent multiple lines at once. Highlight the text first.
The problem with the new version of QuickText seems to be that it is set to react to the TAB key. Previously it was set to use CTRL-ENTER. If you change the key combination in the shortcut mapper then your TAB key should start working again, and QuickText should also work (with whatever new key you've assigned).
It works fine for my v. 5.4.5 of Notepad++. I just select multiple lines and press TAB.
If you want TAB to be replaced by SPACE than you need to go Settings > Preferences and select Edit Components tab. Next check Replace by spaces check box in Tab Setting section.
Update: In a newer version of Notepad++ this option is in Settings > Preferences > Language section.
If you're using QuickText and like pressing Tab for it, you can otherwise change the indentation key.
Go Settings > Shortcup Mapper > Scintilla Command. Look at the number 10.
I changed 10 to : CTRL + ALT + RIGHT and
11 to : CTRL+ ALT+ LEFT.
Now I think it's even better than the TABL / SHIFT + TAB as default.
I have Notepad++ 5.3.1 (UNICODE). I haven't done any magic and it works fine for me as described by you.
Maybe it depends on the (programming/markup/...) "Language"?
Just install the NppAutoIndent plug-in, select Plugins > NppAutoIndent > Ignore Language and then Plugins > NppAutoIndent > Smart Indent.
Notepad++ will only auto-insert subsequent indents if you manually indent the first line in a block; otherwise you can re-indent your code after the fact using TextFX > TextFX Edit > Reindent C++ code.
in Notepad++v6.1.8 (Unicode) it works after removing the QuickText plugin.
To increase indent - Press and hold TAB
To decrease indent - Press and hold TAB + SHIFT