Questions tagged [indentation]

Indenting is used to organize code by indicating blocks, closures, conditionals, and other constructs. It makes code easier to read, and in some languages is used to handle control flow.

2947 questions
2252
votes
33 answers

Indent multiple lines quickly in vi

It should be trivial, and it might even be in the help, but I can't figure out how to navigate it. How do I indent multiple lines quickly in vi?
Allain Lalonde
  • 85,857
  • 67
  • 175
  • 234
1353
votes
16 answers

How do I reformat HTML code using Sublime Text 2?

I've got some poorly-formatted HTML code that I'd like to reformat. Is there a command that will automatically reformat HTML code in Sublime Text 2 so it looks better and is easier to read?
Ravi Ram
  • 22,578
  • 20
  • 69
  • 97
1331
votes
11 answers

Tab key == 4 spaces and auto-indent after curly braces in Vim

How do I make vi-Vim never use tabs (converting spaces to tabs, bad!), makes the tab key == 4 spaces, and automatically indent code after curly brace blocks like Emacs does? Also, how do I save these settings so I never have to input them…
mmcdole
  • 86,293
  • 60
  • 181
  • 221
1318
votes
24 answers

Turning off auto indent when pasting text into vim

I am making the effort to learn Vim. When I paste code into my document from the clipboard, I get extra spaces at the start of each new line: line line line I know you can turn off auto indent but I can't get it to work because I have some…
Rimian
  • 32,654
  • 13
  • 106
  • 109
1155
votes
15 answers

Convert tabs to spaces in Notepad++

How do I convert tabs to spaces in Notepad++? I found a webpage that suggests it's possible, but I couldn't find any information about how to do it. I would like to be able to do that, because some web forms don't respect code with tabs in them.
Helephant
  • 15,502
  • 7
  • 37
  • 35
938
votes
34 answers

How do you auto format code in Visual Studio?

I know Visual Studio can auto format to make my methods and loops indented properly, but I cannot find the setting.
user719550
  • 9,399
  • 3
  • 13
  • 7
668
votes
33 answers

IndentationError: unindent does not match any outer indentation level

When I compile the Python code below, I get IndentationError: unindent does not match any outer indentation level import sys def Factorial(n): # Return factorial result = 1 for i in range (1,n): result = result * i print…
cbrulak
  • 14,071
  • 19
  • 56
  • 96
662
votes
16 answers

How do I fix the indentation of an entire file in Vi?

In Vim, what is the command to correct the indentation of all the lines? Often times I'll copy and paste code into a remote terminal and have the whole thing messed up. I want to fix this in one fell swoop.
mmcdole
  • 86,293
  • 60
  • 181
  • 221
525
votes
6 answers

How do I force Sublime Text to indent two spaces per tab?

Is there a way to force Sublime Text 2 to always indent two spaces per tab when working with Ruby files? I know that indentation can be set under the view -> indentation menu option, but it does not stick. Every time I open a new file and hit tab,…
Mohamad
  • 32,727
  • 31
  • 131
  • 208
404
votes
11 answers

Changing Vim indentation behavior by file type

Could someone explain to me in simple terms the easiest way to change the indentation behavior of Vim based on the file type? For instance, if I open a Python file it should indent with 2 spaces, but if I open a Powershell script it should use 4…
EBGreen
  • 33,707
  • 11
  • 58
  • 80
233
votes
10 answers

How to fix/convert space indentation in Sublime Text?

Example: If I have a document with 2 space indentation, and I want it to have 4 space indentation, how do I automatically convert it by using the Sublime Text editor?
Magne
  • 14,749
  • 8
  • 57
  • 77
222
votes
11 answers

JavaScript error (Uncaught SyntaxError: Unexpected end of input)

I have some JavaScript code that works in FireFox but not in Chrome or IE. In the Chrome JS Console I get the follow error: "Uncaught SyntaxError: Unexpected end of input". The JavaScript code I am using is: