Skip to content

Commit 036cdfd

Browse files
Strackeror71karimknaebel
authored
misc: add Helix keymap (#338)
* Behavior choice: Basic helix keymap * Behavior choice: Helix keymap as an extension * Fix shift+c in helix modes Remove category field from package.json * Fix missing editorTextFocus condition * Add `%` binding to helix * Fix binding: `Shift+R` * PR Fixes * Fix typos and title, add toggle indices * Add numpad bindings to select mode * PR Fixes * Improve keybind parsing for less verbose definitions * use symlinks * Fix invalid pre-release version string It's not consistent, but vscode sometimes gives me errors about the semver for the helix package not being valid, and indeed it seems leading zeroes are not valid semver, so switching to a tag to mark the prerelease * fix go to menu items * Keymap: Add switch back to normal mode on some keybinds * remove symlinks And: - Update LICENSE to ~2025. - Add purple Dance logo for Helix. --------- Co-authored-by: Grégoire Geis <opensource@gregoirege.is> Co-authored-by: Karim Abou Zeid <7303830+kabouzeid@users.noreply.github.com>
1 parent 7bf1463 commit 036cdfd

26 files changed

Lines changed: 4448 additions & 2007 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
/src/commands/load-all.ts linguist-generated
44
/src/commands/README.md linguist-generated
55
/package.json linguist-generated
6+
/extensions/helix/package.json linguist-generated
67
/test/suite/api.test.ts linguist-generated
78
/test/suite/commands/*.test.ts linguist-generated

.vscode/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
1010
"outFiles": ["${workspaceFolder}/out/**/*.js"],
1111
},
12+
{
13+
"name": "Launch extension with Helix keybindings",
14+
"type": "extensionHost",
15+
"request": "launch",
16+
"runtimeExecutable": "${execPath}",
17+
"args": [
18+
"--extensionDevelopmentPath=${workspaceFolder}",
19+
"--extensionDevelopmentPath=${workspaceFolder}/extensions/helix/",
20+
],
21+
"outFiles": ["${workspaceFolder}/out/**/*.js"],
22+
},
1223
{
1324
"name": "Run all tests",
1425
"type": "extensionHost",

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2020-2021 Grégoire Geis
1+
Copyright 2020-2025 Grégoire Geis
22

33
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
44

extensions/helix/LICENSE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright 2020-2025 Grégoire Geis
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4+
5+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

extensions/helix/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Dance - Helix keybindings
2+
3+
Helix keybindings for VS Code based on [Dance](https://github.com/71/dance).

extensions/helix/assets/dance.png

134 KB
Loading

extensions/helix/package.build.ts

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
// Save to package.json
2+
// ============================================================================
3+
4+
import { Builder, generateIgnoredKeybinds } from "../../meta";
5+
import * as fs from "fs/promises";
6+
import { extensionId } from "../../src/utils/constants";
7+
8+
const version = "0.1.0",
9+
preRelease = 1,
10+
preReleaseVersion = `${version}-pre${preRelease}`;
11+
12+
export const pkg = (modules: Builder.ParsedModule[]) => ({
13+
14+
// Common package.json properties.
15+
// ==========================================================================
16+
17+
name: "dance-helix-keybindings",
18+
description: "Helix keybindings for Dance",
19+
version,
20+
license: "ISC",
21+
extensionDependencies: [extensionId],
22+
author: {
23+
name: "Grégoire Geis",
24+
email: "opensource@gregoirege.is",
25+
},
26+
27+
contributors: [
28+
{
29+
name: "Rémi Lavergne",
30+
url: "https://github.com/Strackeror",
31+
},
32+
],
33+
34+
repository: {
35+
type: "git",
36+
url: "https://github.com/71/dance.git",
37+
},
38+
39+
engines: {
40+
vscode: "^1.63.0",
41+
},
42+
43+
displayName: "Dance (Helix keybindings)",
44+
publisher: "gregoire",
45+
categories: ["Keymaps", "Other"],
46+
readme: "README.md",
47+
icon: "assets/dance.png",
48+
extensionKind: ["ui", "workspace"],
49+
50+
scripts: {
51+
"package": "vsce package --allow-star-activation",
52+
"publish": "vsce publish --allow-star-activation",
53+
"package:pre": `vsce package --allow-star-activation --pre-release --no-git-tag-version --no-update-package-json ${preReleaseVersion}`,
54+
"publish:pre": `vsce publish --allow-star-activation --pre-release --no-git-tag-version --no-update-package-json ${preReleaseVersion}`,
55+
},
56+
57+
contributes: {
58+
configurationDefaults: {
59+
"dance.defaultMode": "helix/normal",
60+
"dance.modes": {
61+
"helix/insert": {
62+
onLeaveMode: [
63+
[".selections.save", {
64+
register: " insert",
65+
}],
66+
],
67+
},
68+
"helix/select": {
69+
cursorStyle: "block",
70+
selectionBehavior: "character",
71+
},
72+
"helix/normal": {
73+
cursorStyle: "block",
74+
selectionBehavior: "character",
75+
decorations: {
76+
applyTo: "main",
77+
backgroundColor: "$editor.hoverHighlightBackground",
78+
isWholeLine: true,
79+
},
80+
onEnterMode: [
81+
[".selections.restore", { register: " ^", try: true }],
82+
],
83+
onLeaveMode: [
84+
[".selections.save", {
85+
register: " ^",
86+
style: {
87+
borderColor: "$editor.selectionBackground",
88+
borderStyle: "solid",
89+
borderWidth: "2px",
90+
borderRadius: "1px",
91+
},
92+
until: [
93+
["mode-did-change", { include: "normal" }],
94+
["selections-did-change"],
95+
],
96+
}],
97+
],
98+
},
99+
},
100+
101+
"dance.menus": {
102+
match: {
103+
title: "Match",
104+
items: {
105+
// Should be jump in normal mode, extend in select mode, but jump for seek.enclosing is not implemented
106+
"m": { command: "dance.seek.enclosing", text: "Goto matching bracket" },
107+
"a": { command: "dance.openMenu", args: [{ menu: "object", title: "Match around" }], text: "Select around object" },
108+
"i": { command: "dance.openMenu", args: [{ menu: "object", title: "Match inside", pass: [{ inner: true }] }], text: "Select inside object" },
109+
},
110+
},
111+
112+
object: {
113+
title: "Select object...",
114+
items: ((command = "dance.seek.object") => ({
115+
"()": { command, args: [{ input: "\\((?#inner)\\)" }], text: "parenthesis block" },
116+
"{}": { command, args: [{ input: "\\{(?#inner)\\}" }], text: "braces block" },
117+
"[]": { command, args: [{ input: "\\[(?#inner)\\]" }], text: "brackets block" },
118+
"<>": { command, args: [{ input: "<(?#inner)>" }], text: "angle block" },
119+
'"': { command, args: [{ input: "(?#noescape)\"(?#inner)(?#noescape)\"" }], text: "double quote string" },
120+
"'": { command, args: [{ input: "(?#noescape)'(?#inner)(?#noescape)'" }], text: "single quote string" },
121+
"`": { command, args: [{ input: "(?#noescape)`(?#inner)(?#noescape)`" }], text: "grave quote string" },
122+
"w": { command, args: [{ input: "[\\p{L}_\\d]+(?<after>[^\\S\\n]+)" }], text: "word" },
123+
"W": { command, args: [{ input: "[\\S]+(?<after>[^\\S\\n]+)" }], text: "WORD" },
124+
"p": { command, args: [{ input: "(?#predefined=paragraph)" }], text: "paragraph" },
125+
"a": { command, args: [{ input: "(?#predefined=argument)" }], text: "argument" },
126+
"!": { command, text: "custom object desc" },
127+
}))(),
128+
},
129+
130+
view: {
131+
"title": "View",
132+
"items": {
133+
"cz": { text: "Align view center", command: "dance.view.line", args: [{ "at": "center" }] },
134+
"t": { text: "Align view top", command: "dance.view.line", args: [{ "at": "top" }] },
135+
"b": { text: "Align view bottom", command: "dance.view.line", args: [{ "at": "bottom" }] },
136+
"k": { text: "Scroll view up", command: "editorScroll", args: [{ "by": "line", "revealCursor": true, "to": "up" }] },
137+
"j": { text: "Scroll view down", command: "editorScroll", args: [{ "by": "line", "revealCursor": true, "to": "down" }] },
138+
"/": { text: "Search for regex pattern", command: "dance.search" },
139+
"?": { text: "Reverse search for regex pattern", command: "dance.search.backward" },
140+
"n": { text: "Select next search match", command: "dance.search.next" },
141+
"N": { text: "Select previous search match", command: "dance.search.previous" },
142+
},
143+
},
144+
145+
goto: {
146+
title: "Goto",
147+
items: {
148+
"g": { text: "to line number else file start", command: "dance.select.lineStart", "args": [{ "count": 1 }] },
149+
"e": { text: "to last line", command: "dance.select.lineEnd", args: [{ count: 2 ** 31 - 1 }] },
150+
"f": { text: "to file/URLs in selections", command: "dance.selections.open" },
151+
"h": { text: "to line start", command: "dance.select.lineStart" },
152+
"l": { text: "to line end", command: "dance.select.lineEnd" },
153+
"s": { text: "to first non-blank in line", command: "dance.select.lineStart", args: [{ skipBlank: true }] },
154+
"d": { text: "to definition", command: "editor.action.revealDefinition" },
155+
"r": { text: "to references", command: "editor.action.goToReferences" },
156+
"j": { text: "to last line", command: "dance.select.lastLine" },
157+
"t": { text: "to window top", command: "dance.select.firstVisibleLine" },
158+
"c": { text: "to window center", command: "dance.select.middleVisibleLine" },
159+
"b": { text: "to window bottom", command: "dance.select.lastVisibleLine" },
160+
"a": { text: "to last buffer", command: "workbench.action.openPreviousRecentlyUsedEditorInGroup" },
161+
"A": { text: "to last buffer...", command: "workbench.action.quickOpenPreviousRecentlyUsedEditorInGroup" },
162+
"n": { text: "to next buffer", command: "workbench.action.nextEditor" },
163+
"p": { text: "to previous buffer", command: "workbench.action.previousEditor" },
164+
".": { text: "to last buffer modification position", command: "dance.selections.restore", args: [{ register: " insert" }],
165+
},
166+
},
167+
},
168+
},
169+
},
170+
171+
keybindings: (() => {
172+
const ignoredKeybindings = [],
173+
keybindings = modules
174+
.flatMap((module) => module.keybindings)
175+
.filter((keybinding) => ["core", "helix", undefined].includes(keybinding.category))
176+
.map(({ category, ...kb }) => kb);
177+
178+
for (const mode of ["normal", "select", "insert"]) {
179+
for (const keybind of keybindings) {
180+
keybind.when = keybind.when.replace(`dance.mode == '${mode}'`, `dance.mode == 'helix/${mode}'`);
181+
}
182+
}
183+
184+
for (const mode of ["normal", "select"]) {
185+
const whenMode = `editorTextFocus && dance.mode == 'helix/${mode}'`;
186+
ignoredKeybindings.push(...generateIgnoredKeybinds(
187+
keybindings.filter(key => key.when.includes(whenMode)),
188+
whenMode,
189+
));
190+
}
191+
192+
return [
193+
...keybindings,
194+
...ignoredKeybindings,
195+
];
196+
})(),
197+
},
198+
});
199+
200+
201+
export async function build(builder: Builder) {
202+
await fs.writeFile(
203+
`${__dirname}/package.json`,
204+
JSON.stringify(pkg(await builder.getCommandModules()), undefined, 2) + "\n",
205+
"utf-8",
206+
);
207+
}

0 commit comments

Comments
 (0)