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.
Questions tagged [indentation]
3215 questions
2396
votes
34 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
- 91,574
- 70
- 187
- 238
1484
votes
27 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
- 36,864
- 16
- 117
- 117
1419
votes
12 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
- 91,488
- 60
- 186
- 222
1390
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
- 24,078
- 21
- 82
- 113
1248
votes
12 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
- 16,738
- 8
- 39
- 36
1148
votes
38 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
- 11,507
- 3
- 15
- 7
791
votes
32 answers
IndentationError: unindent does not match any outer indentation level, although the indentation looks correct
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
- 15,436
- 20
- 61
- 101
703
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
- 91,488
- 60
- 186
- 222
615
votes
23 answers
How to indent a few lines in Markdown markup?
I want to write a few lines of text. They should be formatted normally except each line should start at the 6th column. I.e. I don't want the code block formatting rule to make this chunk of text look like code as I'll use other formatting like bold…

Meng Lu
- 13,726
- 12
- 39
- 47
548
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
- 34,731
- 32
- 140
- 219
439
votes
12 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
- 36,735
- 12
- 65
- 85
392
votes
29 answers
"inconsistent use of tabs and spaces in indentation"
I'm trying to create an application in Python 3.2 and I use tabs all the time for indentation, but even the editor changes some of them into spaces and then print out "inconsistent use of tabs and spaces in indentation" when I try to run the…

Julia Lärkert
- 3,961
- 3
- 15
- 3
251
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: