Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Highlighting

Greed highlights code with tree-sitter. A language’s highlights query gives pieces of the text names like keyword.control.return or markup.heading.1, and the theme gives each name a look. The names are the same in every language, so one theme entry styles keywords everywhere. Files are parsed again in the background after each edit; until that’s done, the highlights from before move along with the text you typed.

A name falls back to its parent when the theme has no entry for it: keyword.control.return uses keyword.control, then keyword. A theme can be as short as the top-level names, or style any of the finer ones.

require("@greed").theme.set({
	keyword = { fg = "magenta" },
	["keyword.control.return"] = { fg = "red", bold = true },
	["markup.heading.1"] = { fg = "blue", bold = true, underline = true },
})

These are the names Greed’s queries and themes use, and the ones to use in queries you write. They’re the names Helix uses, so its queries work as they are. A theme entry can also be set for one kind of client only, with tui and gui parts:

require("@greed").theme.set({
	comment = { fg = "bright-black", gui = { italic = true } },
})

Code

NameFor
attribute#[derive(Debug)], decorators
commentComments
comment.line// ...
comment.line.documentation/// ...
comment.block/* ... */
comment.block.documentation/** ... */
constantConstants
constant.builtinnil, None, self as a value
constant.builtin.booleantrue, false
constant.character'a'
constant.character.escape\n in a string
constant.numericNumbers
constant.numeric.integer42
constant.numeric.float4.2
constructorSome(...), new Foo
functionFunctions
function.builtinprint, len
function.methodx.len()
function.macroprintln!
function.specialPreprocessor functions and the like
keywordKeywords
keyword.controlKeywords that change the flow
keyword.control.conditionalif, else, match
keyword.control.repeatfor, while, loop
keyword.control.importuse, import, require
keyword.control.returnreturn, break, continue
keyword.control.exceptiontry, catch, throw
keyword.directive#include, #!
keyword.functionfn, function, def
keyword.operatorand, or, in
keyword.storagelet, const, static
keyword.storage.typestruct, enum, class
keyword.storage.modifierpub, mut, async
label'outer:, a code block’s language
namespaceModules and packages
operator+, =, ->
punctuationPunctuation
punctuation.bracket( ) [ ] { }
punctuation.delimiter, ; .
punctuation.special${ in strings, Markdown’s >
specialAnything else a query wants to stand out
stringStrings
string.regexpRegular expressions
string.specialDates, symbols and the like
string.special.pathPaths
string.special.urlURLs
string.special.symbol:symbol, atoms
tagHTML and XML tags
tag.builtinHTML’s own tags
typeTypes
type.builtinu8, string, int
type.parameterT in Vec<T>
type.enum.variantEnum variants
variableVariables
variable.builtinself, this
variable.parameterFunction parameters
variable.other.memberFields, properties, keys

Prose

NameFor
markup.headingHeadings
markup.heading.markerThe # of a heading
markup.heading.1A level 1 heading, and so on to markup.heading.6
markup.heading.2
markup.heading.3
markup.heading.4
markup.heading.5
markup.heading.6
markup.listList markers
markup.list.unnumbered-, *
markup.list.numbered1.
markup.list.checked[x]
markup.list.unchecked[ ]
markup.bold**bold**
markup.italic*italic*
markup.strikethrough~~gone~~
markup.linkLinks
markup.link.urlA link’s address
markup.link.label[label] in a reference link
markup.link.textA link’s text
markup.quoteBlock quotes
markup.rawCode
markup.raw.inline`code`
markup.raw.blockCode blocks

Writing queries

Queries are files named queries/LANGUAGE/highlights.scm, in a plugin or in ~/.config/greed/queries; see Using Greed. In greed repl, tostring(require("@greed").view():buffer():tree()) shows the current buffer’s syntax tree, which is what a query matches against. A capture whose name starts with _ (like @_name) is only there for a predicate and isn’t drawn.