Cursor Language Switcher
Automatically switches the document language mode based on cursor position. Move the cursor into a <script>, <style>, Razor block, or similar region and get the right syntax highlighting and language features (IntelliSense, Find References, etc.) for that fragment.
Works with HTML, Vue, Razor (.cshtml), Blade, Svelte, PHP, and other mixed-content files.
Features
- No manual switching — place the cursor in a block and the editor language updates.
- Script & style — respects
lang attributes: <script lang="ts"> → TypeScript, <style lang="scss"> → SCSS.
- Razor / .cshtml —
@{ }, @code { }, @functions { } switch to ASP.NET Core Razor or C# (configurable).
- Templates —
<template>...</template> is treated as HTML.
- Configurable — enable/disable, debounce, file types, fallback language, and Razor block language.
Supported blocks
| Block |
Language |
<script>, <script lang="ts">, lang="jsx" / tsx |
JavaScript, TypeScript, JSX, TSX |
<style>, <style lang="scss">, lang="sass" / less |
CSS, SCSS, Sass, Less |
<template>...</template> |
HTML |
@{ }, @code { }, @functions { } (Razor) |
aspnetcorerazor / razor / csharp (configurable) |
| Outside any block |
Fallback (document language or custom) |
Configuration
Search for Cursor Language Switcher in Settings (Ctrl+,).
| Setting |
Default |
Description |
| Enabled |
true |
Turn automatic language switching on or off. |
| Debounce (ms) |
100 |
Delay before switching after cursor move (0–500). |
| File languages |
["html", "vue", "razor", "blade", "svelte", "php"] |
Only run in these document types. Empty = all. |
| Fallback language |
document |
Language when cursor is outside any block. Use document for the file’s original language, or set e.g. html, plaintext. |
| Razor blocks language |
aspnetcorerazor |
Language for @{ } / @code { } / @functions { }: aspnetcorerazor (C# features, Find References), razor (Razor coloring), or csharp. |
| Log to Output |
false |
Log each language switch to the Output channel. |
Usage
- Open a mixed-content file (e.g.
.html, .vue, .cshtml).
- Move the cursor into a
<script>, <style>, Razor block, or template.
- The status bar language and editor behavior (syntax, IntelliSense) update to match that region.
- Move the cursor outside blocks to use the fallback language (e.g. HTML for the rest of the file).
Requirements
- VS Code or Cursor
^1.80.0
License
See LICENSE in the repository.
| |