Text and code
Any file that reads as text and has no view of its own opens in the text viewer, colored by the language it is written in. Forty-nine languages are known, and the editor colors them the same way as you type.
What the keys do
| Key | For a text or source file |
|---|---|
| Enter | Hands it to the application macOS opens it with |
| F3 | Shows it in the text viewer — unless it is one of the kinds with a view of its own, on the pages beside this one |
| ⇧F3 | Shows it in the text viewer, whatever it is |
| F4 | Opens it in the built-in editor |
A file with no extension whose first line is #! is a script, and is not run by a key unless you set its kind to Run: Enter opens
the context menu of what can be done with it instead. Opening files
says how to change any of this.
Recognized by
The extensions the Text, source and configuration type lists, anything macOS calls plain text or source code, and — whatever the name — a file whose first few kilobytes read as text. Which language it is colored as is below.
At a glance
| Key | Action |
|---|---|
| F2 | Wrap the long lines |
| F5 | Line numbers |
| ⇧F9 | Spaces and tabs |
| F4 | Show the bytes |
| ⌘E | Encoding… |
| Language… | Language… |
| F7 | Search… |
| F6 | Only the lines that match |
| ⌘G | Go to… |
Reading it
The text viewer reads only the part of the file on screen, so a file of any size opens at once. The header gives the language it is colored as, the encoding, how its lines end and which line you are on.
- Moving about, wrapping, line numbers and invisible characters, encodings, big files and files that change as you read: Text and bytes.
- Finding text, showing only the lines that match, going to a line: Searching a file.
- Selecting with the mouse, ⌘A, and copying what is selected: Selecting and copying.
The colors
Keywords, types, strings, comments and numbers each have a color. Coloring is by the language’s own rules, a line at a time — nothing is worked out from what the program means.
The languages are Bash, C, C#, C++, Clojure, CMake, CSS, Dart, Diff, Docker, Elixir, Erlang, Fish, Go, GraphQL, Groovy, Haskell, HTML, INI, Java, JavaScript, JSON, Kotlin, Lua, Makefile, Markdown, Nginx configuration file, Nix, Objective-C, Perl, PHP, PowerShell, properties, Protocol Buffer, Python, R, Ruby, Rust, Scala, SCSS, SQL, Swift, Terraform, TeX, TOML, TypeScript, XML, YAML and Zig.
Which files each language colors
Names are matched whatever their case. Where two languages claim a name, as C and Objective-C both
claim .h, the first alphabetically wins unless one of them ranks higher.
| Language | Files |
|---|---|
| Bash | .sh, .ksh, .bash, .zsh, .ebuild, .eclass, .env, .env., .exheres-0, .exlib, .bashrc, bashrc, .bash_, bash_*, .zshrc, zshrc, APKBUILD, PKGBUILD |
| C | .c, .h, .idc, .xbm, .xpm |
| C# | .cs |
| C++ | .cpp, .hpp, .c++, .h++, .cc, .hh, .cxx, .hxx, .cp, .tpp |
| Clojure | .clj, .edn |
| CMake | .cmake, CMakeLists.txt |
| CSS | .css |
| Dart | .dart |
| Diff | .diff, .patch |
| Docker | Dockerfile, Dockerfile., .Dockerfile, .docker, Containerfile, Containerfile., .Containerfile |
| Elixir | .ex, .eex, .exs |
| Erlang | .erl, .hrl, .es, .escript |
| Fish | .fish, .load |
| Go | .go |
| GraphQL | .graphql, .graphqls |
| Groovy | .groovy, .gradle |
| Haskell | .hs |
| HTML | .html, .htm, .xhtml, .xslt |
| INI | .ini, .cfg, .inf, .service, .socket, .container, .network, .build, .pod, .kube, .volume, .image, .gitconfig, .editorconfig, pylintrc, .pylintrc |
| Java | .java |
| JavaScript | .js, .jsm, .mjs, .cjs |
| JSON | .json, .jsonl, .jsonc, .json5, .avsc, .luaurc |
| Kotlin | .kt, .kts |
| Lua | .lua, .wlua |
| Makefile | .mak, .mk, Makefile, Makefile.*, GNUmakefile, BSDmakefile, Justfile, .justfile |
| Markdown | .md, .markdown, .mdown |
| Nginx configuration file | nginx.conf |
| Nix | .nix |
| Objective-C | .m, .h |
| Perl | .pl, .pm, .t |
| PHP | .php, .php3, .php4, .php5, .inc |
| PowerShell | .ps1, .psm1, .psd1 |
| properties | .properties |
| Protocol Buffer | .proto |
| Python | .py, .pyi, .pyw, .jy, .sage, .sc, .bzl, .star, .tac, SConstruct, SConscript, BUCK, BUILD, BUILD.bazel, WORKSPACE, WORKSPACE.bazel, WORKSPACE.bzlmod, MODULE.bazel, REPO.bazel |
| R | .r, .s, .Rhistory, .Rprofile, .Renviron |
| Ruby | .rb, .rbw, .rake, .gemspec, .rbx, .duby, .gemfile, .json.jbuilder, Rakefile, Gemfile, Vagrantfile, Appraisals, .pryrc |
| Rust | .rs, .rs.in |
| Scala | .scala |
| SCSS | .scss |
| SQL | .sql |
| Swift | .swift |
| Terraform | .tf, .hcl |
| TeX | .tex, .aux, .toc |
| TOML | .toml, Pipfile, poetry.lock, uv.lock |
| TypeScript | .ts, .tsx, .mts, .cts |
| XML | .xml, .xsl, .xslt, .xsd, .wsdl, .wsf, .rss, .svg, .qrc, .csproj, .vcxproj, .fsproj |
| YAML | .yaml, .yml |
| Zig | .zig, .zon |
How the language is chosen
The first of these that names one:
- A file type of your own that sets a language — or sets none.
- The file’s name, from the table above.
- Only when the name says nothing, the start of the file:
- an editor’s mode line:
-*- mode: python -*-in the first line, or the second after a#!line, orvim: ft=pythonin the first five; - the program a
#!line runs, throughenv, with its version left off:#!/usr/bin/env python3.12is Python,#!/usr/bin/env nodeis JavaScript; <?xmlat the start, which is XML.
- an editor’s mode line:
Nothing is guessed from how the text looks: a file with no ending, no #! and no mode line is not
colored.
Choosing another
Language…, in the View menu of the viewer and of the editor, colors the file as any of the languages, or as none. The list shows the files each one claims.
Always color .conf files like this keeps the choice for every file with that ending, as a file type of your own that sets only the language, so every key still does what it did. Choosing again for the same ending replaces it. A file with no ending has nothing to keep it for, so the box is gray.
Editing it
F4 opens the built-in editor, colored by the same rules, and the colors keep up as you type — opening a comment recolors the lines after it at once. What the language adds:
- ⌘/ comments out the line, or every line of the block, with the language’s own marks. Diff has none.
- Brackets are matched, and close as you type.
- ⌥⌘[ folds a block: by brackets, by indentation in Python, YAML and XML, and by headings in Markdown.
- ⌥⌘P lays out JSON and XML, and ⌥⇧⌘P packs them. No other language has them.
All of the editor is in Editing files.
Limits
- Only the first 4,096 characters of a line are colored; the rest of a longer one, such as a minified file, is plain.
- The bytes, and lines kept by a filter, are never colored.
- There is no way to add a language of your own; a file type can only choose one of these.