How do I re-indent a block of code to match the surrounding indentation?
=i{ or =ap
The = operator performs smart indentation based on Vim's filetype-aware indent rules.
=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.