Questions tagged [code-formatting]

Code formatting is the way to format the source code of programs,using spaces and tabs, improving legibility of source code.

Formatting the code, such as introducing spaces or tabs, is an important and fundamental rule of good programming.

In this way, it's possibile to improve the legibility of source code, following the logical structure of program, in order to separate more clearly the instructions.

Modern text editors or IDE, such as Eclipse or NetBeans, perform functions of automatic code formatting, to help programmers about code developing.

Other info on Wikipedia.

1457 questions
9401
votes
26 answers

What is the "-->" operator in C/C++?

After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4. Here's the code: #include int main() { …
GManNickG
  • 459,504
  • 50
  • 465
  • 534
1850
votes
20 answers

How do I format XML in Notepad++?

I have Notepad++ and I got some XML code which is very long. When I pasted it in Notepad++ there was a long line of code (difficult to read and work with). I want to know if there is a simple way to make the text readable (by readable I mean…
happyhardik
  • 22,805
  • 6
  • 42
  • 58
990
votes
29 answers

How do you format code in Visual Studio Code (VSCode)?

What is the equivalent of Ctrl + K + F and Ctrl + K + D on Windows in Visual Studio for formatting, or "beautifying" code in the Visual Studio Code editor?
Brandon Clapp
  • 56,445
  • 6
  • 17
  • 24
837
votes
24 answers

Code formatting shortcuts in Android Studio for Operation Systems

I have started developing with Android Studio. In Eclipse I was using Ctrl + Shift + F, but in Android Studio it does not work. It will be different. How can I jump to any method in a .java file? I was using Ctrl + O in Eclipse. Is it available?…
Bhavesh Hirpara
  • 21,576
  • 12
  • 60
  • 102
614
votes
20 answers

How can I indent multiple lines in Xcode?

When I select multiple lines of code and want to indent them as usual with TAB key, it just deletes them all. I come from Eclipse where I always did it that way. How's that done in Xcode? I hope not line by line ;)
Thanks
  • 39,247
  • 69
  • 202
  • 315
506
votes
13 answers

How to turn off the Eclipse code formatter for certain sections of Java code?

I've got some Java code with SQL statements written as Java strings (please no OR/M flamewars, the embedded SQL is what it is - not my decision). I've broken the SQL statements semantically into several concatenated strings over several lines of…
Greg Mattes
  • 30,462
  • 13
  • 66
  • 103
443
votes
16 answers

Ruby: Can I write multi-line string with no concatenation?

Is there a way to make this look a little better? conn.exec 'select attr1, attr2, attr3, attr4, attr5, attr6, attr7 ' + 'from table1, table2, table3, etc, etc, etc, etc, etc, ' + 'where etc etc etc etc etc etc etc etc etc etc etc…
Zombies
  • 22,793
  • 38
  • 132
  • 216
435
votes
17 answers

Tool to Unminify / Decompress JavaScript

Are there any command line scripts and/or online tools that can reverse the effects of minification similar to how Tidy can clean up horrific HTML? (I'm specifically looking to unminify a minified JavaScript file, so variable renaming might still be…
Andy Ford
  • 8,221
  • 3
  • 24
  • 34
431
votes
13 answers

How to auto-format code in Eclipse?

How do you auto-format code in Eclipse?
HasanAboShally
  • 17,553
  • 7
  • 26
  • 33
408
votes
11 answers

How to auto-indent code in the Atom editor?

How do you auto-indent your code in the Atom editor? In other editors you can usually select some code and auto-indent it. Is there a keyboard shortcut as well?
Anders
  • 9,518
  • 7
  • 25
  • 34
383
votes
2 answers

How can I beautify JSON programmatically?

Do you know of any "JSON Beautifier" for JavaScript? From {"name":"Steve","surname":"Jobs","company":"Apple"} To { "name" : "Steve", "surname" : "Jobs", "company" : "Apple" } Example some_magic(jsonObj); // return beautified JSON
Randy Mayer
  • 6,917
  • 8
  • 22
  • 11
342
votes
6 answers

How to disable code formatting for some part of the code using comments?

I'd like to selectively disable the IntelliJ IDEA code formatter for a portion of code just like I can in Eclipse. Does IntelliJ support this feature, and if so, how do I use it?
Greg Mattes
  • 30,462
  • 13
  • 66
  • 103
299
votes
4 answers

How to format code in Xcode?

I wonder how can I format my code to align it neatly? Does it have a feature similar to Eclipse's ctrlshiftf?
James Raitsev
  • 82,013
  • 132
  • 311
  • 454
267
votes
9 answers

How can I autoformat/indent C code in vim?

When I copy code from another file, the formatting is messed up, like this: fun() { for(...) { for(...) { if(...) { } } } } How can I autoformat this code in vim?
Yongwei Xing
  • 11,745
  • 21
  • 65
  • 88
261
votes
7 answers

How do you format code on save in VS Code

I would like to automatically format TypeScript code using the build-in formatter when I save a file in Visual Studio Code. I'm aware of the following options, but none of them is good enough: Format manually Shift + Alt + F Format on type…
Tomas Nikodym
  • 8,782
  • 3
  • 15
  • 17
1
2 3
97 98