Code and Config Files
Slate is a capable editor for source code and configuration files, not only Markdown. Open a file and the plain-text view highlights it in its language, the outline maps its structure, and the sidebar and search treat it like any other document.
A general text editor
Slate is not only for Markdown. Open any text file and it edits in the plain-text view, built on CodeMirror 6. For a non-Markdown file this is the whole editor. The WYSIWYG, Reading, and split modes are Markdown-only, so the view switcher does not appear.
Everything else about the editor stays the same. You still get the sidebar, tabs, search, the outline, and the command palette, working exactly as they do for a Markdown document.
Syntax highlighting
The plain-text editor highlights the open file in its language. It covers well over a hundred languages, including JavaScript, TypeScript, Python, Rust, Go, Ruby, Java, C, C++, HTML, CSS, JSON, YAML, TOML, SQL, and Bash. The language is picked from the file extension, so opening a .py file gives you Python highlighting without any setup.
When a file has no extension, or its extension does not match the language, you can override the choice for the current document with the /lang command from the command palette. Open a file with no extension, or a .txt log, and run /lang with a language, for example /lang python, to highlight it as that language. /lang auto restores the choice based on the extension. The override applies to the current document and lasts for the session.
Soft wrap
Soft wrap folds long lines to the width of the editor instead of letting them run off the right edge. By default prose wraps and code does not. A Markdown or plain-text file wraps so paragraphs stay readable, while a source or config file keeps each line intact and scrolls sideways, which is usually what you want for code.
To flip wrapping for just the file you are in, run /wrap from the command palette or press ⌥Z⌥Zsoft wrap. That override applies to the current document for the session and does not change your saved defaults.
To change the defaults, open Settings and choose Editor. Three controls live there:
- Wrap long lines. The global default. On by default.
- Do not wrap code files. Keeps code and other non-prose languages on single long lines even when wrapping is on. On by default, which is what makes prose wrap while code does not. Markdown and plain text always count as prose.
- Per-language exceptions. Pick a language and force wrap on or off for it, overriding both settings above. The list starts empty. Add, for example, YAML set to wrap, or Markdown set to never wrap.
Supported file types
Slate opens and edits Markdown, plain text, and a broad set of source and config formats. Here are representative extensions in each group.
Markdown
.md, .markdown, .mdown, and .mkd.
Plain text
.txt and .text.
Source code
.js, .mjs, .cjs, .jsx, .ts, .tsx, .py, .rb, .rs, .go, .java, .kt, .c, .h, .cpp, .cs, .php, .swift, .lua, and .sh.
Data and config
.json, .jsonc, .yaml, .yml, .toml, .ini, .env, .csv, .tsv, and .xml.
Web
.html, .css, .scss, and .less.
Images
Images such as .png, .jpg, .gif, .webp, .svg, and more open in a read-only image viewer.
Everything else
Binary files such as PDFs, Word documents, and archives show in the file tree but cannot be opened in Slate.
The code symbol outline
For source files, the outline panel can list the file's structure instead of headings. Right now the symbol outline supports the JavaScript and TypeScript family only:
- JavaScript (
.js,.jsx,.mjs,.cjs) - TypeScript (
.ts) - TSX (
.tsx)
For these files the outline lists the file's classes, functions, and other top-level symbols, and clicking one jumps straight to it. For every other file type the outline simply has nothing to show.
Finding in code
The plain-text view has the same find bar as everywhere else in Slate. Open it with ⌘FCtrlFfind and search the current file. The bar supports case sensitivity, regular expressions, and stepping through matches with find next and find previous.
This is the same find described on the Editing and Formatting page.
How code files differ from Markdown
A code or text file is simpler than a Markdown document in a few specific ways, and identical in the rest.
- There is one view: plain-text. The WYSIWYG and Reading views, the split preview, reading-mode zoom, and typography themes apply only to Markdown documents.
- The outline shows symbols for JavaScript and TypeScript files rather than headings.
- Everything else works identically: the sidebar, tabs, search, saving, autosave, and the color mode of your theme.
Because the Markdown views follow the document's effective language, /lang markdown switches a file into Markdown and gives it the WYSIWYG and Reading views, and switching it to a code language with /lang returns it to the single plain-text view.