You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -71,9 +71,10 @@ Parts in square braces (`[]`) are optional.
71
71
Targets are represented by `T` with a possible digit.
72
72
73
73
- Core Changers
74
-
-`"bring T1 [to T2]"`: replace selection/T2 with T
75
-
-`"bring T1 before/after T2"`:
76
-
-`"move T1 [to T2]"`
74
+
-`"bring T"`: insert a copy of T at the cursor/selection.
75
+
-`"bring T1 to T2"`: replace T2 with T
76
+
-`"bring T1 before/after T2"`: insert a copy of T1 before/after T2, including appropriate delimiters.
77
+
-`"move T1 [to/before/after T2]"`: like `"bring"`, but moves instead of copies
77
78
-`"chuck T"`: delete T and appropriate delimiter
78
79
-`"change T"`: delete T and set cursor(s) to where T was
79
80
-`"drink/pour T"`: edit new line before/after T
@@ -84,13 +85,52 @@ Targets are represented by `T` with a possible digit.
84
85
-`"paste to/before/after T"`
85
86
-`"carve/copy T"`: cut/copy T
86
87
87
-
## Examples with walkthroughs
88
+
## Some of the more useful modifiers
88
89
89
-
### TO BE CATEGORIZED
90
+
Here are some very useful modifiers:
90
91
91
-
### Simple line operations
92
+
- Syntactic scopes ([reference](README.md#syntactic-scopes)) are great for expanding the target to what you want to operate on, like the containing function.
93
+
-`"arg"`, often used to involve commas, like `"chuck arg air"` or `"bring air after arg bat"` that take care of commas.
94
+
-`"funk"` for function.
95
+
-`"state"` for statement (which might span multiple lines or only part of a line).
96
+
- Other modifiers that are like syntactic scopes in that they expand the target.
97
+
-[`"file"`](README.md#file) for the whole file.
98
+
-[`"block"`](README.md#block) for a contiguous block of non-empty lines.
99
+
-[`"line"`](README.md#line), often used in commands like `"chuck line"`.
100
+
-[`"paint"`](README.md#paint) for contiguous sequence of non-white space characters.
101
+
-[`"token"`](README.md#token).
102
+
-[`"word"`](README.md#word) allows you to refer to words within a snake_case or camelCase token.
103
+
-[`"char"`](README.md#char) for individual characters.
92
104
93
-
Cursorless might feel token oriented at the beginning, but line operations and feel very natural, especially with use of `"before"` and `"after"`.
105
+
And you can reuse the above scopes when using [relative/ordinal modifiers](README.md#previous--next--ordinal--number).
106
+
Some examples:
107
+
108
+
-`"[number] [scope]s"`, like `"chuck three lines row 12"` to delete rows 12-14.
109
+
-`"[number] [scope]s backward"`, like `"chuck three lines backward row 12"` to delete rows 10-12.
110
+
-`"[nth] [scope]"`, like `"chuck second word air"` to delete "Banana" from "appleBananaCherry".
111
+
-`"[nth] last [scope]"`, like `"chuck last char air"` to delete "s" from "apples".
112
+
-`"next/previous [scope]"`, like `"chuck until next token"` to delete everything from the cursor/selection to the next token.
113
+
114
+
`"past"`, `"until"`, and `"and"` are good ways to build up targets.
115
+
116
+
-`"chuck row 7 past row 9"` to delete rows 7 through 9.
117
+
-`"chuck air until bat"` to delete tokens starting at the air token ending just before the bat token.
118
+
-`"chuck row 7 and row 10"` to delete rows 7 and 10.
119
+
120
+
There is also `"head"` and `"tail"` to expand a target through to the beginning or end of the line.
121
+
`"take head air"` selects the air token through to the beginning of air's line.
122
+
When followed by a modifier, they will expand their input to the start or end of the given modifier range.
123
+
`"take head funk"` will select from the cursor the start of the containing function.
124
+
125
+
## Examples of some common operations
126
+
127
+
The below examples are supposed to show you how to do some of the most common text editing operations, especially the
128
+
operations that might not be initially obvious how to do because of their use of multiple concepts in combination.
129
+
130
+
### "Line operations
131
+
132
+
Cursorless might feel token oriented at the beginning, but line operations can feel very natural, especially with use of `"before"` and `"after"`.
133
+
Also, a lot of the line-based examples can be adapted to tokens, blocks, and so on.
94
134
95
135
#### Bringing a copy of a line to another line
96
136
@@ -124,6 +164,9 @@ Copying a line to an adjacent line has some specialized command support:
124
164
- The useful difference from `"clone line"` is that your cursor moves up to the new line so that you are editing the "top" line rather than the "bottom" line.
125
165
-`"clone up row 7"` only differs from `"clone row 7"` if your cursor is on row 7.
126
166
167
+
`"clone"` commands on a line also bring the existing hats to the new line, so you can chain commands to operate on the new line without waiting for the clone to complete and see the new hats.
168
+
Sidenote: `"clone"` can operate on many types of targets, but lines, blocks, functions, and statements are the most common.
169
+
127
170
#### Operating on multiple lines
128
171
129
172
You can operate on multiple lines at a time:
@@ -134,10 +177,117 @@ You can operate on multiple lines at a time:
134
177
Both destinations and sources can be multiple lines.
135
178
-`"chuck 3 lines air"` will delete three full lines starting at the line that contains the `"air"` token.
136
179
- This command shows that you should not think of these commands as having a length and a start point; think of them as a mark and zero or more modifiers that expand or shift the target.
137
-
- TODO MAYBE: <number> lines backwards & next & previous & next <number> lines
180
+
-`"chuck row 7 past row 9"` uses the `"past"` modifier to delete row 7 through row 9.
181
+
182
+
#### Joining lines
183
+
184
+
It is common to want to join lines.
185
+
For example, to go from...
186
+
187
+
```markdown
188
+
apple
189
+
banana
190
+
```
191
+
192
+
to...
193
+
194
+
```markdown
195
+
apple banana
196
+
```
197
+
198
+
There are a few ways to join lines.
199
+
Remember, not everything needs to be done in Cursorless.
200
+
Talon's community config repo [has](https://github.com/talonhub/community/blob/468fb16392e6a9907cb98e2526c1e5cbf3b5fc8d/apps/vscode/vscode.talon#L265)`join lines: user.vscode("editor.action.joinLines")`.
201
+
Using that command will join the current line with the line below it.
202
+
Or, if you have a multi-line selection, then it will join all the selected lines.
203
+
204
+
Also, you can [customize Cursorless](customization.md##experimental-cursorless-custom-ide-actions) so you can invoke the vscode operation `editor.action.joinLines` with a Cursorless command and target.
205
+
In your Cursorless settings `experimental/actions_custom.csv` file, if you add `join, editor.action.joinLines`, then you can do Cursorless commands like `"join row 7"` to join row 7 and row 8 or `"join 5 lines row 7"` to join 5 lines starting at row 7.
206
+
207
+
vscode's `editor.action.joinLines` puts a space between joined lines.
208
+
If you want to join lines without a space, `"move <BottomLineTarget> to end of <TopLineTarget>"` or `"move <TopLineTarget> to start of <BottomLineTarget>"` are an approach you could take.
209
+
210
+
-`"move down 1 to end of line"` if your cursor is on the top line.
211
+
-`"move row 7 to start of row 8"` for any two lines regardless or cursor position.
212
+
213
+
#### Splitting lines
214
+
215
+
Sometimes you want to split a line into multiple lines.
216
+
For instance, for this...
217
+
218
+
```typescript
219
+
someCode(); // some comment
220
+
```
221
+
222
+
to become this...
223
+
224
+
```typescript
225
+
// some comment
226
+
someCode();
227
+
```
228
+
229
+
`"move tail <mark> before its line"` will do the split starting at `"<mark>"` (`"slash"` for the example above).
230
+
First, the `"tail <mark>"` expands the target from the mark to everything until the end of the line.
231
+
The `"its line"` makes Cursorless re-use the previous mark (from `"tail <mark>"`) and expand to the corresponding line.
232
+
The overall `"move ... before ..."` structure moves the tail portion to before the line.
233
+
234
+
Or, you might want to do the other split, where the tail goes below.
235
+
Where this...
236
+
237
+
```typescript
238
+
applebananacherrydate
239
+
```
240
+
241
+
becomes this...
242
+
243
+
```typescript
244
+
applebanana
245
+
cherrydate
246
+
```
247
+
248
+
`"move tail <mark> after its line"` will do the above split.
249
+
250
+
### Subtoken changes
251
+
252
+
Cursorless also has good support for operating on parts of a token.
253
+
Cursorless can recognize and operate on words within a snake_case, camelCase, or PascalCase token.
254
+
255
+
-`"chuck third word air"` or `"chuck last word air"` to delete `"_cherry"` from `"apple_banana_cherry"`.
256
+
-`"change second word past third word air"` to delete `"BananaCherry"` from `"AppleBananaCherryDate"`.
257
+
-`"chuck last 2 words air"` to delete the last two words of the air token.
258
+
-`"chuck tail token third word air"` to delete from the third word to the last word of the air token.
259
+
It is probably easier to do `"chuck third word past last word air"`.
260
+
-`"bring 2 words third word air to last word bat"` will replace the last word of the bat token with some words from the air token.
261
+
262
+
Similar things can be done on characters, like `"chuck last char air"` to delete `"s"` from `"apples"`.
263
+
264
+
### Arg and item changes
265
+
266
+
The `"arg"` (argument to a function call) and `"item"` (item in a list, map, or object) modifiers are often helpful because they are comma-aware.
267
+
268
+
-`"chuck arg bat"` is a good way to go from `someFunction(apple, banana + otherStuff, cherry)` to `someFunction(apple, cherry)`.
269
+
The command deletes the argument and the appropriate delimiters (comma and a space).
270
+
-`"bring bat after arg air"` lets you go from `someFunction(apple, cherry)` to `someFunction(apple, banana, cherry)`, again taking care of commas and spaces.
271
+
-`"chuck item air"` can go from `someMap = { key1: "apple", key2: "banana" }` to `someMap = { key2: "banana" }`.
272
+
273
+
### Delimeter-only changes
274
+
275
+
You can use `"leading"` and `"trailing"` to target delimiters themselves.
276
+
277
+
-`"chuck leading and trailing air"` to delete the spaces around the air token.
278
+
-`"chuck leading block` will delete the empty lines before the current block.
279
+
280
+
But `"leading"` and `"trailing"` are not always needed to mess with delimiters.
281
+
282
+
-`"chuck until next token"` will delete spaces from the cursor to the next token.
283
+
284
+
## What's next
138
285
139
-
## Some reminders for the author about advanced level content
286
+
Eventually there will be more guide-like documentation on the more advanced concepts.
287
+
In the meantime, here are a few more useful concepts to look into.
140
288
141
-
Whether a command operates on delimiters can be changed by a target modifier.
142
-
`"chuck just bat"` will not delete any spaces; the `"just"` causes the command to ignore delimiters.
143
-
`"take just just just bat"` does the same as `"take bat"`.
289
+
-[pair operations](README.md#surrounding-pair), with [list of paired delimiters](README.md#paired-delimiters)
0 commit comments