Custom Prettier WidthFormat a selected range with Prettier using a What it doesThe extension resolves Prettier from the current workspace first, then uses
the bundled Prettier dependency as a fallback. It loads the project's normal
configuration (including parser, plugins, and style options) and overrides
only Usage
The accepted range is 20–500. The last entered value is remembered by default. The edit is applied through the VS Code editor API, so it supports undo/redo and keeps the document's normal dirty-state behavior. Keyboard shortcuts
The shortcut is active only when an editor has focus and a non-empty selection exists. Command PaletteRun Prettier: Format Selection with Custom Print Width. Configuration
RequirementsPrettier must be installed locally in the workspace (recommended):
If no workspace installation is available, the extension uses its bundled
Prettier fallback. Project configuration files such as Supported examples include JavaScript, TypeScript, JSX, TSX, JSON, JSONC, CSS, SCSS, Less, HTML, Markdown, and YAML, subject to the installed Prettier version and plugins. Important behaviorPrettier's range formatting is syntax-aware. It may expand the selected range to an enclosing syntactic structure to produce valid output; the extension does not promise that only the literal selected characters will change. Only the resulting changed text span is sent to VS Code as one edit, and a parsing or formatting error leaves the document unchanged. Example: JavaScript/TypeScriptInput:
With
Example: JSONA selected long object is wrapped according to the chosen width while the project's quote, indentation, and trailing-comma settings remain in effect. Development and publishingInstall dependencies:
Compile:
Test:
Create the VSIX:
Install the local VSIX:
The repository metadata is configured for
Authenticate and publish without placing credentials in the project:
|