pi-vim 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +243 -0
- package/index.ts +1395 -0
- package/motions.ts +125 -0
- package/package.json +40 -0
- package/types.ts +49 -0
- package/word-boundary-cache.ts +180 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lajarre
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# vim-bindings — Pi REPL Vim Mode
|
|
2
|
+
|
|
3
|
+
A modal vim-like editing extension for Pi's REPL prompt, covering the
|
|
4
|
+
high-frequency ("90%") command surface without trying to clone full Vim.
|
|
5
|
+
|
|
6
|
+
## Loading
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
pi --extension /path/to/vim-bindings/index.ts
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Or add to `.pi/settings.json`:
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{
|
|
16
|
+
"extensions": ["./pi-extensions/vim-bindings/index.ts"]
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The mode indicator (`INSERT` / `NORMAL`) is shown in the bottom-right corner
|
|
21
|
+
of the prompt.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Supported command surface
|
|
26
|
+
|
|
27
|
+
### Mode switching
|
|
28
|
+
|
|
29
|
+
| Key | Action |
|
|
30
|
+
|----------|----------------------------------------|
|
|
31
|
+
| `Esc` | Insert → Normal mode |
|
|
32
|
+
| `Esc` | Normal mode → pass to Pi (abort agent) |
|
|
33
|
+
| `i` | Normal → Insert at cursor |
|
|
34
|
+
| `a` | Normal → Insert after cursor |
|
|
35
|
+
| `I` | Normal → Insert at line start |
|
|
36
|
+
| `A` | Normal → Insert at line end |
|
|
37
|
+
| `o` | Normal → open line below + Insert |
|
|
38
|
+
| `O` | Normal → open line above + Insert |
|
|
39
|
+
|
|
40
|
+
Insert-mode shortcuts (stay in Insert mode):
|
|
41
|
+
|
|
42
|
+
| Key | Action |
|
|
43
|
+
|-----------------|------------------------|
|
|
44
|
+
| `Shift+Alt+A` | Go to end of line |
|
|
45
|
+
| `Shift+Alt+I` | Go to start of line |
|
|
46
|
+
| `Alt+o` | Open line below |
|
|
47
|
+
| `Alt+Shift+O` | Open line above |
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
### Navigation (Normal mode)
|
|
52
|
+
|
|
53
|
+
| Key | Action |
|
|
54
|
+
|-------|-------------------------|
|
|
55
|
+
| `h` | Left |
|
|
56
|
+
| `l` | Right |
|
|
57
|
+
| `j` | Down |
|
|
58
|
+
| `k` | Up |
|
|
59
|
+
| `0` | Line start |
|
|
60
|
+
| `$` | Line end |
|
|
61
|
+
| `gg` | Buffer start (line 1) |
|
|
62
|
+
| `G` | Buffer end (last line) |
|
|
63
|
+
| `w` | Next word start |
|
|
64
|
+
| `b` | Previous word start |
|
|
65
|
+
| `e` | Word end (inclusive) |
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### Character-find motions (Normal mode)
|
|
70
|
+
|
|
71
|
+
| Key | Action |
|
|
72
|
+
|------------|------------------------------------------------|
|
|
73
|
+
| `f{char}` | Jump forward to `char` (inclusive) |
|
|
74
|
+
| `F{char}` | Jump backward to `char` (inclusive) |
|
|
75
|
+
| `t{char}` | Jump forward to one before `char` (exclusive) |
|
|
76
|
+
| `T{char}` | Jump backward to one after `char` (exclusive) |
|
|
77
|
+
| `;` | Repeat last `f/F/t/T` motion |
|
|
78
|
+
| `,` | Repeat last motion in reverse direction |
|
|
79
|
+
|
|
80
|
+
Char-find motions compose with operators: `df{char}`, `ct{char}`, etc.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
### Edit operators (Normal mode)
|
|
85
|
+
|
|
86
|
+
All operators write to the unnamed register and mirror to the system clipboard
|
|
87
|
+
(best-effort; clipboard failure never breaks editing).
|
|
88
|
+
|
|
89
|
+
#### Delete `d{motion}` / `dd`
|
|
90
|
+
|
|
91
|
+
| Command | Deletes |
|
|
92
|
+
|------------|---------------------------------------------|
|
|
93
|
+
| `dw` | Forward to next word start (exclusive, can cross lines) |
|
|
94
|
+
| `de` | Forward to word end (inclusive, can cross lines) |
|
|
95
|
+
| `db` | Backward to word start (exclusive, can cross lines) |
|
|
96
|
+
| `d$` | To end of line |
|
|
97
|
+
| `d0` | To start of line |
|
|
98
|
+
| `dd` | Current line (linewise) |
|
|
99
|
+
| `{count}dd` | `{count}` lines (linewise) |
|
|
100
|
+
| `d{count}j` | Current line + `{count}` lines below (linewise) |
|
|
101
|
+
| `d{count}k` | Current line + `{count}` lines above (linewise) |
|
|
102
|
+
| `dG` | Current line to end of buffer (linewise) |
|
|
103
|
+
| `df{char}` | To and including `char` |
|
|
104
|
+
| `dt{char}` | Up to (not including) `char` |
|
|
105
|
+
| `dF{char}` | Backward to and including `char` |
|
|
106
|
+
| `dT{char}` | Backward to one after `char` |
|
|
107
|
+
| `diw` | Inner word |
|
|
108
|
+
| `daw` | Around word (includes surrounding spaces) |
|
|
109
|
+
|
|
110
|
+
#### Change `c{motion}` / `cc`
|
|
111
|
+
|
|
112
|
+
Same motion set as `d`. Deletes text then enters Insert mode.
|
|
113
|
+
|
|
114
|
+
| Command | Alias |
|
|
115
|
+
|---------|-------|
|
|
116
|
+
| `cw` | delete word + Insert |
|
|
117
|
+
| `ciw` | change inner word |
|
|
118
|
+
| `caw` | change around word |
|
|
119
|
+
| `cc` | delete line + Insert |
|
|
120
|
+
| `c$` | delete to EOL + Insert |
|
|
121
|
+
| … | all `d` motions apply |
|
|
122
|
+
|
|
123
|
+
#### Single-key edits
|
|
124
|
+
|
|
125
|
+
| Key | Action |
|
|
126
|
+
|-----|----------------------------------------------|
|
|
127
|
+
| `x` | Delete char under cursor (no-op at/past EOL) |
|
|
128
|
+
| `s` | Delete char under cursor + Insert mode |
|
|
129
|
+
| `S` | Delete line content + Insert mode |
|
|
130
|
+
| `D` | Delete cursor to EOL (captures `\n` if at EOL with next line) |
|
|
131
|
+
| `C` | Delete cursor to EOL + Insert mode |
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### Yank `y{motion}` / `yy`
|
|
136
|
+
|
|
137
|
+
Same motion set as `d`. Writes to register, **no text mutation**.
|
|
138
|
+
|
|
139
|
+
| Command | Yanks |
|
|
140
|
+
|---------|---------------------------------|
|
|
141
|
+
| `yy` | Whole line + trailing `\n` |
|
|
142
|
+
| `{count}yy` | `{count}` whole lines + trailing `\n` |
|
|
143
|
+
| `y{count}j` | Current line + `{count}` lines below (linewise) |
|
|
144
|
+
| `y{count}k` | Current line + `{count}` lines above (linewise) |
|
|
145
|
+
| `yG` | Current line to end of buffer (linewise) |
|
|
146
|
+
| `yw` | Forward to next word start |
|
|
147
|
+
| `ye` | To word end (inclusive) |
|
|
148
|
+
| `yb` | Backward to word start |
|
|
149
|
+
| `y$` | To end of line |
|
|
150
|
+
| `y0` | To start of line |
|
|
151
|
+
| `yf{c}` | To and including `char` |
|
|
152
|
+
| `yiw` | Inner word |
|
|
153
|
+
| `yaw` | Around word (includes spaces) |
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
### Put / Paste
|
|
158
|
+
|
|
159
|
+
| Key | Action |
|
|
160
|
+
|-----|-------------------------------------------------------------|
|
|
161
|
+
| `p` | Put after cursor (char-wise) / new line below (line-wise) |
|
|
162
|
+
| `P` | Put before cursor (char-wise) / new line above (line-wise) |
|
|
163
|
+
|
|
164
|
+
Put reads from the **unnamed register** (not OS clipboard).
|
|
165
|
+
Line-wise detection: register content ending in `\n` is treated as line-wise.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
### Undo
|
|
170
|
+
|
|
171
|
+
| Key | Action |
|
|
172
|
+
|-----|-------------------------------------------------|
|
|
173
|
+
| `u` | Undo — sends `ctrl+_` (`\x1f`) to the underlying readline editor |
|
|
174
|
+
|
|
175
|
+
Redo (`<C-r>`) is **not implemented** — see [Out of scope](#out-of-scope).
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Register and clipboard policy
|
|
180
|
+
|
|
181
|
+
- One unnamed register (like Vim's `""` register).
|
|
182
|
+
- Every `d`, `c`, `x`, `s`, `S`, `D`, `C`, `y` operator form
|
|
183
|
+
(including `dd`, `{count}dd`, `d{count}j/k`, `dG`, `yy`, `{count}yy`,
|
|
184
|
+
`y{count}j/k`, `yG`) writes to the register and mirrors to the OS clipboard
|
|
185
|
+
(via `copyToClipboard`, best-effort).
|
|
186
|
+
- `p` / `P` read from the unnamed register only (not the OS clipboard).
|
|
187
|
+
- This gives stable behaviour across local terminals and SSH / OSC52 setups.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Known differences from full Vim
|
|
192
|
+
|
|
193
|
+
| Area | This extension | Full Vim |
|
|
194
|
+
|-----------------------|----------------------------------------|-------------------------------|
|
|
195
|
+
| `$` motion | Moves past last char (readline CTRL+E) | Moves to last char |
|
|
196
|
+
| `w` / `e` / `b` | Cross-line for word motions | Cross-line |
|
|
197
|
+
| `0` / `$` operators | Exclusive of anchor col | `0` inclusive of col 0 |
|
|
198
|
+
| Undo depth | Delegates to underlying readline undo | Full per-change undo tree |
|
|
199
|
+
| Redo | Not implemented | `<C-r>` |
|
|
200
|
+
| Visual mode | Not implemented | `v`, `V`, `<C-v>` |
|
|
201
|
+
| Text objects | Supports `iw`/`aw` only | Full text-object set |
|
|
202
|
+
| Count prefix | Partial: linewise `dd`/`yy` and `d/y{count}j/k` only | Supported |
|
|
203
|
+
| Named registers | Not implemented (`"a`, etc.) | Supported |
|
|
204
|
+
| Macros | Not implemented (`q`, `@`) | Supported |
|
|
205
|
+
| Search | Not implemented (`/`, `?`, `n`, `N`) | Supported |
|
|
206
|
+
| Ex commands | Not implemented (`:s`, `:g`, etc.) | Supported |
|
|
207
|
+
| Multi-line operators | Supports `d/y` with `w/e/b`, `j/k` counts, and `G`; not full Vim motion matrix | Rich cross-line semantics |
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## Out of scope
|
|
212
|
+
|
|
213
|
+
These are **explicitly deferred** and not planned for this feature:
|
|
214
|
+
|
|
215
|
+
- Visual modes (`v`, `V`, block visual)
|
|
216
|
+
- Extended text objects beyond word (`ip`, `i"`, `i(`, etc.)
|
|
217
|
+
- Named registers (`"a`, `"b`, …)
|
|
218
|
+
- Macros (`q{char}`, `@{char}`)
|
|
219
|
+
- Ex command surface (`:s`, `:g`, `:r`, …)
|
|
220
|
+
- Search mode (`/`, `?`, `n`, `N`)
|
|
221
|
+
- Repeat (`.`)
|
|
222
|
+
- General count prefixes beyond current linewise scope (`3dw`, `2j`, …)
|
|
223
|
+
- Redo (`<C-r>`) — no native redo primitive in the underlying readline editor;
|
|
224
|
+
deferred until a suitable hook is available.
|
|
225
|
+
- Window / tab / buffer management
|
|
226
|
+
- Plugin / runtime ecosystem compatibility
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Architecture notes
|
|
231
|
+
|
|
232
|
+
- `index.ts` — `ModalEditor` subclass of `CustomEditor`; all key handling.
|
|
233
|
+
- `motions.ts` — pure motion calculation helpers (`findWordMotionTarget`,
|
|
234
|
+
`findCharMotionTarget`); no side effects.
|
|
235
|
+
- `types.ts` — shared types and escape-sequence constants.
|
|
236
|
+
- `test/` — Node test runner suite; no browser / full runtime required.
|
|
237
|
+
|
|
238
|
+
Run tests:
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
cd vim-bindings
|
|
242
|
+
npm test
|
|
243
|
+
```
|