Keyboard shortcut to decrease indent: A practical guide for editors

A comprehensive, editor-ready guide on dedenting code with keyboard shortcuts across popular IDEs, with editor-specific tips, step-by-step workflows, and practical examples. Learn how to apply the keyboard shortcut to decrease indent efficiently for faster code formatting.

Shortcuts Lib
Shortcuts Lib Team
·5 min read
Dedent Shortcuts - Shortcuts Lib
Photo by StockSnapvia Pixabay
Quick AnswerDefinition

The keyboard shortcut to decrease indent is typically Shift+Tab on Windows and macOS across many editors. In Vim, use << in Normal or Visual mode to dedent. JetBrains IDEs and Sublime Text often follow the same Shift+Tab convention, though you can customize keymaps in preferences. This quick action helps you clean up blocks of code without moving your hands away from the keyboard.

What indentation is and why dedent matters

Indentation defines structure and readability in code. The keyboard shortcut to decrease indent reduces the leading whitespace on the selected lines, effectively moving code closer to the left margin and clarifying nested blocks. According to Shortcuts Lib, standardized dedent behavior across editors accelerates formatting work without shifting your hands from the home row. When used consistently, it also helps collaborators quickly scan and understand control flow. This section demonstrates both the concept and a simple, programmatic way to visualize dedentation using Python's textwrap, which mirrors what visual editors do with a keystroke.

Python
# Before dedent code = "def f():\n if True:\n return 1\n" print(code) # After dedent (programmatic equivalent of a dedent shortcut) import textwrap print(textwrap.dedent(code)) # removes common leading spaces
  • The input shows nested blocks with spaces for indentation. The output demonstrates how a single command (keyboard shortcut or programmatic equivalent) reduces indentation levels.
  • In practice, editors use your tab width setting to determine how much a dedent moves lines. If your project uses spaces, ensure consistent spacing to avoid misalignment.

Common variations include dedenting by one level in Python or JavaScript, or removing a block of indentation in languages where whitespace is significant. This can be especially helpful when you refactor nested blocks or reflow code during rapid debugging.

wordCountInSection":null} ,{

textBlocks:missing

wordCountInSection":null} ],

prerequisites_placeholder

wordCountInSection":null}],

prerequisites_fake

wordCountInSection":null}]},

prerequisites_placeholder2

wordCountInSection":null}]

blockDataIDError

wordCountInSection":null}

mainTopicQuery

indentation

Steps

Estimated time: 25-45 minutes

  1. 1

    Identify target block

    Select the lines you want to dedent. Ensure the block is the same logical level to avoid breaking code semantics in languages like Python where indentation controls blocks.

    Tip: If unsure, start with a single line to confirm how the editor moves the text.
  2. 2

    Apply the dedent shortcut

    Press Shift+Tab on Windows or macOS to reduce indentation by one level. In Vim, switch to Visual mode and press << to dedent the selected block, or use << to dedent the current line in Normal mode.

    Tip: Consistent tab width makes dedent predictable across editors.
  3. 3

    Check alignment

    Review the affected lines for alignment with surrounding blocks. Ensure there are no mixed tabs and spaces that could mislead readers or break syntax in languages with whitespace significance.

    Tip: Paste without formatting to avoid introducing unwanted whitespace.
  4. 4

    Save and compare

    Save the file and compare the before/after view in a side-by-side diff to confirm the dedent result.

    Tip: Enable editor warnings for syntax errors to catch indentation-related mistakes early.
  5. 5

    Handle multi-file changes

    If you dedent across multiple files, apply the same tab width and ensure consistency with the project’s style guide.

    Tip: Run a quick linter or formatter (e.g., Prettier, Black) after dedenting.
  6. 6

    Customize if needed

    If Shift+Tab isn’t performing as expected, rebind the shortcut in your editor’s keymap or preferences to ensure reliable dedenting.

    Tip: Document your keymap changes for teammates.
Pro Tip: Use a consistent indentation standard (spaces vs tabs) across the project to avoid misalignment when dedenting.
Warning: Be cautious in languages where indentation marks code blocks (e.g., Python). Dedenting incorrectly can alter behavior.
Note: If your editor uses a conflict with a global OS shortcut, customize the key binding to avoid clashes.

Prerequisites

Required

  • Required
  • Shift+Tab or equivalent dedent shortcut configured in editor
    Required
  • Basic keyboard familiarity (arrow keys, home/end, etc.)
    Required
  • Operating system with standard keyboard layout (Windows/macOS/Linux)
    Required

Optional

  • Optional: Vim or other terminal editors for cross-environment workflows
    Optional

Keyboard Shortcuts

ActionShortcut
Decrease indentation (dedent)Applies to most editors by default+

Questions & Answers

What is indentation, and why is dedenting important?

Indentation defines code structure and readability. Dedenting reduces leading whitespace to move blocks left, clarifying scope. Consistent dedent behavior across editors speeds up formatting.

Indentation shows code structure; dedenting moves blocks left for clarity. It’s faster when the shortcut is consistent across editors.

Does the dedent shortcut work on all editors?

Most modern editors map dedent to Shift+Tab, but some may differ. Always check your editor’s keymap settings if Shift+Tab isn’t working as expected.

Most editors use Shift+Tab to dedent, but some apps let you customize the shortcut.

How do I dedent in Vim or Vi?

In Vim, you can dedent a block by using Visual mode and pressing < to shift left, or using << to unindent the current line. For a whole block, make a visual selection and press <<.

In Vim, select the text and press < to dedent, or << for the current line.

What about tabs vs spaces when dedenting?

Prefer a project-wide standard (spaces or tabs). If using spaces, ensure your editor uses the correct tab width to maintain alignment after dedenting.

Use a consistent indentation method and a fixed tab width to avoid misalignment.

Can I customize the dedent shortcut?

Yes. Most editors allow rebinding the dedent action in the keymap or preferences. After changing, test with a small block to confirm behavior.

You can customize the dedent shortcut in your editor’s settings.

Main Points

  • Shift+Tab dedents in most editors
  • Vim uses << to dedent in Visual/Normal mode
  • Verify tab width and indentation style across files
  • Customize keymaps to ensure consistent productivity

Related Articles