Skip to content

Commit

Permalink
📝 [docs] Update leader key example to use one variable
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-liu committed Feb 14, 2025
1 parent f3ca994 commit 5500fac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
8 changes: 5 additions & 3 deletions examples/vim/nested-leader-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
title: Nested leader key
---

To nest leader keys, use variables on [leaderMode()](/rules/leader-mode).
To nest leader keys, use a variables:

- `leader` `o` `f`: Open Finder
- `leader` `r` `e`: Raycast Emoji Picker
- Set the variable on the leader key
- Set the variable to different value on each nested leader key
- Unset the variable on all action keys and escape key(s)
- (optional) Use notification for hints
53 changes: 34 additions & 19 deletions examples/vim/nested-leader-key.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
import {
hyperLayer,
ifVar,
map,
rule,
toRemoveNotificationMessage,
toUnsetVar,
withCondition,
withMapper,
} from '../../src'

let escapeLeader = ['__layer', 'leader', 'leader--'].map(toUnsetVar)
let raycastEmoji = 'emoji-symbols/search-emoji-symbols'
let raycastEmoji = 'raycast/emoji-symbols/search-emoji-symbols'
let escape = [toUnsetVar('leader'), toRemoveNotificationMessage('leader')]

let rules = [
hyperLayer('l', 'leader')
.leaderMode({ sticky: true, escape: [] })
.manipulators([
map('escape').to(escapeLeader),
rule('Leader Key').manipulators([
map('l', 'Hyper') // Or mapSimultaneous(['l', ';']) ...
.toVar('leader')
.toNotificationMessage('leader', 'Leader Key: Open, Raycast, ...'),

map('o').toVar('leader--', 'o'), // Open
withCondition(ifVar('leader--', 'o'))([
withMapper([
map('f').toApp('Finder'), // Open Finder
])((x) => x.to(escapeLeader)),
]),
withCondition(ifVar('leader', 0).unless())([
// Escape key(s)
map('escape').to(escape),

map('r').toVar('leader--', 'r'), // Raycast
withCondition(ifVar('leader--', 'r'))([
withMapper([
map('e').to$(`open raycast://extensions/raycast/${raycastEmoji}`),
])((x) => x.to(escapeLeader)),
]),
// Nested leader keys
withMapper(['o', 'r'])((x) =>
map(x)
.toVar('leader', x)
.toNotificationMessage('leader', `leader ${x}`),
),

// o - Open
withCondition(ifVar('leader', 'o'))(
[
map('f').toApp('Finder'),
// f - Finder, ...
].map((x) => x.to(escape)),
),

// r - Raycast
withCondition(ifVar('leader', 'r'))(
[
map('e').to$(`open raycast://extensions/${raycastEmoji}`),
// e - Emoji, ...
].map((x) => x.to(escape)),
),
]),
]),
]

0 comments on commit 5500fac

Please sign in to comment.