Questions tagged [indentation]

Prefixing lines with whitespace to aid in readability.

Filter by
Sorted by
Tagged with
107
votes
5answers
107k 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.
55
votes
6answers
48k 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. ...
51
votes
1answer
30k 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 ...
45
votes
2answers
8k 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 ...
42
votes
7answers
14k 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 ...
42
votes
1answer
30k 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 ...
41
votes
4answers
11k 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 ...
39
votes
4answers
49k 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 ...
33
votes
2answers
39k 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 ...
32
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 ...
18
votes
3answers
17k 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 ...
16
votes
3answers
1k 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 ...
16
votes
1answer
842 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....
13
votes
1answer
1k 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, ...
12
votes
1answer
818 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
609 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
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 ...
10
votes
1answer
5k 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 $ vim ...
10
votes
1answer
174 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
614 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
6answers
6k 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, ...
9
votes
2answers
422 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
3answers
1k views

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: { ...
9
votes
2answers
1k 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: ...
9
votes
1answer
398 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
1answer
657 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
3answers
483 views

Is it possible to get the rule (cinoptions) that govern the indentation for a specific line in vim

I have the following code: namespace { template<typename T> struct One // This is the odd line { // impl details } template<typename T> struct Two { // impl details } }...
8
votes
1answer
190 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
3answers
950 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 "...
8
votes
1answer
545 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
2answers
5k 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
758 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
1answer
404 views

How to visually select based on indentation?

If someone is editing the following javascript file: let foo = true if (foo) { let bar = 42 // moooooore code... } You can use vi{ anywhere on the line with let bar to select let bar = 42 and ...
7
votes
1answer
471 views

Automatically apply indentation using spaces or tabs

I often edit different files in vim, some of which use tabs, and some and different amounts of spaces. With this, I have not found a combination of set expandtab, set shiftwidth, set softtabstop, and ...
6
votes
2answers
791 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() ...
6
votes
3answers
9k 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? ...
6
votes
1answer
798 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
295 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
370 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
2answers
1k views

How do I jump to the next line with the same indent level?

I have a space formatted (yaml) file like the following: en: templates: template: "VERYLONGTEXTHEREWITHHUNDREDSOFLINES" destination: "I want to jump here" other: stuff ...
6
votes
1answer
238 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 ...
6
votes
1answer
522 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 ...
6
votes
2answers
3k 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 ...
6
votes
1answer
5k views

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. ...
6
votes
1answer
367 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
1k 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
646 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).
6
votes
0answers
968 views

What is the best practice in vim8 for wrapping with indentation aka breakindent

To have proper paragraph wrapping with indentation in vim (after vim7.4) we could use this: " Wrap the text with identation isntead of the old way set breakindent set showbreak=\ \\_ Since vim8 ...
5
votes
1answer
454 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
719 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){ ...

1
2 3 4 5
7