Sources/OrgCore/Keymap/Presets.swift

1d5593eadf032a1cc3c0eb3230ceecd7e4fc151c
orgstar/Sources/OrgCore/Keymap/Presets.swift

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