Sources/OrgCore/Keymap/Presets.swift

2e692ba274ccc7e69b6b3cfc00edeafbbeef638a
orgstar/Sources/OrgCore/Keymap/Presets.swift

1068 lines · 29425 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 s c"
 194        command = "org.subtree.clone"
 195        mode = "normal"
 196        [[bind]]
 197        keys = "SPC m s d"
 198        command = "org.subtree.cut"
 199        mode = "normal"
 200        [[bind]]
 201        keys = "SPC m s S"
 202        command = "org.sort"
 203        mode = "normal"
 204        [[bind]]
 205        keys = "SPC m h"
 206        command = "org.heading.toggle"
 207        mode = "normal"
 208        [[bind]]
 209        keys = "SPC m i"
 210        command = "org.item.toggle"
 211        mode = "normal"
 212        [[bind]]
 213        keys = "SPC m l l"
 214        command = "org.link.insert"
 215        mode = "normal"
 216        [[bind]]
 217        keys = "SPC m l s"
 218        command = "org.link.store"
 219        mode = "normal"
 220        [[bind]]
 221        keys = "SPC m l i"
 222        command = "org.id.store-link"
 223        mode = "normal"
 224        [[bind]]
 225        keys = "SPC n l"
 226        command = "org.link.store"
 227        mode = "normal"
 228        [[bind]]
 229        keys = "SPC m t"
 230        command = "org.todo.cycle"
 231        mode = "normal"
 232        [[bind]]
 233        keys = "SPC m q"
 234        command = "org.tags.set"
 235        mode = "normal"
 236        [[bind]]
 237        keys = "SPC m x"
 238        command = "org.checkbox.toggle"
 239        mode = "normal"
 240        [[bind]]
 241        keys = "SPC m A"
 242        command = "app.archive"
 243        mode = "normal"
 244        [[bind]]
 245        keys = "SPC m e h h"
 246        command = "app.export.html"
 247        mode = "normal"
 248        [[bind]]
 249        keys = "SPC m e h o"
 250        command = "app.export.html-open"
 251        mode = "normal"
 252        [[bind]]
 253        keys = "SPC m e m m"
 254        command = "app.export.markdown"
 255        mode = "normal"
 256        [[bind]]
 257        keys = "SPC m e l p"
 258        command = "app.export.pdf"
 259        mode = "normal"
 260        [[bind]]
 261        keys = "SPC m d d"
 262        command = "org.deadline"
 263        mode = "normal"
 264        [[bind]]
 265        keys = "SPC m d s"
 266        command = "org.schedule"
 267        mode = "normal"
 268        [[bind]]
 269        keys = "SPC m d t"
 270        command = "org.timestamp.active"
 271        mode = "normal"
 272        [[bind]]
 273        keys = "SPC m d T"
 274        command = "org.timestamp.inactive"
 275        mode = "normal"
 276        [[bind]]
 277        keys = "SPC m r r"
 278        command = "app.refile"
 279        mode = "normal"
 280        [[bind]]
 281        keys = "SPC m s r"
 282        command = "app.refile"
 283        mode = "normal"
 284        [[bind]]
 285        keys = "SPC m s A"
 286        command = "app.archive"
 287        mode = "normal"
 288        [[bind]]
 289        keys = "SPC m s h"
 290        command = "org.subtree.promote"
 291        mode = "normal"
 292        [[bind]]
 293        keys = "SPC m s l"
 294        command = "org.subtree.demote"
 295        mode = "normal"
 296        [[bind]]
 297        keys = "SPC m s j"
 298        command = "org.subtree.down"
 299        mode = "normal"
 300        [[bind]]
 301        keys = "SPC m s k"
 302        command = "org.subtree.up"
 303        mode = "normal"
 304        [[bind]]
 305        keys = "SPC m c i"
 306        command = "app.clock.in"
 307        mode = "normal"
 308        [[bind]]
 309        keys = "SPC m c o"
 310        command = "app.clock.out"
 311        mode = "normal"
 312        [[bind]]
 313        keys = "SPC m c c"
 314        command = "app.clock.cancel"
 315        mode = "normal"
 316        [[bind]]
 317        keys = "SPC m c g"
 318        command = "app.clock.goto"
 319        mode = "normal"
 320        [[bind]]
 321        keys = "SPC m c R"
 322        command = "app.clock.report"
 323        mode = "normal"
 324        [[bind]]
 325        keys = "SPC m p u"
 326        command = "org.priority.up"
 327        mode = "normal"
 328        [[bind]]
 329        keys = "SPC m p d"
 330        command = "org.priority.down"
 331        mode = "normal"
 332        [[bind]]
 333        keys = "SPC m b -"
 334        command = "org.table.insert-hline"
 335        mode = "normal"
 336        [[bind]]
 337        keys = "SPC m b a"
 338        command = "org.table.align"
 339        mode = "normal"
 340        [[bind]]
 341        keys = "SPC m b r"
 342        command = "org.table.recalc-all"
 343        mode = "normal"
 344        [[bind]]
 345        keys = "SPC m b d c"
 346        command = "org.table.delete-column"
 347        mode = "normal"
 348        [[bind]]
 349        keys = "SPC m b d r"
 350        command = "org.table.kill-row"
 351        mode = "normal"
 352        [[bind]]
 353        keys = "SPC m b i c"
 354        command = "org.table.insert-column"
 355        mode = "normal"
 356        [[bind]]
 357        keys = "SPC m b i r"
 358        command = "org.table.insert-row"
 359        mode = "normal"
 360        [[bind]]
 361        keys = "SPC m b i h"
 362        command = "org.table.insert-hline"
 363        mode = "normal"
 364
 365        # evil-org and Doom's org keys
 366        [[bind]]
 367        keys = "TAB"
 368        command = "org.cycle"
 369        mode = "normal"
 370        [[bind]]
 371        keys = "S-TAB"
 372        command = "org.cycle-global"
 373        mode = "normal"
 374        [[bind]]
 375        keys = "RET"
 376        command = "org.dwim"
 377        mode = "normal"
 378        [[bind]]
 379        keys = "z a"
 380        command = "org.cycle"
 381        mode = "normal"
 382        [[bind]]
 383        keys = "z c"
 384        command = "org.cycle"
 385        mode = "normal"
 386        [[bind]]
 387        keys = "z o"
 388        command = "org.cycle"
 389        mode = "normal"
 390        [[bind]]
 391        keys = "z A"
 392        command = "org.cycle-global"
 393        mode = "normal"
 394        [[bind]]
 395        keys = "g h"
 396        command = "org.heading.up"
 397        mode = "normal"
 398        [[bind]]
 399        keys = "g j"
 400        command = "org.heading.forward-same-level"
 401        mode = "normal"
 402        [[bind]]
 403        keys = "g k"
 404        command = "org.heading.backward-same-level"
 405        mode = "normal"
 406        [[bind]]
 407        keys = "] h"
 408        command = "org.heading.forward-same-level"
 409        mode = "normal"
 410        [[bind]]
 411        keys = "[ h"
 412        command = "org.heading.backward-same-level"
 413        mode = "normal"
 414        [[bind]]
 415        keys = "RET"
 416        command = "org.table.next-row"
 417        when = "table"
 418        mode = "insert"
 419        [[bind]]
 420        keys = "TAB"
 421        command = "org.cycle"
 422        mode = "visual"
 423        [[bind]]
 424        keys = "S-TAB"
 425        command = "org.cycle-global"
 426        mode = "visual"
 427
 428        # Insert state: org-cycle and org-shifttab with Doom's +org-indent-maybe-h, which
 429        # demotes or promotes a heading and indents or outdents an item tree.
 430        [[bind]]
 431        keys = "S-TAB"
 432        command = "org.cycle-global"
 433        mode = "insert"
 434        [[bind]]
 435        keys = "TAB"
 436        command = "org.table.next-field"
 437        when = "table"
 438        mode = "insert"
 439        [[bind]]
 440        keys = "S-TAB"
 441        command = "org.table.previous-field"
 442        when = "table"
 443        mode = "insert"
 444        [[bind]]
 445        keys = "TAB"
 446        command = "org.item.indent-tree"
 447        when = "item"
 448        mode = "insert"
 449        [[bind]]
 450        keys = "S-TAB"
 451        command = "org.item.outdent-tree"
 452        when = "item"
 453        mode = "insert"
 454        [[bind]]
 455        keys = "TAB"
 456        command = "org.heading.demote"
 457        when = "heading"
 458        mode = "insert"
 459        [[bind]]
 460        keys = "S-TAB"
 461        command = "org.heading.promote"
 462        when = "heading"
 463        mode = "insert"
 464
 465        """
 466
 467
 468    static let common = """
 469        [[bind]]
 470        keys = "TAB"
 471        command = "org.cycle"
 472        when = "heading"
 473        [[bind]]
 474        keys = "TAB"
 475        command = "org.cycle"
 476        when = "fold-line"
 477
 478        [[bind]]
 479        keys = "S-TAB"
 480        command = "org.cycle-global"
 481        [[bind]]
 482        keys = "TAB"
 483        command = "org.table.next-field"
 484        when = "table"
 485        [[bind]]
 486        keys = "S-TAB"
 487        command = "org.table.previous-field"
 488        when = "table"
 489        [[bind]]
 490        keys = "RET"
 491        command = "org.table.next-row"
 492        when = "table"
 493
 494        """
 495
 496    static let emacsBindings = """
 497        # Movement and editing. With a mark set (C-SPC), movement extends the region.
 498        [[bind]]
 499        keys = "C-f"
 500        command = "edit.forward-char"
 501        [[bind]]
 502        keys = "C-b"
 503        command = "edit.backward-char"
 504        [[bind]]
 505        keys = "C-n"
 506        command = "edit.next-line"
 507        [[bind]]
 508        keys = "C-p"
 509        command = "edit.previous-line"
 510        [[bind]]
 511        keys = "C-a"
 512        command = "edit.beginning-of-line"
 513        [[bind]]
 514        keys = "C-e"
 515        command = "edit.end-of-line"
 516        [[bind]]
 517        keys = "M-f"
 518        command = "edit.forward-word"
 519        [[bind]]
 520        keys = "M-b"
 521        command = "edit.backward-word"
 522        [[bind]]
 523        keys = "M-<"
 524        command = "edit.beginning-of-buffer"
 525        [[bind]]
 526        keys = "M->"
 527        command = "edit.end-of-buffer"
 528        [[bind]]
 529        keys = "C-v"
 530        command = "edit.scroll-up"
 531        [[bind]]
 532        keys = "M-v"
 533        command = "edit.scroll-down"
 534        [[bind]]
 535        keys = "C-l"
 536        command = "edit.recenter"
 537        [[bind]]
 538        keys = "C-d"
 539        command = "edit.delete-char"
 540        [[bind]]
 541        keys = "M-d"
 542        command = "edit.kill-word"
 543        [[bind]]
 544        keys = "M-DEL"
 545        command = "edit.backward-kill-word"
 546        [[bind]]
 547        keys = "C-k"
 548        command = "edit.kill-line"
 549        [[bind]]
 550        keys = "C-y"
 551        command = "edit.yank"
 552        [[bind]]
 553        keys = "C-SPC"
 554        command = "edit.set-mark"
 555        [[bind]]
 556        keys = "C-x h"
 557        command = "edit.select-all"
 558        [[bind]]
 559        keys = "C-w"
 560        command = "edit.kill-region"
 561        [[bind]]
 562        keys = "M-w"
 563        command = "edit.copy-region"
 564        [[bind]]
 565        keys = "C-/"
 566        command = "edit.undo"
 567        [[bind]]
 568        keys = "C-_"
 569        command = "edit.undo"
 570        [[bind]]
 571        keys = "C-x u"
 572        command = "edit.undo"
 573        [[bind]]
 574        keys = "C-g"
 575        command = "edit.keyboard-quit"
 576        [[bind]]
 577        keys = "C-t"
 578        command = "edit.transpose-chars"
 579        [[bind]]
 580        keys = "C-s"
 581        command = "edit.find"
 582        [[bind]]
 583        keys = "C-r"
 584        command = "edit.find"
 585        [[bind]]
 586        keys = "M-%"
 587        command = "edit.replace"
 588
 589        # Files and commands
 590        [[bind]]
 591        keys = "C-x C-s"
 592        command = "app.save"
 593        [[bind]]
 594        keys = "C-c C-o"
 595        command = "org.link.open"
 596        [[bind]]
 597        keys = "C-c C-l"
 598        command = "org.link.insert"
 599        [[bind]]
 600        keys = "C-c l"
 601        command = "org.link.store"
 602        [[bind]]
 603        keys = "C-c ;"
 604        command = "org.heading.toggle-comment"
 605        [[bind]]
 606        keys = "C-c *"
 607        command = "org.heading.toggle"
 608        [[bind]]
 609        keys = "C-c -"
 610        command = "org.item.toggle"
 611        [[bind]]
 612        keys = "C-c @"
 613        command = "org.subtree.mark"
 614        [[bind]]
 615        keys = "C-c C-x C-w"
 616        command = "org.subtree.cut"
 617        [[bind]]
 618        keys = "C-c C-x M-w"
 619        command = "org.subtree.copy"
 620        [[bind]]
 621        keys = "C-c C-x C-y"
 622        command = "org.subtree.paste"
 623        [[bind]]
 624        keys = "C-c C-x c"
 625        command = "org.subtree.clone"
 626        [[bind]]
 627        keys = "C-c ^"
 628        command = "org.sort"
 629        [[bind]]
 630        keys = "C-x b"
 631        command = "app.buffer.switch"
 632        [[bind]]
 633        keys = "C-x C-b"
 634        command = "app.buffer.switch"
 635        [[bind]]
 636        keys = "C-x k"
 637        command = "app.buffer.kill"
 638        [[bind]]
 639        keys = "C-x <right>"
 640        command = "app.buffer.next"
 641        [[bind]]
 642        keys = "C-x <left>"
 643        command = "app.buffer.previous"
 644        [[bind]]
 645        keys = "C-x s"
 646        command = "app.save-all"
 647        [[bind]]
 648        keys = "C-x C-f"
 649        command = "app.quick-open"
 650        [[bind]]
 651        keys = "M-x"
 652        command = "app.palette"
 653        [[bind]]
 654        keys = "C-c a"
 655        command = "app.agenda"
 656        [[bind]]
 657        keys = "C-c c"
 658        command = "app.capture"
 659        [[bind]]
 660        keys = "C-c C-x C-i"
 661        command = "app.clock.in"
 662        [[bind]]
 663        keys = "C-c C-x C-o"
 664        command = "app.clock.out"
 665        [[bind]]
 666        keys = "C-c C-x C-q"
 667        command = "app.clock.cancel"
 668        [[bind]]
 669        keys = "C-c C-x C-j"
 670        command = "app.clock.goto"
 671        [[bind]]
 672        keys = "C-c C-e h h"
 673        command = "app.export.html"
 674        [[bind]]
 675        keys = "C-c C-e h o"
 676        command = "app.export.html-open"
 677        [[bind]]
 678        keys = "C-c C-e m m"
 679        command = "app.export.markdown"
 680        [[bind]]
 681        keys = "C-c C-e l p"
 682        command = "app.export.pdf"
 683        [[bind]]
 684        keys = "C-c C-e l l"
 685        command = "app.export.latex"
 686        [[bind]]
 687        keys = "C-c C-e o o"
 688        command = "app.export.odt"
 689        [[bind]]
 690        keys = "C-c C-e t u"
 691        command = "app.export.text"
 692
 693        # Org
 694        [[bind]]
 695        keys = "C-c C-t"
 696        command = "org.todo.cycle"
 697        [[bind]]
 698        keys = "S-<right>"
 699        command = "org.todo.next"
 700        when = "heading"
 701        [[bind]]
 702        keys = "S-<left>"
 703        command = "org.todo.previous"
 704        when = "heading"
 705        [[bind]]
 706        keys = "S-<up>"
 707        command = "org.priority.up"
 708        when = "heading"
 709        [[bind]]
 710        keys = "S-<down>"
 711        command = "org.priority.down"
 712        when = "heading"
 713        [[bind]]
 714        keys = "M-<left>"
 715        command = "org.heading.promote"
 716        when = "heading"
 717        [[bind]]
 718        keys = "M-<right>"
 719        command = "org.heading.demote"
 720        when = "heading"
 721        [[bind]]
 722        keys = "M-S-<left>"
 723        command = "org.subtree.promote"
 724        when = "heading"
 725        [[bind]]
 726        keys = "M-S-<right>"
 727        command = "org.subtree.demote"
 728        when = "heading"
 729        [[bind]]
 730        keys = "M-<up>"
 731        command = "org.subtree.up"
 732        when = "heading"
 733        [[bind]]
 734        keys = "M-<down>"
 735        command = "org.subtree.down"
 736        when = "heading"
 737        [[bind]]
 738        keys = "M-RET"
 739        command = "org.heading.insert"
 740        [[bind]]
 741        keys = "C-RET"
 742        command = "org.heading.insert-after-subtree"
 743        [[bind]]
 744        keys = "M-S-RET"
 745        command = "org.heading.insert-todo"
 746        [[bind]]
 747        keys = "C-c C-n"
 748        command = "org.heading.next"
 749        [[bind]]
 750        keys = "C-c C-p"
 751        command = "org.heading.previous"
 752        [[bind]]
 753        keys = "C-c C-f"
 754        command = "org.heading.forward-same-level"
 755        [[bind]]
 756        keys = "C-c C-b"
 757        command = "org.heading.backward-same-level"
 758        [[bind]]
 759        keys = "C-c C-u"
 760        command = "org.heading.up"
 761        [[bind]]
 762        keys = "C-c C-q"
 763        command = "org.tags.set"
 764        [[bind]]
 765        keys = "M-RET"
 766        command = "org.item.insert"
 767        when = "item"
 768        [[bind]]
 769        keys = "M-S-RET"
 770        command = "org.item.insert-checkbox"
 771        when = "item"
 772        [[bind]]
 773        keys = "M-<left>"
 774        command = "org.item.outdent"
 775        when = "item"
 776        [[bind]]
 777        keys = "M-<right>"
 778        command = "org.item.indent"
 779        when = "item"
 780        [[bind]]
 781        keys = "M-S-<left>"
 782        command = "org.item.outdent-tree"
 783        when = "item"
 784        [[bind]]
 785        keys = "M-S-<right>"
 786        command = "org.item.indent-tree"
 787        when = "item"
 788        [[bind]]
 789        keys = "M-<up>"
 790        command = "org.item.up"
 791        when = "item"
 792        [[bind]]
 793        keys = "M-<down>"
 794        command = "org.item.down"
 795        when = "item"
 796        [[bind]]
 797        keys = "C-c C-c"
 798        command = "org.checkbox.toggle"
 799        when = "item"
 800        [[bind]]
 801        keys = "C-c C-x C-b"
 802        command = "org.checkbox.toggle"
 803        [[bind]]
 804        keys = "C-c C-w"
 805        command = "app.refile"
 806        [[bind]]
 807        keys = "C-c C-x C-s"
 808        command = "app.archive"
 809        [[bind]]
 810        keys = "C-c $"
 811        command = "app.archive"
 812        [[bind]]
 813        keys = "C-c ."
 814        command = "org.timestamp.active"
 815        [[bind]]
 816        keys = "C-c !"
 817        command = "org.timestamp.inactive"
 818        [[bind]]
 819        keys = "C-c C-s"
 820        command = "org.schedule"
 821        [[bind]]
 822        keys = "C-c C-d"
 823        command = "org.deadline"
 824        [[bind]]
 825        keys = "M-q"
 826        command = "org.fill-paragraph"
 827        [[bind]]
 828        keys = "C-c C-c"
 829        command = "org.table.align"
 830        when = "table"
 831        [[bind]]
 832        keys = "C-c C-c"
 833        command = "org.table.recalc-all"
 834        when = "tblfm"
 835        [[bind]]
 836        keys = "C-c *"
 837        command = "org.table.recalc"
 838        when = "table"
 839        [[bind]]
 840        keys = "C-c C-c"
 841        command = "org.babel.execute"
 842        when = "src"
 843        [[bind]]
 844        keys = "M-<up>"
 845        command = "org.table.row-up"
 846        when = "table"
 847        [[bind]]
 848        keys = "M-<down>"
 849        command = "org.table.row-down"
 850        when = "table"
 851        [[bind]]
 852        keys = "M-<left>"
 853        command = "org.table.column-left"
 854        when = "table"
 855        [[bind]]
 856        keys = "M-<right>"
 857        command = "org.table.column-right"
 858        when = "table"
 859        [[bind]]
 860        keys = "M-S-<right>"
 861        command = "org.table.insert-column"
 862        when = "table"
 863        [[bind]]
 864        keys = "M-S-<left>"
 865        command = "org.table.delete-column"
 866        when = "table"
 867        [[bind]]
 868        keys = "M-S-<up>"
 869        command = "org.table.kill-row"
 870        when = "table"
 871        [[bind]]
 872        keys = "M-S-<down>"
 873        command = "org.table.insert-row"
 874        when = "table"
 875        [[bind]]
 876        keys = "C-c -"
 877        command = "org.table.insert-hline"
 878        when = "table"
 879        [[bind]]
 880        keys = "C-c |"
 881        command = "org.table.create"
 882        [[bind]]
 883        keys = "S-<up>"
 884        command = "org.timestamp.up"
 885        when = "timestamp"
 886        [[bind]]
 887        keys = "S-<down>"
 888        command = "org.timestamp.down"
 889        when = "timestamp"
 890        [[bind]]
 891        keys = "S-<right>"
 892        command = "org.timestamp.day-later"
 893        when = "timestamp"
 894        [[bind]]
 895        keys = "S-<left>"
 896        command = "org.timestamp.day-earlier"
 897        when = "timestamp"
 898
 899        """
 900
 901    /// Standard Mac text keys stay as they are; org commands use Control-Command chords, which
 902    /// macOS text editing leaves free.
 903    static let macBindings = """
 904        [[bind]]
 905        keys = "C-TAB"
 906        command = "app.buffer.next"
 907        [[bind]]
 908        keys = "C-S-TAB"
 909        command = "app.buffer.previous"
 910        [[bind]]
 911        keys = "C-s-t"
 912        command = "org.todo.cycle"
 913        [[bind]]
 914        keys = "C-s-<up>"
 915        command = "org.priority.up"
 916        [[bind]]
 917        keys = "C-s-<down>"
 918        command = "org.priority.down"
 919        [[bind]]
 920        keys = "C-s-<left>"
 921        command = "org.heading.promote"
 922        [[bind]]
 923        keys = "C-s-<right>"
 924        command = "org.heading.demote"
 925        [[bind]]
 926        keys = "C-M-s-<left>"
 927        command = "org.subtree.promote"
 928        [[bind]]
 929        keys = "C-M-s-<right>"
 930        command = "org.subtree.demote"
 931        [[bind]]
 932        keys = "C-M-s-<up>"
 933        command = "org.subtree.up"
 934        [[bind]]
 935        keys = "C-M-s-<down>"
 936        command = "org.subtree.down"
 937        [[bind]]
 938        keys = "s-RET"
 939        command = "org.heading.insert"
 940        [[bind]]
 941        keys = "C-s-RET"
 942        command = "org.heading.insert-after-subtree"
 943        [[bind]]
 944        keys = "s-S-RET"
 945        command = "org.heading.insert-todo"
 946        [[bind]]
 947        keys = "M-s-<down>"
 948        command = "org.heading.next"
 949        [[bind]]
 950        keys = "M-s-<up>"
 951        command = "org.heading.previous"
 952        [[bind]]
 953        keys = "C-s-q"
 954        command = "org.tags.set"
 955        [[bind]]
 956        keys = "s-RET"
 957        command = "org.item.insert"
 958        when = "item"
 959        [[bind]]
 960        keys = "s-S-RET"
 961        command = "org.item.insert-checkbox"
 962        when = "item"
 963        [[bind]]
 964        keys = "C-s-<left>"
 965        command = "org.item.outdent"
 966        when = "item"
 967        [[bind]]
 968        keys = "C-s-<right>"
 969        command = "org.item.indent"
 970        when = "item"
 971        [[bind]]
 972        keys = "C-M-s-<left>"
 973        command = "org.item.outdent-tree"
 974        when = "item"
 975        [[bind]]
 976        keys = "C-M-s-<right>"
 977        command = "org.item.indent-tree"
 978        when = "item"
 979        [[bind]]
 980        keys = "C-M-s-<up>"
 981        command = "org.item.up"
 982        when = "item"
 983        [[bind]]
 984        keys = "C-M-s-<down>"
 985        command = "org.item.down"
 986        when = "item"
 987        [[bind]]
 988        keys = "C-s-c"
 989        command = "org.checkbox.toggle"
 990        [[bind]]
 991        keys = "C-s-w"
 992        command = "app.refile"
 993        [[bind]]
 994        keys = "C-s-a"
 995        command = "app.archive"
 996        [[bind]]
 997        keys = "C-s-."
 998        command = "org.timestamp.active"
 999        [[bind]]
1000        keys = "C-M-s-."
1001        command = "org.timestamp.inactive"
1002        [[bind]]
1003        keys = "C-s-s"
1004        command = "org.schedule"
1005        [[bind]]
1006        keys = "C-s-d"
1007        command = "org.deadline"
1008        [[bind]]
1009        keys = "C-s-p"
1010        command = "org.fill-paragraph"
1011        [[bind]]
1012        keys = "C-s-<up>"
1013        command = "org.table.row-up"
1014        when = "table"
1015        [[bind]]
1016        keys = "C-s-<down>"
1017        command = "org.table.row-down"
1018        when = "table"
1019        [[bind]]
1020        keys = "C-s-<left>"
1021        command = "org.table.column-left"
1022        when = "table"
1023        [[bind]]
1024        keys = "C-s-<right>"
1025        command = "org.table.column-right"
1026        when = "table"
1027        [[bind]]
1028        keys = "C-M-s-<right>"
1029        command = "org.table.insert-column"
1030        when = "table"
1031        [[bind]]
1032        keys = "C-M-s-<left>"
1033        command = "org.table.delete-column"
1034        when = "table"
1035        [[bind]]
1036        keys = "C-M-s-<up>"
1037        command = "org.table.kill-row"
1038        when = "table"
1039        [[bind]]
1040        keys = "C-M-s-<down>"
1041        command = "org.table.insert-row"
1042        when = "table"
1043        [[bind]]
1044        keys = "C-s--"
1045        command = "org.table.insert-hline"
1046        when = "table"
1047        [[bind]]
1048        keys = "C-s-\\\\"
1049        command = "org.table.create"
1050        [[bind]]
1051        keys = "C-s-<up>"
1052        command = "org.timestamp.up"
1053        when = "timestamp"
1054        [[bind]]
1055        keys = "C-s-<down>"
1056        command = "org.timestamp.down"
1057        when = "timestamp"
1058        [[bind]]
1059        keys = "C-s-<right>"
1060        command = "org.timestamp.day-later"
1061        when = "timestamp"
1062        [[bind]]
1063        keys = "C-s-<left>"
1064        command = "org.timestamp.day-earlier"
1065        when = "timestamp"
1066
1067        """
1068}
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