---
title: "Indentation"
url: "https://courses.osherove.com/courses/vim-hates-you/indentation.md"
canonical: "https://courses.osherove.com/courses/vim-hates-you/indentation/"
tags: []
author: "Roy Osherove"
description: "Lesson 6 of 26 in Vim Hates You (Get Somewhat productive in an hour or so), 3:31. Free video by Roy Osherove."
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Indentation

1. [Courses](https://courses.osherove.com/#courses)
2. [Vim Hates You](https://courses.osherove.com/courses/vim-hates-you/)
3. Get Somewhat productive in an hour or so

Lesson 6 of 26

Duration: 3:31 [Watch on YouTube](https://www.youtube.com/watch?v=wvmGAA7xN1o)

## In this lesson

Roy indents lines of an HTML file by selecting them with Shift-V and pressing the greater-than sign, de-indents them with the less-than sign, and repeats the last action with the dot key. For automatic indentation he adds filetype indent on to the vimrc file, so that pressing = on a selection makes Vim detect HTML and indent it. He notes that the indentation settings can be overridden in a special vim directory.

## Transcript

510 words

[\[00:07\]](https://www.youtube.com/watch?v=wvmGAA7xN1o&t=7s) Okay, we still want to get a bit more productive with the HTML for example. So the indentation kind of sucks. So one way to do indentation in Vim is to select the rows you want to indent. So shift V in this case. Let's say all the style and then press shift and the right arrow or the dot. So like this shift and then kind of the larger than sign. And if you want to repeat the command, you can you can actually press dot with nothing and the last thing you did will be repeated again.

[\[00:40\]](https://www.youtube.com/watch?v=wvmGAA7xN1o&t=40s) So if I press dot again, you can see that this is repeated. I'm going to press undo once and undo twice. And then if I want to select stuff inside the style, I say I'll say shift V again, select these rows and then shift larger than and then I get the following. And if I want to indent everything inside HTML, I can select this stuff and press shift larger than again. And I want to indent just the body. I can select stuff here and indent, etc., etc.

[\[01:13\]](https://www.youtube.com/watch?v=wvmGAA7xN1o&t=73s) So, that's one way to indent things. But I also like to be able to get Vim's help to do all these things. So, I'm going to if I want to de-indent, I can select everything. So, shift V and then GG to go all the way to the beginning of the file and then shift smaller than. So, and I can just repeat this again with a dot. So, let me try this. Shift V then shift G and then unindent and then dot to repeat unindent.

[\[01:48\]](https://www.youtube.com/watch?v=wvmGAA7xN1o&t=108s) You can see that this has just repeated the de-indentation of everything. Now there is an auto indentation in Vim. So I can select everything and ideally if I press equals Vim should just detect how to indent HTML. But I don't have indentation turned on and detection in Vim. For that I'm going to have to save the file and then edit the vimrc file. So e home

[\[02:20\]](https://www.youtube.com/watch?v=wvmGAA7xN1o&t=140s) Dot vimrc file. And here I need to add one command which is file type indent on this this basically tells Vim to start detecting which file types I'm loading not just for syntax but also for indentation. And if I close Vim write q so right quit and then I in open index html again it doesn't indent automatically.

[\[02:55\]](https://www.youtube.com/watch?v=wvmGAA7xN1o&t=175s) I still have to tell it to indent. So I'm going to say shiftv and then shiftg to go all the way down to the file. Now if I press equals, vim detects that this is the HTML and indents things for me. And I can change how it indents things because all of my indentation information can actually be overridden in a special directory which is called the vim directory. We're going to use that for a bit very very soon. So that's how we fix indentation. Let's look at color schemes and other bunch of other useful configuration in the next

[Previous lesson Basic Searching inside a file in VIM](https://courses.osherove.com/courses/vim-hates-you/basic-searching-inside-a-file-in-vim/) [Next lesson Understanding Vim Modes and Block Selection Magic](https://courses.osherove.com/courses/vim-hates-you/understanding-vim-modes-and-block-selection-magic/)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
