---
title: "Indentation And Format Code In Vim"
date: 2020-11-12T09:48:11.000Z
author: Z.SHINCHVEN
tags: [VIM, indent code, format code, editor]
canonical: https://atlassc.net/2020/11/12/indentation-and-format-code-in-vim
---
## indentation

### basics

press `v` to enter selection mode, then...

#### indent

- indent by default configuration: `>`
- indent 4 spaces: `4` `>`

#### unindent

- unindent by default configuration: `<`
- unindent 4 spaces: `4` `<`

### indent selected lines

- use `v` command to enter select mode, select lines you want to indent
- indent selected lines: `j` `j` `>`

`v` `j` `j` `>`

### indent particular lines

Example is set to 5 lines

`5` `>` `>`

### references

- [indent-multiple-lines-quickly-in-vi](https://stackoverflow.com/questions/235839/indent-multiple-lines-quickly-in-vi)

## format code

### configure indent size

add configurations to `~/.vimrc`

```conf
:set shiftwidth=2
:set autoindent
:set smartindent
:set tabstop=2
```

### command

`g` `g` `=` `G`

### references

- [how-can-i-change-the-indent-size](https://vi.stackexchange.com/questions/7975/how-can-i-change-the-indent-size)
