How to Manually Indent in Vim
This guide walks through how to manually indent lines inside of Vim.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In the last guide we talked about how we can implement auto indentation inside of vim but we now need to actually walk through how we could manually do it. Because there's gonna be times where say that we pull down a piece of code, such as I have our package json file right here. There could be times when we're gonna get things that are not properly indented and we need to be able to do that manually.

So let's come down to this version number right here, and let's imagine that it needs to move over and be indented one time. What we can do is, the command we're going to run is I'm gonna put it right here just so you can see it. We're gonna type Shift and then give two greater-than >> brackets and that's gonna move it and indent it once to the right.

So if you switch back in command mode, you can do it. The cool thing is you can do this from anywhere, so yeah, I can do it right here and that works. But let's say that I'm in the middle of a line I can also do it right here and it does the exact same thing. That's something I find very nice and helpful 'cause I don't have to actually return to the very beginning of the line in order to perform indentation the way I would have to do with some of the other options out there.

large

Now that's nice for one line but there are many times where you need to do this on multiple lines. So let's pretend that all of these lines had to move down so all of the ones in this dependency list. The way we can do that is by switching into visual mode, so if I do Shift + V that's gonna take me into visual line mode and now I can use my J character to come all the way down, pull all of these. And then if I type the double less-than, so Shift, less-than twice then it's going to take me there and bring all of them back. And in fact, I actually only have to press it once when you're in that mode.

Now if I do this again so if I press that again it's only gonna take me that once, it's not going to do it for all of the lines. So if you want to do this multiple times so let me hit Shift + V come all the way down and select everything. And if I wanna go to the right then I can do Shift and the greater-than angle brackets. And then if I want to continue doing it I just press the period after that.

large

large

So I'm gonna do it once, then period and right here I'm just hitting period over and over and over again. Now if I want to take it back, same exact thing, if I do Shift all the way down I'm gonna do Shift + V then in order to go back I'll do Shift, the less-than symbol, just once and then I'll press the period to repeat that action. Remember, anytime I type the period it is going to repeat whatever the last action was, and that's very helpful when working with the visual line mode just like this.