Skip to content
mart3323 edited this page Mar 13, 2025 · 1 revision

Using micro as the default editor

Micro (https://micro-editor.github.io/) is "a modern and intuitive terminal-based text editor"

To use micro, add it to your jj config as the ui.editor

$ jj config edit --user --config-toml 'ui-editor="micro"'

ui.editor = "micro"

# Alternatively, you can add it under the ui heading as follows
# [ui]
# editor = "micro"

Now, jj will open micro for editing change descriptions and configs

Syntax highlighting

To get syntax highlighting, a custom syntax file needs to be added to micro

$ micro ~/.config/micro/syntax/jjdescription.yaml

filetype: jj-commit

detect:
  filename: "(\\.(jjdescription)$)"

rules:

  # Since jj v0.25.0, a `JJ: ignore-rest` line will comment out everything until the next describe block
  - comment.block:
      start: "^JJ: ignore-rest"
      # Impl note: Cannot use lookaheads in micro, so to highlight describe at all, i need to match this series of dashes after it
      # Assumption: The only lines ending in 7 dashes are the describe lines, and all describe lines will have dashes
      # If this assumption is broken, the highlighting will become incorrect
      end: " -------$" 
      rules:
          - type.keyword: "describe [0-9a-f]{12}"
          - diff-added: "     A (.+)$"
          - diff-modified: "     M (.+)$"
          - diff-deleted: "     D (.+)$"

  # Otherwise, every line starting with JJ: is also considered a comment on its own
  - comment:
        start: "JJ:"
        end: "$"
        rules: 
            - type.keyword: "describe [0-9a-f]{12}"
            - diff-added: "^     A (.+)$"
            - diff-modified: "^     M (.+)$"
            - diff-deleted: "^     D (.+)$"

Limitations:

This syntax file is imperfect - it works fine for most cases, but the highlighting can break...:

  • ...When using JJ: ignore-rest, if you have 7 dashes at the end of a different line other than the JJ: describe 0123456789ab -------
  • ...When using JJ: ignore-rest, and the next describe line has been modified (dashes removed, extra spaces on the end, etc.)
Clone this wiki locally