Sources/OrgCore/Keymap/Presets.swift

7744f4f551b533ee3cd949986caca4af3c9a12f1
orgstar/Sources/OrgCore/Keymap/Presets.swift

1190 lines · 33735 bytes

   1/// The keymaps the app ships. The user's `keymap.toml` is layered on top of the chosen one.
   2public enum KeymapPreset: String, Sendable, CaseIterable {
   3    case emacs, mac, doom
   4
   5    public var title: String {
   6        switch self {
   7        case .emacs: "Emacs"
   8        case .mac: "Mac"
   9        case .doom: "Doom (Vim keys)"
  10        }
  11    }
  12
  13    /// Whether the preset edits modally.
  14    public var isModal: Bool { self == .doom }
  15
  16    public var keymap: Keymap {
  17        var problems: [String] = []
  18        let map = try! Keymap(toml: toml, problems: &problems)
  19        precondition(problems.isEmpty, "preset \(rawValue): \(problems)")
  20        return map
  21    }
  22
  23    public var toml: String {
  24        switch self {
  25        case .emacs: Self.common + Self.speedBindings(mode: nil) + Self.emacsBindings
  26        case .mac: Self.common + Self.speedBindings(mode: nil) + Self.macBindings
  27        case .doom: Self.doomToml + Self.speedBindings(mode: "insert")
  28        }
  29    }
  30
  31    /// `org-speed-commands`, for the start of a heading line when `org-use-speed-commands` is on.
  32    static let speedCommands: [(key: String, command: String)] = [
  33        ("n", "org.heading.next"), ("p", "org.heading.previous"), ("f", "org.heading.forward-same-level"),
  34        ("b", "org.heading.backward-same-level"), ("u", "org.heading.up"), ("j", "org.goto"),
  35        ("c", "org.cycle"), ("C", "org.cycle-global"), ("s", "org.narrow.toggle"), ("k", "org.subtree.cut"),
  36        ("U", "org.subtree.up"), ("D", "org.subtree.down"), ("r", "org.heading.demote"), ("l", "org.heading.promote"),
  37        ("R", "org.subtree.demote"), ("L", "org.subtree.promote"), ("i", "org.heading.insert-after-subtree"),
  38        ("^", "org.sort"), ("w", "app.refile"), ("a", "app.archive"), ("@", "org.subtree.mark"),
  39        ("#", "org.heading.toggle-comment"), ("I", "app.clock.in"), ("O", "app.clock.out"), ("t", "org.todo.cycle"),
  40        (",", "org.priority.set"), ("0", "org.priority.remove"), ("1", "org.priority.set-a"), ("2", "org.priority.set-b"),
  41        ("3", "org.priority.set-c"), (":", "org.tags.set"), ("e", "org.effort.set"), ("v", "app.agenda"),
  42        ("/", "org.sparse-tree"), ("o", "org.link.open"),
  43    ]
  44
  45    static func speedBindings(mode: String?) -> String {
  46        speedCommands.map { key, command in
  47            "[[bind]]\nkeys = \"\(key)\"\ncommand = \"\(command)\"\nwhen = \"speed\"\n" + (mode.map { "mode = \"\($0)\"\n" } ?? "")
  48        }.joined()
  49    }
  50
  51    /// Doom: the Emacs preset's org bindings in every evil state (as org-mode-map's are), with
  52    /// evil-org's `M-h/j/k/l` forms, then Doom's leader, localleader and evil-org keys.
  53    static var doomToml: String {
  54        var problems: [String] = []
  55        let emacs = try! Keymap(toml: common + emacsBindings, problems: &problems)
  56        let translations: [String: String] = ["<left>": "h", "<right>": "l", "<up>": "k", "<down>": "j"]
  57        var out = ""
  58        func bind(_ keys: String, _ command: String, when: String?, mode: String) {
  59            out += "[[bind]]\nkeys = \"\(keys.replacingOccurrences(of: "\\", with: "\\\\"))\"\ncommand = \"\(command)\"\n"
  60            if let when { out += "when = \"\(when)\"\n" }
  61            out += "mode = \"\(mode)\"\n"
  62        }
  63        for binding in emacs.bindings {
  64            let first = binding.keys[0]
  65            let keys = KeySequence.format(binding.keys)
  66            let orgKey = first.key == "c" && first.modifiers == [.control] || first.key == "x" && first.modifiers == [.control]
  67                || (first.modifiers.contains(.meta) && ["<left>", "<right>", "<up>", "<down>", "RET"].contains(first.key))
  68                || (first.modifiers.contains(.shift) && ["<left>", "<right>", "<up>", "<down>"].contains(first.key))
  69                || (first.modifiers == [.control] && first.key == "RET")
  70                || keys == "M-x"
  71            guard orgKey else { continue }
  72            for mode in ["normal", "insert", "visual"] { bind(keys, binding.command, when: binding.when, mode: mode) }
  73            // evil-org: M-h/j/k/l and M-H/J/K/L in normal, visual and insert.
  74            if binding.keys.count == 1, first.modifiers.contains(.meta), let letter = translations[first.key] {
  75                let shifted = first.modifiers.contains(.shift)
  76                let key = "M-" + (shifted ? letter.uppercased() : letter)
  77                for mode in ["normal", "insert", "visual"] { bind(key, binding.command, when: binding.when, mode: mode) }
  78            }
  79            // Doom: C-S-h/j/k/l are org-shift* in normal and insert.
  80            if binding.keys.count == 1, first.modifiers == [.shift], let letter = translations[first.key] {
  81                for mode in ["normal", "insert"] { bind("C-" + letter.uppercased(), binding.command, when: binding.when, mode: mode) }
  82            }
  83            // evil-org insert state: C-t demotes, C-d promotes.
  84            if binding.keys.count == 1, first.modifiers == [.meta], first.key == "<right>" || first.key == "<left>" {
  85                bind(first.key == "<right>" ? "C-t" : "C-d", binding.command, when: binding.when, mode: "insert")
  86            }
  87        }
  88        return out + doomBindings
  89    }
  90
  91    static let doomBindings = """
  92        # Leader
  93        [[bind]]
  94        keys = "SPC SPC"
  95        command = "app.quick-open"
  96        mode = "normal"
  97        [[bind]]
  98        keys = "SPC q q"
  99        command = "app.quit"
 100        mode = "normal"
 101        [[bind]]
 102        keys = "SPC ."
 103        command = "app.quick-open"
 104        mode = "normal"
 105        [[bind]]
 106        keys = "SPC f f"
 107        command = "app.quick-open"
 108        mode = "normal"
 109        [[bind]]
 110        keys = "SPC f s"
 111        command = "app.save"
 112        mode = "normal"
 113        # Buffers
 114        [[bind]]
 115        keys = "SPC b b"
 116        command = "app.buffer.switch"
 117        mode = "normal"
 118        [[bind]]
 119        keys = "SPC b B"
 120        command = "app.buffer.switch"
 121        mode = "normal"
 122        [[bind]]
 123        keys = "SPC ,"
 124        command = "app.buffer.switch"
 125        mode = "normal"
 126        [[bind]]
 127        keys = "SPC `"
 128        command = "app.buffer.last"
 129        mode = "normal"
 130        [[bind]]
 131        keys = "SPC b k"
 132        command = "app.buffer.kill"
 133        mode = "normal"
 134        [[bind]]
 135        keys = "SPC b d"
 136        command = "app.buffer.kill"
 137        mode = "normal"
 138        [[bind]]
 139        keys = "SPC b K"
 140        command = "app.buffer.kill-all"
 141        mode = "normal"
 142        [[bind]]
 143        keys = "SPC b O"
 144        command = "app.buffer.kill-others"
 145        mode = "normal"
 146        [[bind]]
 147        keys = "SPC b n"
 148        command = "app.buffer.next"
 149        mode = "normal"
 150        [[bind]]
 151        keys = "SPC b p"
 152        command = "app.buffer.previous"
 153        mode = "normal"
 154        [[bind]]
 155        keys = "SPC b ]"
 156        command = "app.buffer.next"
 157        mode = "normal"
 158        [[bind]]
 159        keys = "SPC b ["
 160        command = "app.buffer.previous"
 161        mode = "normal"
 162        [[bind]]
 163        keys = "] b"
 164        command = "app.buffer.next"
 165        mode = "normal"
 166        [[bind]]
 167        keys = "[ b"
 168        command = "app.buffer.previous"
 169        mode = "normal"
 170        [[bind]]
 171        keys = "SPC b s"
 172        command = "app.save"
 173        mode = "normal"
 174        [[bind]]
 175        keys = "SPC b S"
 176        command = "app.save-all"
 177        mode = "normal"
 178        [[bind]]
 179        keys = "SPC s s"
 180        command = "edit.find"
 181        mode = "normal"
 182        [[bind]]
 183        keys = "SPC /"
 184        command = "app.search"
 185        mode = "normal"
 186        [[bind]]
 187        keys = "SPC s p"
 188        command = "app.search"
 189        mode = "normal"
 190        [[bind]]
 191        keys = "SPC :"
 192        command = "app.palette"
 193        mode = "normal"
 194        [[bind]]
 195        keys = "SPC o a"
 196        command = "app.agenda"
 197        mode = "normal"
 198        [[bind]]
 199        keys = "SPC X"
 200        command = "app.capture"
 201        mode = "normal"
 202        [[bind]]
 203        keys = "SPC z t"
 204        command = "app.clock.report"
 205        mode = "normal"
 206        [[bind]]
 207        keys = "SPC h r r"
 208        command = "app.reload-keymap"
 209        mode = "normal"
 210
 211        # Localleader (SPC m)
 212        [[bind]]
 213        keys = "SPC m '"
 214        command = "org.edit-special"
 215        mode = "normal"
 216        [[bind]]
 217        keys = "SPC m s c"
 218        command = "org.subtree.clone"
 219        mode = "normal"
 220        [[bind]]
 221        keys = "SPC m s d"
 222        command = "org.subtree.cut"
 223        mode = "normal"
 224        [[bind]]
 225        keys = "SPC m s S"
 226        command = "org.sort"
 227        mode = "normal"
 228        [[bind]]
 229        keys = "SPC m s n"
 230        command = "org.narrow.subtree"
 231        mode = "normal"
 232        [[bind]]
 233        keys = "SPC m s s"
 234        command = "org.sparse-tree"
 235        mode = "normal"
 236        [[bind]]
 237        keys = "SPC m s N"
 238        command = "org.widen"
 239        mode = "normal"
 240        [[bind]]
 241        keys = "SPC m ."
 242        command = "org.goto"
 243        mode = "normal"
 244        [[bind]]
 245        keys = "SPC m h"
 246        command = "org.heading.toggle"
 247        mode = "normal"
 248        [[bind]]
 249        keys = "SPC m i"
 250        command = "org.item.toggle"
 251        mode = "normal"
 252        [[bind]]
 253        keys = "SPC m l l"
 254        command = "org.link.insert"
 255        mode = "normal"
 256        [[bind]]
 257        keys = "SPC m l s"
 258        command = "org.link.store"
 259        mode = "normal"
 260        [[bind]]
 261        keys = "SPC m l i"
 262        command = "org.id.store-link"
 263        mode = "normal"
 264        [[bind]]
 265        keys = "SPC n l"
 266        command = "org.link.store"
 267        mode = "normal"
 268        [[bind]]
 269        keys = "SPC m t"
 270        command = "org.todo.cycle"
 271        mode = "normal"
 272        [[bind]]
 273        keys = "SPC m q"
 274        command = "org.tags.set"
 275        mode = "normal"
 276        [[bind]]
 277        keys = "SPC m x"
 278        command = "org.checkbox.toggle"
 279        mode = "normal"
 280        [[bind]]
 281        keys = "SPC m A"
 282        command = "app.archive"
 283        mode = "normal"
 284        [[bind]]
 285        keys = "SPC m e h h"
 286        command = "app.export.html"
 287        mode = "normal"
 288        [[bind]]
 289        keys = "SPC m e h o"
 290        command = "app.export.html-open"
 291        mode = "normal"
 292        [[bind]]
 293        keys = "SPC m e m m"
 294        command = "app.export.markdown"
 295        mode = "normal"
 296        [[bind]]
 297        keys = "SPC m e l p"
 298        command = "app.export.pdf"
 299        mode = "normal"
 300        [[bind]]
 301        keys = "SPC m d d"
 302        command = "org.deadline"
 303        mode = "normal"
 304        [[bind]]
 305        keys = "SPC m d s"
 306        command = "org.schedule"
 307        mode = "normal"
 308        [[bind]]
 309        keys = "SPC m d t"
 310        command = "org.timestamp.active"
 311        mode = "normal"
 312        [[bind]]
 313        keys = "SPC m d T"
 314        command = "org.timestamp.inactive"
 315        mode = "normal"
 316        [[bind]]
 317        keys = "SPC m r r"
 318        command = "app.refile"
 319        mode = "normal"
 320        [[bind]]
 321        keys = "SPC m s r"
 322        command = "app.refile"
 323        mode = "normal"
 324        [[bind]]
 325        keys = "SPC m s A"
 326        command = "app.archive"
 327        mode = "normal"
 328        [[bind]]
 329        keys = "SPC m s h"
 330        command = "org.subtree.promote"
 331        mode = "normal"
 332        [[bind]]
 333        keys = "SPC m s l"
 334        command = "org.subtree.demote"
 335        mode = "normal"
 336        [[bind]]
 337        keys = "SPC m s j"
 338        command = "org.subtree.down"
 339        mode = "normal"
 340        [[bind]]
 341        keys = "SPC m s k"
 342        command = "org.subtree.up"
 343        mode = "normal"
 344        [[bind]]
 345        keys = "SPC m c i"
 346        command = "app.clock.in"
 347        mode = "normal"
 348        [[bind]]
 349        keys = "SPC m c o"
 350        command = "app.clock.out"
 351        mode = "normal"
 352        [[bind]]
 353        keys = "SPC m c c"
 354        command = "app.clock.cancel"
 355        mode = "normal"
 356        [[bind]]
 357        keys = "SPC m c g"
 358        command = "app.clock.goto"
 359        mode = "normal"
 360        [[bind]]
 361        keys = "SPC m c R"
 362        command = "app.clock.report"
 363        mode = "normal"
 364        [[bind]]
 365        keys = "SPC m c E"
 366        command = "org.effort.set"
 367        mode = "normal"
 368        [[bind]]
 369        keys = "SPC m p p"
 370        command = "org.priority.set"
 371        mode = "normal"
 372        [[bind]]
 373        keys = "SPC m o"
 374        command = "org.property.read-and-set"
 375        mode = "normal"
 376        [[bind]]
 377        keys = "SPC m p u"
 378        command = "org.priority.up"
 379        mode = "normal"
 380        [[bind]]
 381        keys = "SPC m p d"
 382        command = "org.priority.down"
 383        mode = "normal"
 384        [[bind]]
 385        keys = "SPC m b -"
 386        command = "org.table.insert-hline"
 387        mode = "normal"
 388        [[bind]]
 389        keys = "SPC m b a"
 390        command = "org.table.align"
 391        mode = "normal"
 392        [[bind]]
 393        keys = "SPC m b r"
 394        command = "org.table.recalc-all"
 395        mode = "normal"
 396        [[bind]]
 397        keys = "SPC m b d c"
 398        command = "org.table.delete-column"
 399        mode = "normal"
 400        [[bind]]
 401        keys = "SPC m b d r"
 402        command = "org.table.kill-row"
 403        mode = "normal"
 404        [[bind]]
 405        keys = "SPC m b i c"
 406        command = "org.table.insert-column"
 407        mode = "normal"
 408        [[bind]]
 409        keys = "SPC m b i r"
 410        command = "org.table.insert-row"
 411        mode = "normal"
 412        [[bind]]
 413        keys = "SPC m b i h"
 414        command = "org.table.insert-hline"
 415        mode = "normal"
 416
 417        # evil-org and Doom's org keys
 418        [[bind]]
 419        keys = "TAB"
 420        command = "org.cycle"
 421        mode = "normal"
 422        [[bind]]
 423        keys = "S-TAB"
 424        command = "org.cycle-global"
 425        mode = "normal"
 426        [[bind]]
 427        keys = "RET"
 428        command = "org.dwim"
 429        mode = "normal"
 430        [[bind]]
 431        keys = "z a"
 432        command = "org.cycle"
 433        mode = "normal"
 434        [[bind]]
 435        keys = "z c"
 436        command = "org.cycle"
 437        mode = "normal"
 438        [[bind]]
 439        keys = "z o"
 440        command = "org.cycle"
 441        mode = "normal"
 442        [[bind]]
 443        keys = "z A"
 444        command = "org.cycle-global"
 445        mode = "normal"
 446        [[bind]]
 447        keys = "g h"
 448        command = "org.heading.up"
 449        mode = "normal"
 450        [[bind]]
 451        keys = "g j"
 452        command = "org.heading.forward-same-level"
 453        mode = "normal"
 454        [[bind]]
 455        keys = "g k"
 456        command = "org.heading.backward-same-level"
 457        mode = "normal"
 458        [[bind]]
 459        keys = "] h"
 460        command = "org.heading.forward-same-level"
 461        mode = "normal"
 462        [[bind]]
 463        keys = "[ h"
 464        command = "org.heading.backward-same-level"
 465        mode = "normal"
 466        [[bind]]
 467        keys = "RET"
 468        command = "org.table.next-row"
 469        when = "table"
 470        mode = "insert"
 471        [[bind]]
 472        keys = "TAB"
 473        command = "org.cycle"
 474        mode = "visual"
 475        [[bind]]
 476        keys = "S-TAB"
 477        command = "org.cycle-global"
 478        mode = "visual"
 479
 480        # Insert state: org-cycle and org-shifttab with Doom's +org-indent-maybe-h, which
 481        # demotes or promotes a heading and indents or outdents an item tree.
 482        [[bind]]
 483        keys = "S-TAB"
 484        command = "org.cycle-global"
 485        mode = "insert"
 486        [[bind]]
 487        keys = "TAB"
 488        command = "org.table.next-field"
 489        when = "table"
 490        mode = "insert"
 491        [[bind]]
 492        keys = "S-TAB"
 493        command = "org.table.previous-field"
 494        when = "table"
 495        mode = "insert"
 496        [[bind]]
 497        keys = "TAB"
 498        command = "org.item.indent-tree"
 499        when = "item"
 500        mode = "insert"
 501        [[bind]]
 502        keys = "S-TAB"
 503        command = "org.item.outdent-tree"
 504        when = "item"
 505        mode = "insert"
 506        [[bind]]
 507        keys = "TAB"
 508        command = "org.heading.demote"
 509        when = "heading"
 510        mode = "insert"
 511        [[bind]]
 512        keys = "S-TAB"
 513        command = "org.heading.promote"
 514        when = "heading"
 515        mode = "insert"
 516
 517        """
 518
 519
 520    static let common = """
 521        [[bind]]
 522        keys = "TAB"
 523        command = "org.cycle"
 524        when = "heading"
 525        [[bind]]
 526        keys = "TAB"
 527        command = "org.cycle"
 528        when = "fold-line"
 529
 530        [[bind]]
 531        keys = "S-TAB"
 532        command = "org.cycle-global"
 533        [[bind]]
 534        keys = "TAB"
 535        command = "org.table.next-field"
 536        when = "table"
 537        [[bind]]
 538        keys = "S-TAB"
 539        command = "org.table.previous-field"
 540        when = "table"
 541        [[bind]]
 542        keys = "RET"
 543        command = "org.table.next-row"
 544        when = "table"
 545
 546        """
 547
 548    static let emacsBindings = """
 549        # Movement and editing. With a mark set (C-SPC), movement extends the region.
 550        [[bind]]
 551        keys = "C-f"
 552        command = "edit.forward-char"
 553        [[bind]]
 554        keys = "C-b"
 555        command = "edit.backward-char"
 556        [[bind]]
 557        keys = "C-n"
 558        command = "edit.next-line"
 559        [[bind]]
 560        keys = "C-p"
 561        command = "edit.previous-line"
 562        [[bind]]
 563        keys = "C-a"
 564        command = "edit.beginning-of-line"
 565        [[bind]]
 566        keys = "C-e"
 567        command = "edit.end-of-line"
 568        [[bind]]
 569        keys = "M-f"
 570        command = "edit.forward-word"
 571        [[bind]]
 572        keys = "M-b"
 573        command = "edit.backward-word"
 574        [[bind]]
 575        keys = "M-<"
 576        command = "edit.beginning-of-buffer"
 577        [[bind]]
 578        keys = "M->"
 579        command = "edit.end-of-buffer"
 580        [[bind]]
 581        keys = "C-v"
 582        command = "edit.scroll-up"
 583        [[bind]]
 584        keys = "M-v"
 585        command = "edit.scroll-down"
 586        [[bind]]
 587        keys = "C-l"
 588        command = "edit.recenter"
 589        [[bind]]
 590        keys = "C-d"
 591        command = "edit.delete-char"
 592        [[bind]]
 593        keys = "M-d"
 594        command = "edit.kill-word"
 595        [[bind]]
 596        keys = "M-DEL"
 597        command = "edit.backward-kill-word"
 598        [[bind]]
 599        keys = "C-k"
 600        command = "edit.kill-line"
 601        [[bind]]
 602        keys = "C-y"
 603        command = "edit.yank"
 604        [[bind]]
 605        keys = "C-SPC"
 606        command = "edit.set-mark"
 607        [[bind]]
 608        keys = "C-x h"
 609        command = "edit.select-all"
 610        [[bind]]
 611        keys = "C-w"
 612        command = "edit.kill-region"
 613        [[bind]]
 614        keys = "M-w"
 615        command = "edit.copy-region"
 616        [[bind]]
 617        keys = "C-/"
 618        command = "edit.undo"
 619        [[bind]]
 620        keys = "C-_"
 621        command = "edit.undo"
 622        [[bind]]
 623        keys = "C-x u"
 624        command = "edit.undo"
 625        [[bind]]
 626        keys = "C-g"
 627        command = "edit.keyboard-quit"
 628        [[bind]]
 629        keys = "C-t"
 630        command = "edit.transpose-chars"
 631        [[bind]]
 632        keys = "C-s"
 633        command = "edit.find"
 634        [[bind]]
 635        keys = "C-r"
 636        command = "edit.find"
 637        [[bind]]
 638        keys = "M-%"
 639        command = "edit.replace"
 640
 641        # Files and commands
 642        [[bind]]
 643        keys = "C-x C-s"
 644        command = "app.save"
 645        [[bind]]
 646        keys = "C-c C-o"
 647        command = "org.link.open"
 648        [[bind]]
 649        keys = "C-c C-l"
 650        command = "org.link.insert"
 651        [[bind]]
 652        keys = "C-c l"
 653        command = "org.link.store"
 654        [[bind]]
 655        keys = "C-c ;"
 656        command = "org.heading.toggle-comment"
 657        [[bind]]
 658        keys = "C-c *"
 659        command = "org.heading.toggle"
 660        [[bind]]
 661        keys = "C-c -"
 662        command = "org.item.toggle"
 663        [[bind]]
 664        keys = "C-c @"
 665        command = "org.subtree.mark"
 666        [[bind]]
 667        keys = "C-c C-x C-w"
 668        command = "org.subtree.cut"
 669        [[bind]]
 670        keys = "C-c C-x M-w"
 671        command = "org.subtree.copy"
 672        [[bind]]
 673        keys = "C-c C-x C-y"
 674        command = "org.subtree.paste"
 675        [[bind]]
 676        keys = "C-c C-x c"
 677        command = "org.subtree.clone"
 678        [[bind]]
 679        keys = "C-c ^"
 680        command = "org.sort"
 681        [[bind]]
 682        keys = "C-c C-c"
 683        command = "org.ctrl-c-ctrl-c"
 684        [[bind]]
 685        keys = "C-c C-y"
 686        command = "org.timestamp.evaluate-range"
 687        [[bind]]
 688        keys = "C-c C-x f"
 689        command = "org.footnote.action"
 690        [[bind]]
 691        keys = "C-c ="
 692        command = "org.table.column-formula"
 693        [[bind]]
 694        keys = "C-c TAB"
 695        command = "org.table.toggle-column-width"
 696        when = "table"
 697        [[bind]]
 698        keys = "C-x n s"
 699        command = "org.narrow.subtree"
 700        [[bind]]
 701        keys = "C-x n b"
 702        command = "org.narrow.block"
 703        [[bind]]
 704        keys = "C-x n w"
 705        command = "org.widen"
 706        [[bind]]
 707        keys = "C-c C-j"
 708        command = "org.goto"
 709        [[bind]]
 710        keys = "C-c /"
 711        command = "org.sparse-tree"
 712        [[bind]]
 713        keys = "C-c ,"
 714        command = "org.priority.set"
 715        [[bind]]
 716        keys = "C-c C-x p"
 717        command = "org.property.read-and-set"
 718        [[bind]]
 719        keys = "C-c C-x i"
 720        command = "org.columns.insert-dblock"
 721        [[bind]]
 722        keys = "C-c C-x C-c"
 723        command = "org.columns"
 724        [[bind]]
 725        keys = "S-<right>"
 726        command = "org.property.next-value"
 727        when = "property"
 728        [[bind]]
 729        keys = "S-<left>"
 730        command = "org.property.previous-value"
 731        when = "property"
 732        [[bind]]
 733        keys = "C-c C-x C-r"
 734        command = "org.clock.report"
 735        [[bind]]
 736        keys = "C-c C-x C-u"
 737        command = "org.dblock.update"
 738        [[bind]]
 739        keys = "C-c C-x e"
 740        command = "org.effort.set"
 741        [[bind]]
 742        keys = "C-c C-c"
 743        command = "org.dblock.update"
 744        when = "dblock"
 745        [[bind]]
 746        keys = "C-c C-,"
 747        command = "org.structure-template"
 748        [[bind]]
 749        keys = "C-c '"
 750        command = "org.edit-special"
 751        [[bind]]
 752        keys = "C-x b"
 753        command = "app.buffer.switch"
 754        [[bind]]
 755        keys = "C-x C-b"
 756        command = "app.buffer.switch"
 757        [[bind]]
 758        keys = "C-x k"
 759        command = "app.buffer.kill"
 760        [[bind]]
 761        keys = "C-x <right>"
 762        command = "app.buffer.next"
 763        [[bind]]
 764        keys = "C-x <left>"
 765        command = "app.buffer.previous"
 766        [[bind]]
 767        keys = "C-x s"
 768        command = "app.save-all"
 769        [[bind]]
 770        keys = "C-x C-f"
 771        command = "app.quick-open"
 772        [[bind]]
 773        keys = "M-x"
 774        command = "app.palette"
 775        [[bind]]
 776        keys = "C-c a"
 777        command = "app.agenda"
 778        [[bind]]
 779        keys = "C-c c"
 780        command = "app.capture"
 781        [[bind]]
 782        keys = "C-c C-x C-i"
 783        command = "app.clock.in"
 784        [[bind]]
 785        keys = "C-c C-x C-o"
 786        command = "app.clock.out"
 787        [[bind]]
 788        keys = "C-c C-x C-q"
 789        command = "app.clock.cancel"
 790        [[bind]]
 791        keys = "C-c C-x C-j"
 792        command = "app.clock.goto"
 793        [[bind]]
 794        keys = "C-c C-e h h"
 795        command = "app.export.html"
 796        [[bind]]
 797        keys = "C-c C-e h o"
 798        command = "app.export.html-open"
 799        [[bind]]
 800        keys = "C-c C-e m m"
 801        command = "app.export.markdown"
 802        [[bind]]
 803        keys = "C-c C-e l p"
 804        command = "app.export.pdf"
 805        [[bind]]
 806        keys = "C-c C-e l l"
 807        command = "app.export.latex"
 808        [[bind]]
 809        keys = "C-c C-e o o"
 810        command = "app.export.odt"
 811        [[bind]]
 812        keys = "C-c C-e t u"
 813        command = "app.export.text"
 814
 815        # Org
 816        [[bind]]
 817        keys = "C-c C-t"
 818        command = "org.todo.cycle"
 819        [[bind]]
 820        keys = "S-<right>"
 821        command = "org.todo.next"
 822        when = "heading"
 823        [[bind]]
 824        keys = "S-<left>"
 825        command = "org.todo.previous"
 826        when = "heading"
 827        [[bind]]
 828        keys = "S-<up>"
 829        command = "org.priority.up"
 830        when = "heading"
 831        [[bind]]
 832        keys = "S-<down>"
 833        command = "org.priority.down"
 834        when = "heading"
 835        [[bind]]
 836        keys = "M-<left>"
 837        command = "org.heading.promote"
 838        when = "heading"
 839        [[bind]]
 840        keys = "M-<right>"
 841        command = "org.heading.demote"
 842        when = "heading"
 843        [[bind]]
 844        keys = "M-S-<left>"
 845        command = "org.subtree.promote"
 846        when = "heading"
 847        [[bind]]
 848        keys = "M-S-<right>"
 849        command = "org.subtree.demote"
 850        when = "heading"
 851        [[bind]]
 852        keys = "M-<up>"
 853        command = "org.subtree.up"
 854        when = "heading"
 855        [[bind]]
 856        keys = "M-<down>"
 857        command = "org.subtree.down"
 858        when = "heading"
 859        [[bind]]
 860        keys = "M-RET"
 861        command = "org.heading.insert"
 862        [[bind]]
 863        keys = "C-RET"
 864        command = "org.heading.insert-after-subtree"
 865        [[bind]]
 866        keys = "M-S-RET"
 867        command = "org.heading.insert-todo"
 868        [[bind]]
 869        keys = "C-c C-n"
 870        command = "org.heading.next"
 871        [[bind]]
 872        keys = "C-c C-p"
 873        command = "org.heading.previous"
 874        [[bind]]
 875        keys = "C-c C-f"
 876        command = "org.heading.forward-same-level"
 877        [[bind]]
 878        keys = "C-c C-b"
 879        command = "org.heading.backward-same-level"
 880        [[bind]]
 881        keys = "C-c C-u"
 882        command = "org.heading.up"
 883        [[bind]]
 884        keys = "C-c C-q"
 885        command = "org.tags.set"
 886        [[bind]]
 887        keys = "M-RET"
 888        command = "org.item.insert"
 889        when = "item"
 890        [[bind]]
 891        keys = "M-S-RET"
 892        command = "org.item.insert-checkbox"
 893        when = "item"
 894        [[bind]]
 895        keys = "M-<left>"
 896        command = "org.item.outdent"
 897        when = "item"
 898        [[bind]]
 899        keys = "M-<right>"
 900        command = "org.item.indent"
 901        when = "item"
 902        [[bind]]
 903        keys = "M-S-<left>"
 904        command = "org.item.outdent-tree"
 905        when = "item"
 906        [[bind]]
 907        keys = "M-S-<right>"
 908        command = "org.item.indent-tree"
 909        when = "item"
 910        [[bind]]
 911        keys = "M-<up>"
 912        command = "org.item.up"
 913        when = "item"
 914        [[bind]]
 915        keys = "M-<down>"
 916        command = "org.item.down"
 917        when = "item"
 918        [[bind]]
 919        keys = "C-c C-c"
 920        command = "org.ctrl-c-ctrl-c"
 921        when = "item"
 922        [[bind]]
 923        keys = "C-c C-x C-b"
 924        command = "org.checkbox.toggle"
 925        [[bind]]
 926        keys = "C-c C-w"
 927        command = "app.refile"
 928        [[bind]]
 929        keys = "C-c C-x C-s"
 930        command = "app.archive"
 931        [[bind]]
 932        keys = "C-c $"
 933        command = "app.archive"
 934        [[bind]]
 935        keys = "C-c ."
 936        command = "org.timestamp.active"
 937        [[bind]]
 938        keys = "C-c !"
 939        command = "org.timestamp.inactive"
 940        [[bind]]
 941        keys = "C-c C-s"
 942        command = "org.schedule"
 943        [[bind]]
 944        keys = "C-c C-d"
 945        command = "org.deadline"
 946        [[bind]]
 947        keys = "M-q"
 948        command = "org.fill-paragraph"
 949        [[bind]]
 950        keys = "C-c C-c"
 951        command = "org.table.align"
 952        when = "table"
 953        [[bind]]
 954        keys = "C-c C-c"
 955        command = "org.table.recalc-all"
 956        when = "tblfm"
 957        [[bind]]
 958        keys = "C-c *"
 959        command = "org.table.recalc"
 960        when = "table"
 961        [[bind]]
 962        keys = "C-c C-c"
 963        command = "org.babel.execute"
 964        when = "src"
 965        [[bind]]
 966        keys = "M-<up>"
 967        command = "org.table.row-up"
 968        when = "table"
 969        [[bind]]
 970        keys = "M-<down>"
 971        command = "org.table.row-down"
 972        when = "table"
 973        [[bind]]
 974        keys = "M-<left>"
 975        command = "org.table.column-left"
 976        when = "table"
 977        [[bind]]
 978        keys = "M-<right>"
 979        command = "org.table.column-right"
 980        when = "table"
 981        [[bind]]
 982        keys = "M-S-<right>"
 983        command = "org.table.insert-column"
 984        when = "table"
 985        [[bind]]
 986        keys = "M-S-<left>"
 987        command = "org.table.delete-column"
 988        when = "table"
 989        [[bind]]
 990        keys = "M-S-<up>"
 991        command = "org.table.kill-row"
 992        when = "table"
 993        [[bind]]
 994        keys = "M-S-<down>"
 995        command = "org.table.insert-row"
 996        when = "table"
 997        [[bind]]
 998        keys = "C-c -"
 999        command = "org.table.insert-hline"
1000        when = "table"
1001        [[bind]]
1002        keys = "C-c |"
1003        command = "org.table.create"
1004        [[bind]]
1005        keys = "S-<up>"
1006        command = "org.timestamp.up"
1007        when = "timestamp"
1008        [[bind]]
1009        keys = "S-<down>"
1010        command = "org.timestamp.down"
1011        when = "timestamp"
1012        [[bind]]
1013        keys = "S-<right>"
1014        command = "org.timestamp.day-later"
1015        when = "timestamp"
1016        [[bind]]
1017        keys = "S-<left>"
1018        command = "org.timestamp.day-earlier"
1019        when = "timestamp"
1020
1021        """
1022
1023    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
1024    /// macOS text editing leaves free.
1025    static let macBindings = """
1026        [[bind]]
1027        keys = "C-TAB"
1028        command = "app.buffer.next"
1029        [[bind]]
1030        keys = "C-S-TAB"
1031        command = "app.buffer.previous"
1032        [[bind]]
1033        keys = "C-s-t"
1034        command = "org.todo.cycle"
1035        [[bind]]
1036        keys = "C-s-<up>"
1037        command = "org.priority.up"
1038        [[bind]]
1039        keys = "C-s-<down>"
1040        command = "org.priority.down"
1041        [[bind]]
1042        keys = "C-s-<left>"
1043        command = "org.heading.promote"
1044        [[bind]]
1045        keys = "C-s-<right>"
1046        command = "org.heading.demote"
1047        [[bind]]
1048        keys = "C-M-s-<left>"
1049        command = "org.subtree.promote"
1050        [[bind]]
1051        keys = "C-M-s-<right>"
1052        command = "org.subtree.demote"
1053        [[bind]]
1054        keys = "C-M-s-<up>"
1055        command = "org.subtree.up"
1056        [[bind]]
1057        keys = "C-M-s-<down>"
1058        command = "org.subtree.down"
1059        [[bind]]
1060        keys = "s-RET"
1061        command = "org.heading.insert"
1062        [[bind]]
1063        keys = "C-s-RET"
1064        command = "org.heading.insert-after-subtree"
1065        [[bind]]
1066        keys = "s-S-RET"
1067        command = "org.heading.insert-todo"
1068        [[bind]]
1069        keys = "M-s-<down>"
1070        command = "org.heading.next"
1071        [[bind]]
1072        keys = "M-s-<up>"
1073        command = "org.heading.previous"
1074        [[bind]]
1075        keys = "C-s-q"
1076        command = "org.tags.set"
1077        [[bind]]
1078        keys = "s-RET"
1079        command = "org.item.insert"
1080        when = "item"
1081        [[bind]]
1082        keys = "s-S-RET"
1083        command = "org.item.insert-checkbox"
1084        when = "item"
1085        [[bind]]
1086        keys = "C-s-<left>"
1087        command = "org.item.outdent"
1088        when = "item"
1089        [[bind]]
1090        keys = "C-s-<right>"
1091        command = "org.item.indent"
1092        when = "item"
1093        [[bind]]
1094        keys = "C-M-s-<left>"
1095        command = "org.item.outdent-tree"
1096        when = "item"
1097        [[bind]]
1098        keys = "C-M-s-<right>"
1099        command = "org.item.indent-tree"
1100        when = "item"
1101        [[bind]]
1102        keys = "C-M-s-<up>"
1103        command = "org.item.up"
1104        when = "item"
1105        [[bind]]
1106        keys = "C-M-s-<down>"
1107        command = "org.item.down"
1108        when = "item"
1109        [[bind]]
1110        keys = "C-s-c"
1111        command = "org.checkbox.toggle"
1112        [[bind]]
1113        keys = "C-s-w"
1114        command = "app.refile"
1115        [[bind]]
1116        keys = "C-s-a"
1117        command = "app.archive"
1118        [[bind]]
1119        keys = "C-s-."
1120        command = "org.timestamp.active"
1121        [[bind]]
1122        keys = "C-M-s-."
1123        command = "org.timestamp.inactive"
1124        [[bind]]
1125        keys = "C-s-s"
1126        command = "org.schedule"
1127        [[bind]]
1128        keys = "C-s-d"
1129        command = "org.deadline"
1130        [[bind]]
1131        keys = "C-s-p"
1132        command = "org.fill-paragraph"
1133        [[bind]]
1134        keys = "C-s-<up>"
1135        command = "org.table.row-up"
1136        when = "table"
1137        [[bind]]
1138        keys = "C-s-<down>"
1139        command = "org.table.row-down"
1140        when = "table"
1141        [[bind]]
1142        keys = "C-s-<left>"
1143        command = "org.table.column-left"
1144        when = "table"
1145        [[bind]]
1146        keys = "C-s-<right>"
1147        command = "org.table.column-right"
1148        when = "table"
1149        [[bind]]
1150        keys = "C-M-s-<right>"
1151        command = "org.table.insert-column"
1152        when = "table"
1153        [[bind]]
1154        keys = "C-M-s-<left>"
1155        command = "org.table.delete-column"
1156        when = "table"
1157        [[bind]]
1158        keys = "C-M-s-<up>"
1159        command = "org.table.kill-row"
1160        when = "table"
1161        [[bind]]
1162        keys = "C-M-s-<down>"
1163        command = "org.table.insert-row"
1164        when = "table"
1165        [[bind]]
1166        keys = "C-s--"
1167        command = "org.table.insert-hline"
1168        when = "table"
1169        [[bind]]
1170        keys = "C-s-\\\\"
1171        command = "org.table.create"
1172        [[bind]]
1173        keys = "C-s-<up>"
1174        command = "org.timestamp.up"
1175        when = "timestamp"
1176        [[bind]]
1177        keys = "C-s-<down>"
1178        command = "org.timestamp.down"
1179        when = "timestamp"
1180        [[bind]]
1181        keys = "C-s-<right>"
1182        command = "org.timestamp.day-later"
1183        when = "timestamp"
1184        [[bind]]
1185        keys = "C-s-<left>"
1186        command = "org.timestamp.day-earlier"
1187        when = "timestamp"
1188
1189        """
1190}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form