Questions tagged [indentation]

Prefixing lines with whitespace to aid in readability.

Filter by
Sorted by
Tagged with
86
votes
5answers
72k views

How to replace tabs with spaces?

Is it possible to convert tabs to spaces, while maintaining text alignment? Simply replacing only works usefully when there are no leading characters.
43
votes
5answers
34k views

How to add indentation guides/lines

In Sublime Text 2, you get vertical guides where your indentation is, like this: but in vim I obviously don't: Is there a way to show lines like that in vim? By the way, my indentation is 2 spaces. ...
40
votes
2answers
5k views

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 ...
39
votes
7answers
9k views

Re-indenting badly indented code

I like the smart-indent feature of Vim, it allows me to create well-indented code blocks. I regularly copy/paste code in to buffers, but that code is often poorly formatted. What would be ideal is ...
39
votes
1answer
21k views

What is the difference between `filetype plugin indent on` and `filetype indent on`?

I see one of these two lines in .vimrc files. This one seems to be most common: filetype plugin indent on But how does it differ from this line: filetype indent on I've found documentation for the ...
36
votes
1answer
20k views

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 ...
34
votes
4answers
8k views

How can I change the default indentation based on filetype?

I'd like to have different indentations based on the type of file I am working on. For example, working on a .c file I'd like my indentation be 4 spaces. In .html files I'd like to (have to) work with ...
27
votes
8answers
2k views

How do I move vertically until reaching a non-whitespace character?

In a very long file with (accurately-) indented code, it may be helpful to move directly to a line of text above or below the cursor which delimits the indenting. (One way of doing this could be via ...
21
votes
2answers
21k views

How to indent as spaces instead of tab?

I am coding some html templates in JADE files. I want to auto indent code with spaces instead of tab. I tried shiftwidth=2, tabstop=2, but no matter what, it's still indents using tabs instead of ...
20
votes
4answers
24k views

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 ...
16
votes
3answers
779 views

How do you indent > < without leaving visual mode and losing your current selection?

I often have to manually indent, but when I enter a visual mode, select my lines to indent, and press < or >, I leave visual mode whether I want to or not. I would rather have it so I stay in ...
15
votes
3answers
10k views

How can I automatically indent on new lines?

I work on projects with varying levels of indentation. In many of these projects, because of how the files are typically structured, most lines are indented at least two levels (such as methods in ...
14
votes
1answer
442 views

How to move the cursor to the correct indentation level without quiting insert mode?

For example I have this JavaScript code. The | character represents the cursor position and it is on an empty line. function a() { console.log("a"); function b() { console.log("b"); ...
12
votes
1answer
815 views

Why does >3k move the cursor up when >3j does not move it down? [duplicate]

Hitting >3j indents the current line and the three below it, and >3k does the same but with the three lines above. However, when indenting down, my cursor is left on the same line as it started, ...
11
votes
1answer
993 views

Unexplained gq indentation issue

I insert this text in Vim: t tttt ttttttttt tt tttt tt ttt tttttt-tttt-ttttttt tttttttttttttttttttttttttttttttttttttttttttttttttttttt ttttt ttt ttt tttttt ttttttt tttt ttttttt: ttttttt tt ttttttt, ...
11
votes
1answer
543 views

How do I shift the line indent to a specific value?

Many times I run across a situation where a line is not indented properly. Ether through a paste, bad / not preferred indent plugin, or most often extra spaces offsetting the indent value. I usually ...
10
votes
1answer
145 views

How to temporarily make gq consider hyphen (-) a normal word, to not indent the following lines in the same paragraph

I have tried this in a JavaScript file after disabling smartindent and autoindent options, with textwidth = 80, but it is still the same. It also happens automatically because of the textwidth option ...
10
votes
1answer
571 views

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 ...
9
votes
2answers
330 views

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 ...
9
votes
2answers
6k views

vundle “filetype plugin indent on” messes with tabwidth

I installed vundle yesterday and since I did, the tabwidth I configured in my vimrc is ignored and set back to 4 instead of 2. I found out that the following line after the vundle paragraph is ...
9
votes
1answer
340 views

Disabling partial HTML indentation in Vim

Caveat: I'm not a web developer. That being said, there are rare occasions where I have to edit HTML. When I do, I've noticed a behavior in Vim that I don't like, and hope that I can change via ...
9
votes
0answers
485 views

Is there a setting to force a hanging indent on bulleted/numbered lists WITHOUT hard wrapping?

Basically, I'd like to have long entries for bulleted / numbered lists that automatically indent like so: 1. Congress shall make no law respecting an establishment of religion, or prohibiting the ...
8
votes
1answer
180 views

Running cleanup commands only for edited lines possible?

Referring to clean-up tasks like (but not limited to) the ones detailed in these questions: Re-indenting badly indented code What's the simplest way to strip trailing whitespace from all lines in ...
8
votes
1answer
455 views

What controls indentation of lines following an open square bracket when using cindent?

I am trying to build my own indent file for JavaScript. The default indent file for JavaScript turns cindent on, with minimal modifications, and I am using that as a base. On Vim 7.3 for OSX El ...
7
votes
6answers
5k views

How can I copy/paste new text without auto-indentation at every new line?

How I paste now: Right-click/Copy or simply highlight. Right-click/Paste or Middle Click or CTRL+SHFT+V Indents appear at increasing intervals: 0, 2, 4, 6, + Question at hand: From prior research, ...
7
votes
2answers
3k views

Vim doesn't use the correct indentation in Python files

I have encountered something that I have never seen before in Vim. While I was tentatively modifying some of the source code for software I've been planning to work on, I noticed vim was displaying ...
7
votes
1answer
524 views

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. ...
7
votes
2answers
494 views

Shift left or right (with `noet`) without converting existing spaces to tabs

Foreword I'm using the "indent with tabs, align with spaces" ideology for indentation. This means that each line in a file can be prefixed with an arbitrary amount of tabs and spaces (as opposed to "...
6
votes
1answer
615 views

How to show trailing spaces, while leaving tabs as they are?

I like the ability to show trailing whitespaces, so I have this setting. set list listchars=tab:\ \ ,trail:· I never use tabs (although I don't think tabs are bad, it's just a convention), but ...
6
votes
2answers
179 views

Deleting groups of autoindents in Insert mode

In my .vimrc I have set backspace=eol,start, which allows me to backspace over line breaks and the start of what I wrote since I entered Insert mode. This does not allow me to backspace over ...
6
votes
2answers
820 views

How do I prevent Vim from unindenting empty lines?

Vim keeps unindenting the lines I want to keep indented if I don't write anything on them... I'll give an example, where the | is the caret. Caret is indented and I press enter if expression: ...
6
votes
2answers
322 views

How can I shift only inner contents of HTML element?

How can I quickly shift only inner contents of HTML tag X, when they are on separate lines to the opening and closing X tag? Example below: I want to shift only 2 lines with <p> tags when the ...
6
votes
1answer
3k views

Why is “set noexpandtab” in my ~/.vimrc ignored when I open a file? [duplicate]

I'm using Mac OS X 10.12 and I have set noexpandtab in my ~/.vimrc There are 2 different behaviors : $ vim file.py If run Vim (8.0) to open one file and type :set expandtab?, it says expandtab $ ...
6
votes
1answer
305 views

equalprg to use for Python

Python is whitespace dependent, and it can't be totally autoindented for that reason, but there are a lot of extra stuff that should be possible to do automatically to comply with PEP8. Things like ...
6
votes
1answer
974 views

How can I indent JavaScript that's within <script> tags in an HTML file?

If I am viewing a HTML file that someone else wrote, it often has <script> tags containing javascript, e.g. <!DOCTYPE html> <html> <head> </head> <body&...
6
votes
0answers
610 views

Mixed PHP and HTML indenting

Is there a way to have mixed indenting more like Sublime Text (left) than Vim does it? I would like the nested UL to follow the (line 10) to follow along the (main indentation).
5
votes
2answers
531 views

Toggling Tabs and Spaces

I work on different projects that have preferences for tabs and others for spaces. Is there a way to toggle using tabs or spaces for indentation? I tried a function I saw online function TabToggle() ...
5
votes
2answers
615 views

Vim conceal indentation. Replace indentation spaces with utf-8 chars

I use four spaces for indent. I would like to replace the indentation with some UTF-8 chars. What I have: 1. def foo(bar): for jaffa in bar: print jaffa 2. var foo = function(bar){ ...
5
votes
1answer
311 views

Count the number of whitespace in the beginning of a line

How to count the number of whitespace in the beginning of a line ( aka indentation ). eg: foo() foo() And then :command(2) 4
5
votes
2answers
92 views

Can I make the indent commands take an additional count that doesn't affect the motion?

Let's say I'd like to indent the current line 4 times. (Not 4 spaces, 4 indent commands). As far as I can tell, the shortest way to do this is >>... (Indent once, repeat three times) This ...
5
votes
1answer
2k views

Incorrect auto-indent in python code

I have a following python code, which contains both 4 space and 2 space indents. class Foo(object): def __init__(self, flag = False): if flag: print("hello") ...
5
votes
1answer
174 views

Keep beginning of current fold on top of the screen

I've googled around but can't find anything about this. There is a case: when I navigate deep down through large blocks of code in (for example) python, it would be useful to see which method, ...
5
votes
1answer
292 views

Indentation in Latex within a list after an equation

Here is a minimal .tex file: \begin{document} \begin{itemize} \item Here is an equation: \begin{align*} x = y \end{align*} \item Here is another item ...
5
votes
1answer
190 views

Indent Lines Up Without Moving

I frequently use the >8j and >8k commands to indent several lines at once. Using j, the lines are indented and my cursor stays at the first line. When I use k, the lines are indented, but my cursor ...
5
votes
2answers
603 views

Indent a markdown list item?

I am frequently editing markdown files, and when dealing with multi-line items in hierarchical lists, it would be great to have a rapid way to indent or un-indent a list item. For example, how can I ...
5
votes
1answer
227 views

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 ...
5
votes
2answers
2k views

How can I fix the auto indentation in LaTeX?

Vim has some fancy pants indentation stuff. When it works right it's a pleasure to have, but sometimes it just drives me nuts. One that I've never been able to solve has to do with LaTeX syntax. Lets ...
5
votes
1answer
701 views

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 #...
5
votes
1answer
436 views

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 ...
5
votes
2answers
4k views

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? ...