How do you record a macro to convert 4-space indentation to 2-space?
qa:s/^ / /\njq
Record a macro that substitutes leading 4-space indentation with 2 spaces on each line.
qa:s/^ / /\njq
Record a macro that substitutes leading 4-space indentation with 2 spaces on each line.
]p
The ]p command pastes text and adjusts its indentation to match the current line.
:set autoindent
The autoindent option copies the indentation from the current line when starting a new line.
>
In visual mode, pressing > indents all selected lines by one shiftwidth.
==
The == command auto-indents the current line based on the surrounding context.
> and <
How it works In visual mode, you can shift selected lines to the right or left using the > and to indent them or or shifts the selected lines one shiftwidth to
=i{ or =ap
The = operator performs smart indentation based on Vim's filetype-aware indent rules.
<C-r><C-o>"
The {register} sequence in insert mode pastes register contents literally — without triggering auto-indentation, abbreviations, or mappings.
:set foldmethod=indent
Setting foldmethod=indent tells Vim to create folds based on the indentation level of each line.
vim-sleuth
The vim-sleuth plugin by Tim Pope automatically detects the indentation style (tabs vs spaces) and width used in a file and sets shiftwidth, expandtab, tabstop,
autocmd FileType {lang} setlocal {options}
Vim's autocmd FileType lets you apply settings that only take effect when editing a specific file type.
=
Pressing = in visual mode auto-indents the selected lines according to Vim's built-in indentation rules.
visual-mode #editing #visual-mode #indentation #formatting #productivity
:set tabstop=4 shiftwidth=4 expandtab
The :set tabstop=4 shiftwidth=4 expandtab command configures Vim to use 4-space indentation with spaces instead of tab characters.
>>
The >> command shifts the current line one shiftwidth to the right, adding indentation.
gg=G
The gg=G command re-indents every line in the current file according to Vim's indentation rules.