How do I increase or decrease indentation while staying in insert mode?
Answer
<C-t> and <C-d> in insert mode
Explanation
When typing in insert mode, you can adjust the current line's indentation without leaving to normal mode. <C-t> adds one level of indentation and <C-d> removes one level, both respecting your shiftwidth setting. This keeps your flow uninterrupted when writing code that needs indentation adjustments.
How it works
<C-t>— insert oneshiftwidthof indentation at the beginning of the current line (mnemonic: tab in)<C-d>— remove oneshiftwidthof indentation from the beginning of the current line (mnemonic: de-indent)- Both operate on the current line regardless of cursor position within the line
- They respect
shiftwidth,tabstop, andexpandtabsettings
Example
While typing inside a function body and you realize the line needs less indentation:
def foo():
return True| <- cursor here, too much indentation
Press <C-d> to remove one indentation level:
def foo():
return True| <- one shiftwidth removed
Or press <C-t> to add indentation for a nested block:
if condition:
| <- cursor here, press <C-t>
| <- now indented one more level
Tips
0<C-d>removes all indentation from the current line (jumps to column 1)^<C-d>removes all indentation temporarily — the next line you open will restore the original indent level- These are faster than
<Esc>>>Aor<Esc><<Afor quick adjustments during typing - Works with both tabs and spaces depending on your
expandtabsetting