Questions tagged [indentation]
For questions about prefixing lines with whitespace to aid in readability.
401
questions
135
votes
5
answers
166k
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.
78
votes
2
answers
95k
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 ...
77
votes
1
answer
49k
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 ...
70
votes
6
answers
73k
views
How to add indentation guides/lines?
In Sublime Text 2, you get vertical guides where your indentation is, like this:
but Vim doesn't:
Is there a way to show lines like that in Vim?
By the way, my indentation is 2 spaces.
:set tabstop=...
66
votes
5
answers
112k
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 ...
57
votes
1
answer
53k
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 ...
55
votes
2
answers
13k
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 ...
46
votes
7
answers
18k
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 ...
45
votes
4
answers
17k
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 ...
35
votes
8
answers
4k
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 ...
25
votes
3
answers
33k
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 ...
21
votes
3
answers
3k
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 ...
17
votes
1
answer
2k
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....
14
votes
1
answer
2k
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 ...
14
votes
1
answer
10k
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
...
13
votes
1
answer
2k
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, ...
13
votes
4
answers
21k
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? ...
13
votes
2
answers
1k
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 ...
12
votes
7
answers
13k
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, ...
12
votes
2
answers
2k
views
Why does vim still auto-indent LaTeX after I set noai noci nosi?
I want to disable autoindent and smartindent for LaTeX so I did
:set noai noci nosi
When I open a brand new mwe.tex, filetype=plaintex and there is no auto indent magic.
When I then enter some code,...
12
votes
1
answer
828
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
1
answer
675
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 ...
11
votes
2
answers
2k
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:
...
10
votes
2
answers
7k
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
1
answer
437
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 ...
10
votes
1
answer
193
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
1
answer
647
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 ...
10
votes
3
answers
2k
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 "...
9
votes
3
answers
10k
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 ...
9
votes
2
answers
640
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
2
answers
3k
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
...
9
votes
3
answers
2k
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
1
answer
1k
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.
...
9
votes
1
answer
695
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 ...
8
votes
2
answers
2k
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() ...
8
votes
2
answers
544
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 ...
8
votes
3
answers
923
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
2
answers
4k
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 ...
8
votes
1
answer
205
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
1
answer
626
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
4
answers
819
views
Vim plugin where the first lines in the editor show the first line(s) with less indendation that are not visible
I would like to either find or write a plugin that does the following:
Assume I have this python code:
def foo(a,b,c):
# comment
[100 lines that do stuff]
for i in range(N):
[100 ...
7
votes
1
answer
1k
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 ...
7
votes
1
answer
1k
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 ...
7
votes
1
answer
568
views
Why does the "rst" filetype automatically indent subsequent list items?
I've been having trouble understanding the behavior defined in GetRSTIndent() in indent/rst.vim. I'm specifically using Neovim v0.2.2, but I believe this file has not changed between Vim/Neovim.
...
7
votes
1
answer
2k
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 ...
7
votes
0
answers
775
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
1
answer
904
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
6
votes
3
answers
4k
views
Paste word on new line with indentation from current line
Using ]p in normal mode, I can paste a yanked line of text on a new line below the cursor with indentation equal to the current line.
Using the :put command, I can paste a yanked word as if it were a ...
6
votes
1
answer
4k
views
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:
...
6
votes
2
answers
566
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 ...