Trim Trailing Whitespace

Transform

Removes trailing whitespace from all lines in the file.

macOS

⌘K⌘X

Windows / Linux

CtrlK CtrlX

Pro Tip

Enable 'Trim Trailing Whitespace' on save in settings.

About This Shortcut

The Trim Trailing Whitespace shortcut belongs to the Transform category of VS Code keyboard shortcuts. Removes trailing whitespace from all lines in the file. Learning and using keyboard shortcuts dramatically improves your coding speed and reduces dependence on the mouse.

VS Code is the most popular code editor with over 70% market share among developers. Its extensive keyboard shortcut system enables experienced users to perform complex operations — from multi-cursor editing to Git operations — entirely from the keyboard. This shortcut is one of the essential shortcuts every developer should memorize for efficient coding workflows.

You can customize this keybinding by opening the Keyboard Shortcuts editor (⌘K ⌘S on macOS). Search for "Trim Trailing Whitespace" to view, change, or add alternative keybindings. VS Code also supports keymap extensions that import shortcut schemes from other editors like Vim, Emacs, Sublime Text, and JetBrains.

Related Shortcuts