Syntax Highlighting
Using bat
bat is a cat clone with syntax highlighting and Git integration. You can use mq’s Sublime syntax file to enable syntax highlighting for mq files in bat.
Setting up mq syntax highlighting
- Create the bat syntax directory if it doesn’t exist:
mkdir -p "$(bat --config-dir)/syntaxes"
- Copy the mq syntax file:
# Clone the mq repository or download mq.sublime-syntax
curl -o "$(bat --config-dir)/syntaxes/mq.sublime-syntax" \
https://raw.githubusercontent.com/harehare/mq/main/assets/mq.sublime-syntax
- Rebuild bat’s cache:
bat cache --build
Usage
Now you can use bat to display mq files with syntax highlighting:
# View an mq file with syntax highlighting
bat query.mq
Example
Create a sample mq file:
cat > example.mq << 'EOF'
# This is a comment
def greet(name):
s"Hello, ${name}!"
end
.h | .text | greet("World")
EOF
View it with syntax highlighting:
bat example.mq
Helix
Helix discovers languages, tree-sitter grammars, and LSP servers through its languages.toml config file rather than a dedicated plugin. mq syntax highlighting is provided by tree-sitter-mq, and language features (completion, hover, diagnostics) by mq-lsp.
Setting up mq support
- Add the following to
languages.tomlin your Helix config directory (~/.config/helix/languages.toml):
[[language]]
name = "mq"
scope = "source.mq"
file-types = ["mq"]
comment-token = "#"
language-servers = ["mq-lsp"]
indent = { tab-width = 2, unit = " " }
[language-server.mq-lsp]
command = "mq-lsp"
[[grammar]]
name = "mq"
source = { git = "https://github.com/harehare/tree-sitter-mq", rev = "main" }
- Fetch and build the grammar:
hx --grammar fetch
hx --grammar build
- Copy the highlight queries from tree-sitter-mq into your Helix runtime directory, since Helix does not bundle queries for externally configured grammars:
mkdir -p ~/.config/helix/runtime/queries/mq
curl -o ~/.config/helix/runtime/queries/mq/highlights.scm \
https://raw.githubusercontent.com/harehare/tree-sitter-mq/main/queries/highlights.scm
-
Make sure
mq-lspis installed and on yourPATH. -
Verify the setup:
hx --health mq
This should report the tree-sitter grammar as found and mq-lsp as configured.
Editor Support
In addition to bat, mq syntax highlighting is available for:
- Visual Studio Code: Install the mq extension
- Obsidian: Install the mq plugin
- Helix: See the Helix section above for
languages.tomlsetup