Questions tagged [indentation]

For questions about prefixing lines with whitespace to aid in readability.

Indentation of code typically involves using whitespace or tabs to help readability. Vi/Vim have many built in ways to both configure and show indentations to make it an automatic process for the user.

377 questions
66
votes
5 answers

How can I change the indent size?

I just discovered I could indent and un-indent easily in Vi with : << and >> By default it adds a tab character. Now I'm wondering, could this be to a number of spaces via a configuration in my .vimrc? And how should I do it?
J. Chomel
  • 1,106
  • 1
  • 11
  • 20
57
votes
1 answer

What is the difference between autoindent and smartindent in vimrc?

I read the wiki entry on vim source code indentation I still can't understand the difference between autoindent and smartindent It seems they do the same thing, copy the indentation level to next line when you press enter.
Aaron Shen
  • 2,519
  • 3
  • 24
  • 37
55
votes
2 answers

How do I make Vim adapt to the current indenting style of the file I'm editing?

I work on a range of JavaScript projects. In most of these projects, the indentation of JavaScript files is 2 spaces, so I've set my default indentation width to that. However it becomes 1 or 4 in some other projects. Is there a way to ask Vim to…
thameera
  • 17,434
  • 16
  • 40
  • 42
13
votes
4 answers

How can I stop vim automatically inserting a tab in CSS files?

When I am in a CSS file with a blank line, like this: and I want to simply make a new line and move down to it, by hitting Enter , vim is auto inserting a tab character, e.g. Running :set fo? inside the CSS file => formatoptions=croql. If I…
the_velour_fog
  • 3,335
  • 3
  • 22
  • 40
10
votes
1 answer

Incorrectly indents JavaScript chain calls

For example, if I have some JavaScript code like this: var widget = library() .chainCall1() .chainCall2() .chainCall3(); If I use the = command to auto indent it, it comes out looking this this: var widget =…
aharris88
  • 1,847
  • 2
  • 17
  • 22
9
votes
2 answers

Indent to next indentation level with >>

From time to time I have to work with code that isn't indented to the level of indentation I have Vim set up to (4 spaces per level), usually after copy/pasting something in the file. I usually make do with << and >>. The problem is they don't jump…
Dumitru
  • 780
  • 1
  • 7
  • 10
9
votes
3 answers

Vim switch statement cindent options

I want my C code indented as follows: switch (x) { case 1: break; case 2: { break; } } Instead of this: switch (x) { case 1: break; case 2: { break; } } I looked through…
9
votes
1 answer

How to override the '=' command?

I cannot convince vim to apply the coding-style I'd like to (cindent and friends). However, integrating clang-format.py (which uses the .clang-format of my project) actually makes me totally happy. Except that I have the reflex of using the = +…
Patrick B.
  • 559
  • 1
  • 6
  • 16
9
votes
1 answer

Why is line continuation is indented with 12 spaces in vimscript?

let b:some = { \ 'some', \ 'array', } This makes code ugly IMHO, how can I change that and should I change that? Is that some coding style or something in vimscript? Also, is there a plugin that would (I think I had one, but…
user1685095
  • 1,141
  • 11
  • 24
6
votes
1 answer

incorrect auto-indent in bash code

I have bash script which Vim detects as a sh according to :set filetype?. In addition, Vim-script for auto-indention support for shell-scripts(/usr/share/vim/vim74/indent/sh.vim) is also present. However, for example following while loop: while read…
Martin
  • 945
  • 1
  • 9
  • 18
6
votes
2 answers

HTML is not being indented

I have just created a file .html. When I run set filetype? I get filetype=html. Then I select this code:
and press = but the code is not indented... I don't have problems to indent php files for example using the same…
tirenweb
  • 197
  • 3
6
votes
0 answers

Make Vim ignore first character in line while indenting

Whenever I have to edit Perl Mason files, I always have problems indenting lines due to Perl code starting with %. For example:
% if( !$something ) { <% $title %> % }
Any idea how…
André Gil
  • 161
  • 3
6
votes
1 answer

Vim indent using "=" inserts 2 tabs

If I try to indent a code using visual mode or ggVG= vi automatically inserts 2 tabs instead of just 1. for example: // inside main for (int i = 0; i < 10; i++) { test += i; } changes to: for (int i = 0; i < 10; i++) { …
5
votes
1 answer

When moving text to new line, changes indentation for both lines

I am seeing this in Vim 7.3. I have autoindent on. Sometimes, when I move some code to the next line, the indentation of the line it was originally on changes, and then the newly created line is set to match that indentation. I don't mind that the…
still_dreaming_1
  • 747
  • 5
  • 17
5
votes
1 answer

Indentation of preprocessor directives

In my vimrc I have the following line, which figures all the indentation of my files. filetype plugin indent on When writing C programs sometimes I use preprocessor directives like #ifdef foo and #endif. When writing one such directive inside a…
Gonçalo Ribeiro
  • 1,991
  • 1
  • 18
  • 28
1
2 3 4 5 6