A comprehensive VS Code extension that provides syntax highlighting, formatting and code folding for Slim and Trim templates.
- HTML Elements: Proper highlighting for all HTML tags
- Attributes: Support for ID (#) and class (.) selectors
- Ruby Code: Embedded Ruby code with proper syntax highlighting
- Comments: Support for both single line and block comments
- Text Content: Proper highlighting for text content with pipe (|) syntax
- Doctype: Special highlighting for doctype declarations
- Auto-indentation: Automatic indentation based on Slim structure
- Configurable indentation: Support for both spaces and tabs
- Format on Save: Option to automatically format files when saving
- Range Formatting: Format specific sections of code
- On-type Formatting: Auto-indent when pressing Enter
- Intelligent Folding: Automatic folding ranges based on content structure
- Block-based Folding: Folds blocks with more than 5 lines by default
- Configurable Threshold: Adjustable minimum line count for folding via settings
- Nested Folding: Supports nested folding ranges for complex templates
- Visual Indicators: Clear fold markers for easy navigation
- Elements with IDs: quickly jump to any element with an ID from an alphabetical list
- Blocks: jump to declarations of non-Slim blocks (CSS, Javascript, etc.)
- Real-time Error Detection: Shows syntax errors and warnings as you type
- Configurable Rules: Enable/disable specific linting rules via settings
- Syntax Validation: Validates tag names, attributes, brackets, and Ruby code
- Indentation Checking: Ensures consistent indentation throughout your templates
- Duplicate ID Detection: Warns about duplicate IDs within the same document
- Ruby Syntax Validation: Basic validation of embedded Ruby code syntax
- Smart Block Detection: Automatically skips linting for non-Slim blocks (CSS, JavaScript, SCSS, Ruby, comments)
- Clone this repository
- Run
npm installto install dependencies - Run
npm run compileto build the extension - Press
F5in VS Code to launch the extension in a new window
- Build the extension:
npm run compile - Package the extension:
vsce package - Install the generated
.vsixfile in VS Code
The extension has multiple settings that can be changed:
slim.indentSize: Number of spaces for indentation (default: 2)slim.useTab: Use tabs instead of spaces (default: false)slim.formatOnSave: Format files automatically on save (default: false)slim.codeFoldingDepth: Minimum number of lines that can be folded (default: 2)slim.preserveNonSlimIndentation: Preserve non-Slim indentation when formatting (default: true)slim.outlineSortAlphabetically: Sort outline items alphabetically by id#tag (default: true)
slim.linting.enabled: Enable/disable Slim template linting (default: true)slim.linting.validateSyntax: Validate basic Slim syntax (tags, attributes, brackets) (default: true)slim.linting.validateIndentation: Validate indentation consistency (default: true)slim.linting.validateRuby: Validate embedded Ruby code syntax (default: true)slim.linting.validateIds: Check for duplicate IDs in the document (default: true)slim.linting.warnEmptyTags: Show warnings for empty tags with only selectors (default: false)
Format Document(Shift+Alt+F): Format the entire documentFormat Selection(Ctrl+K Ctrl+F): Format selected text- Auto-format on save (if enabled)
Folding Behavior:
- Adjust the threshold via
slim.codeFoldingDepthsetting
.slimfiles.trimfiles
- VS Code 1.60.0 or higher
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
(c) David Kelly 2025
MIT License - see LICENSE file for details.




