Sources/OrgCore/Keymap/Presets.swift

17a802e0e10aed090bb0556da74277d07734b0ce
orgstar/Sources/OrgCore/Keymap/Presets.swift

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