]> git.gir.st - VimFx.git/blob - documentation/commands.md
Port settings page to a modern format
[VimFx.git] / documentation / commands.md
1 # Commands
2
3 Most of VimFx’s commands are straight-forward enough to not need any
4 documentation. For some commands, though, there is a bit more to know.
5
6 In this document, many commands are referred to by their default shortcut. You
7 can of course [change those] if you like. (Read about [modes] to tell the
8 difference between _commands_ and _shortcuts._)
9
10 [change those]: shortcuts.md
11 [modes]: modes.md
12
13 ## Counts
14
15 Some commands support _counts._ That means that you can type a number before a
16 command and it will change its behavior based on that number—the count. For
17 example, typing `12x` would close 12 tabs.
18
19 (As opposed to Vim, you may only supply a count _before_ a command, not in the
20 middle of one. That’s because VimFx’s commands are simple sequences, while Vim’s
21 are operators and motions.)
22
23 ### `gu`
24
25 Goes _count_ levels up in the URL hierarchy.
26
27 ### `H` and `L`
28
29 Goes _count_ pages backward/forward in history.
30
31 ### Scrolling commands
32
33 Specifying a count make them scroll _count_ times as far.
34
35 ### `J`, `K`
36
37 Selects the tab _count_ tabs backward/forward.
38
39 If the count is greater than one they don’t wrap around when reaching the ends
40 of the tab bar, unless:
41
42 - the first tab is selected and `J` is used.
43 - the last tab is selected and `K` is used.
44
45 They only wrap around _once._
46
47 ### `gl`
48
49 Selects the _count_ most recently visited tab.
50
51 ### `gL`
52
53 Selects the _count_ oldest unvisited tab.
54
55 Tip: It might help to make “unread” tabs visually different through custom
56 [styling]:
57
58 ```css
59 // Unread, unvisited tabs (opened in the background). These are the ones that
60 // can be selected using `gL`.
61 .tabbrowser-tab[unread]:not([VimFx-visited]):not(#override) {
62 font-style: italic !important;
63 }
64
65 // Unread but previously selected tabs (that have changed since last select).
66 .tabbrowser-tab[unread][VimFx-visited]:not(#override) {
67 font-weight: bold !important;
68 }
69 ```
70
71 [styling]: styling.md
72
73 ### `gJ`, `gK`
74
75 Moves the current tab _count_ tabs forward/backward.
76
77 As opposed to `J` and `K`, pinned and non-pinned tabs are handled separately.
78 The first non-pinned tab wraps to the last tab, and the last tab wraps to the
79 first non-pinned tab, and vice versa for non-pinned tabs. Use `gp` to move a tab
80 between the pinned and non-pinned parts of the tab bar.
81
82 Other than the above, the count and wrap semantics work like `J` and `K`.
83
84 ### `g0`, `g^`, `g$`
85
86 `g0` selects the tab at index _count,_ counting from the start.
87
88 `g^` selects the tab at index _count,_ counting from the first non-pinned tab.
89
90 `g$` selects the tab at index _count,_ counting from the end.
91
92 ### `x`
93
94 Closes the current tab and _count_ minus one of the following tabs.
95
96 ### `X`
97
98 Restores the _count_ last closed tabs.
99
100 ### `I`
101
102 Passes on the next _count_ keypresses to the page, without activating VimFx
103 commands.
104
105 ### The hint commands
106
107 Explained in the their own section below.
108
109 ### `gi`
110
111 Explained in its own section below.
112
113
114 ## Scrolling commands
115
116 Firefox lets you scroll with the arrow keys, page down, page up, home, end and
117 space by default. VimFx provides similar scrolling commands (and actually
118 overrides `<space>`), but they work a little bit differently.
119
120 VimFx chooses which element to scroll in this order:
121
122 1. The currently focused element, if it is scrollable.
123 2. The closest scrollable parent element for the currently focused element.
124 3. The largest scrollable element on the page (if any, and including the entire
125 page itself).
126
127 You can focus scrollable elements using the `ef` command (or the `f` command).
128 Scrollable browser elements, such as in the dev tools, can be focused using the
129 `eb` command. The right border of hint markers for scrollable elements is styled
130 to remind of a scroll bar, making them easier to recognize among hints for
131 links.
132
133 Note that `ef` and `f` do _not_ add a hint marker for the _largest_ scrollable
134 element (such as the entire page). There’s no need to focus that element, since
135 it is scrolled by default if no other scrollable element is focused, as
136 explained above. (This prevents the largest scrollable element from likely
137 eating your best hint char on most pages; see [The hint commands]).
138
139 [The hint commands]: #the-hint-commands--hints-mode
140
141 ### `g[` and `g]`
142
143 Each time you use `gg`, `G`, `0`, `$`, `/`, `a/`, `g/`, `n`, `N` or `'`, the
144 current scroll position is recorded in a list just before the scrolling command
145 in question is performed. You can then travel back to the scroll positions in
146 that list by using the `g[` command. Went too far back? Use the `g]` to go
147 forward again.
148
149 If the current scroll position already exists in the list, it is moved to the
150 end. This way, repeating `g[` you will scroll back to old positions only once.
151
152 Both `g[` and `g]` go _count_ steps in the list.
153
154 This feature is inspired by Vim’s _jump list._ Some people prefer changing the
155 shortcuts to `<c-o>` and `<c-i>` to match Vim’s.
156
157 ### Marks: `m` and `'`
158
159 Other than traditional scrolling, VimFx has _marks._ Press `m` followed by a
160 letter to associate the current scroll position with that letter. For example,
161 press `ma` to save the position into mark _a._ Then you can return to that
162 position by pressing `'` followed by the same letter, e.g. `'a`.
163
164 Note: Firefox has a `'` shortcut by default. It opens the Quick Find bar. VimFx
165 provides the `g/` shortcut instead.
166
167 #### Special marks
168
169 Just like Vim, VimFx has a few special marks. These are set automatically.
170
171 - `'`: Pressing `''` takes you to the scroll position before the last `gg`, `G`,
172 `0`, `$`, `/`, `a/`, `g/`, `n`, `N`, `'`, `g[` or `g]`.
173
174 - `/`: Pressing `'/` takes you to the scroll position before the last `/`, `a/`
175 or `g/`.
176
177 (You can change these marks by using the [`scroll.last_position_mark` and
178 `scroll.last_find_mark`][mark-options] options.)
179
180 [mark-options]: options.md#scroll.last_position_mark-and-scroll.last_find_mark
181
182 #### Minor notes
183
184 Unlike Vim, you may press _any_ key after `m`, and the scroll position will be
185 associated with that key (Vim allows only a–z, roughly).
186
187 Unlike Vim and Vimium, VimFx has no global marks. The reason is that they would
188 be a lot more complicated to implement and do not seem useful enough to warrant
189 that effort.
190
191 As mentioned above, `m` stores the _current scroll position._ Specifically, that
192 means the scroll position of the element that would be scrolled if the active
193 element isn’t scrollable; see [Scrolling commands] above.
194
195 [Scrolling commands]: #scrolling-commands-1
196
197
198 ## `gi`
199
200 `gi` focuses the text input you last used, or the first one on the page. Note
201 that a [prevented autofocus] still counts as having focused and used a text
202 input. This allows you to have your cake and eat it too: You can enable
203 autofocus prevention, and type `gi` when you wish you hadn’t.
204
205 `gi` takes a count. It then selects the `counth` text input on the page. Note
206 that `gi` and `1gi` are different: The latter _always_ focuses the first input
207 of the page, regradless of which input you used last.
208
209 After having focused a text input using `gi`, `<tab>` and `<s-tab>` will _only
210 cycle between text inputs,_ instead of moving the focus between _all_ focusable
211 elements as they usually do. (See also the [`focus_previous_key` and
212 `focus_next_key`] advanced options.)
213
214 [prevented autofocus]: options.md#prevent-autofocus
215 [`focus_previous_key` and `focus_next_key`]: options.md#focus_previous_key-and-focus_next_key
216
217
218 ## The hint commands / Hints mode
219
220 When invoking one of the hint commands (such as `f`, `et` or one of the [`v`
221 commands]) you enter Hints mode. In Hints mode, markers with hints are shown for
222 some elements. By typing the letters of a hint something is done to that
223 element, depending on the command. You can also **type the text of an element**
224 with a hint marker: See the [Hint characters] option for more information.
225
226 Another way to find links on the page is to use `g/`. It’s like the regular find
227 command (`/`), except that it searches links only.
228
229 Which elements get hints depends on the command as well:
230
231 - `f` and `af`: Anything clickable—links, buttons, form controls.
232 - `F`, `et`, `ew` and `ep`: Anything that can be opened in a new tab or
233 window—links.
234 - `yf`: Anything that has something useful to copy—links (their URL) and text
235 inputs (their text).
236 - `ef`: Anything focusable—links, buttons, form controls, scrollable elements,
237 frames.
238 - `ec`: Most things that have a context menu—images, links, videos and text
239 inputs, but also many textual elements.
240 - `eb`: Browser elements, such as toolbar buttons.
241
242 It might seem simpler to match the same set of elements for _all_ of the
243 commands. The reason that is not the case is because the fewer elements the
244 shorter the hints. (Also, what should happen if you tried to `F` a button?)
245
246 (You can also customize [which elements do and don’t get hints][hint-matcher].)
247
248 Another way to make hints shorter is to assign the same hint to all links with
249 the same URL. So don’t be surprised if you see the same hint repeated several
250 times.
251
252 VimFx also tries to give you shorter hints for elements that you are more likely
253 to click. This is done by the surprisingly simple rule: The larger the element,
254 the shorter the hint. To learn more about hint characters and hint length, read
255 about the [Hint characters] option.
256
257 Hints are added on top of the corresponding element. If they obscure the display
258 too much you can hold down ctrl and shift simultaneously to make them
259 transparent, letting you peek through them. (See [Styling] and the
260 [`hints.peek_through`] option if you’d like to change that.) The hints can also
261 sometimes cover each other. Press `<c-space>` and `<s-space>` to switch which
262 one should be on top.
263
264 Yet another way to deal with areas crowded with hint markers is to type part of
265 a marker’s element text. That will filter out hint markers whose elements
266 _don’t_ match what you’ve typed. Pagination links are good examples, like these
267 (fake) ones: [1](#1) [2](#2) [3](#3) [4](#4) [5](#5) [6](#6). It’s very hard to
268 tell which hint to use to go to page three. But if you type “3” things will be
269 much clearer. (It might even [auto-activate][Hint auto-activation] the hint
270 marker!)
271
272 When giving a count to a hint command, all markers will be re-shown after you’ve
273 typed the hint characters of one of them, _count_ minus one times. All but the
274 last time, the marker’s link will be opened in a new background tab. The last
275 time the command opens links as normal (in the current tab (`f`) or in a new
276 background (`F`) or foreground tab (`et`)).
277
278 Note that the hint command adds markers not only to links, but to buttons and
279 form controls as well. What happens the _count_ minus one times then? Buttons,
280 checkboxes and the like are simply clicked, allowing you to quickly check many
281 checkboxes in one go, for example. Text inputs cancel the command.
282
283 `af` works as if you’d supplied an infinite count to `f`. (In fact, the `af`
284 command is implemented by running the same function as for the `f` command,
285 passing `Infinity` as the `count` argument!) Therefore the `af` command does not
286 accept a count itself.
287
288 The `et`, `ef`, `yf` and `eb` commands do not accept counts.
289
290 Press `<up>` to increase the count by one. This is useful when you’ve already
291 entered Hints mode but realize that you want to interact with yet a marker. This
292 can be faster than going into Hints mode once more.
293
294 If you’ve pressed `f` but realize that you’d rather open a link in a new tab you
295 can hold ctrl while typing the last hint character. This is similar to how you
296 can press `<c-enter>` on a focused link to open it in a new tab (while just
297 `<enter>` would have opened it in the same tab). Hold alt to open in a new
298 foreground tab. In other words, holding ctrl works as if you’d pressed `F` from
299 the beginning, and holding alt works as if you’d pressed `et`.
300
301 For the `F` and `et` commands, holding ctrl makes them open links in the same
302 tab instead, as if you’d used the `f` command. Holding alt toggles whether to
303 open tabs in the background or foreground—it makes `F` work like `et`, and `et`
304 like `F`. As mentioned in [Hint auto-activation], the best hint is highlighted
305 with a different color, and can be activated by pressing `<enter>`. Holding alt
306 or ctrl works there too: `<c-enter>` toggles same/new tab and `<a-enter>`
307 toggles background/foreground tab.
308
309 (Also see the advanced options [`hints.toggle_in_tab`] and
310 [`hints.toggle_in_background`].)
311
312 Finally, if the element you wanted to interact with didn’t get a hint marker you
313 can try pressing `<c-backspace>` while the hints are still shown. That will give
314 hint markers to all _other_ elements. Warning: This can be very slow, and result
315 in an overwhelming amount of hint markers (making it difficult to know which
316 hint to activate sometimes). See this as an escape hatch if you _really_ want to
317 avoid using the mouse at all costs. (Press `<c-backspace>` again to toggle back
318 to the previous hints.)
319
320 ### Mnemonics and choice of default hint command shortcuts
321
322 The main command is `f`. It comes from the Vimium and Vimperator extensions. The
323 mnemonic is “<strong>f</strong>ollow link.” It is a good key, because on many
324 keyboard layouts it is located right under where your left index finger rests.
325
326 The most common variations of `f` are centered around that letter: `F`, `yf` and
327 `af`. (Some users might want to swap `F` and `et`, though.) In Vim, it is not
328 uncommon that an uppercase letter does the same thing as its lowercase
329 counterpart, but with some variation (in this case, `F` opens links in new tabs
330 instead of in the current tab), and `y` usually means “yank” or “copy.” VimFx
331 also has this pattern that `a` means “all.”
332
333 You can think of the above commands as the “f commands.” That sounds like
334 “eff-commands” when you say it out loud, which is a way of remembering that the
335 rest of the `f` variations are behind the `e` key. That’s also a pretty good
336 key/letter, because it is close to `f` both alphabetically, and physically in
337 many keyboard layouts (and is pretty easy to type).
338
339 The second key after `e` was chosen based on mnemonics: There’s `et` as in
340 <strong>t</strong>ab, `ew` as in <strong>w</strong>indow, `ep` as in
341 <strong>p</strong>rivate window, `ef` as in <strong>f</strong>ocus, `ec` as in
342 <strong>c</strong>ontext menu and `eb` as in <strong>b</strong>rowser.
343
344 [`v` commands]: #the-v-commands--caret-mode
345 [hint-matcher]: api.md#vimfxsethintmatcherhintmatcher
346 [Hint characters]: options.md#hint-characters
347 [Hint auto-activation]: options.md#hint-auto-activation
348 [Styling]: styling.md
349 [`hints.peek_through`]: options.md#hints.peek_through
350 [`hints.toggle_in_tab`]: options.md#hints.toggle_in_tab
351 [`hints.toggle_in_background`]: options.md#hints.toggle_in_background
352
353
354 ## The `v` commands / Caret mode
355
356 The point of Caret mode is to copy text from web pages using the keyboard.
357
358 ### Entering Caret mode
359
360 Pressing `v` will enter Hints mode with hint markers for all elements with text
361 inside. When activating a marker, its element will get a blinking caret at the
362 beginning of it, and Caret mode will be entered.
363
364 The `av` command does the same thing as `v`, but instead of placing the caret at
365 the beginning of the element, it selects the entire element (it selects
366 <strong>a</strong>ll of the element).
367
368 The `yv` command brings up the same hint markers as `av` does, and then takes
369 the text that `av` would have selected and copies it to the clipboard. It does
370 not enter Caret mode at all.
371
372 The letter `v` was chosen for these shortcuts because that’s what Vim uses to
373 enter its Visual mode, which was an inspiration for VimFx’s Caret mode.
374
375 ### Caret mode commands
376
377 Caret mode uses [Firefox’s own Caret mode] under the hood. This means that you
378 can use the arrows keys, `<home>`, `<end>`, `<pageup>` and `<pagedown>`
379 (optionally holding ctrl) to move the caret as usual. Hold shift while moving
380 the caret to select text.
381
382 In addition to the above, VimFx provides a few commands inspired by Vim.
383
384 - `h`, `j`, `k`, `l`: Move the caret left, down, up or right, like the arrow
385 keys.
386
387 - `b`, `w`: Move the caret one word backward or forward, like `<c-left>` and
388 `<c-right>` but a bit “Vim-adjusted” (see the section on Vim below) in order
389 to be more useful.
390
391 - `0` (or `^`), `$`: Move the caret to the start or end of the line.
392
393 The above commands (except the ones moving to the start or end of the line)
394 accept a _count._ For example, press `3w` to move three words forward.
395
396 Press `v` to start selecting text. After doing so, VimFx’s commands for moving
397 the caret select the text instead of just moving the caret. Press `v` again to
398 collapse the selection again. (Note that after pressing `v`, only VimFx’s
399 commands goes into “selection mode,” while Firefox’s work as usual, requiring
400 shift to be held to select text.)
401
402 `o` moves the caret to the “other end” of the selection. If the caret is at the
403 end of the selection, `o` will move it to the start (while keeping the selection
404 intact), and vice versa. This let’s you adjust the selection in both ends.
405
406 Finally, `y` is a possibly faster alternative to the good old `<c-c>`. Other
407 than copying the selection to the clipboard, it also exits Caret mode, saving
408 you yet a keystroke. (`<escape>` is unsurprisingly used to exit Caret mode
409 otherwise.)
410
411 [Firefox’s own Caret mode]: http://kb.mozillazine.org/Accessibility_features_of_Firefox#Allow_text_to_be_selected_with_the_keyboard
412
413 ### Workflow tips
414
415 If you’re lucky, the text you want to copy is located within a single element
416 that contains no other text, such as the text of a link or an inline code
417 snippet. If so, using the `yv` command (which copies an entire element without
418 entering Caret mode) is the fastest.
419
420 If you want to copy _almost_ all text of an element, or a bit more than it, use
421 the `av` command (which selects an entire element). Then adjust the selection
422 using the various Caret mode commands. Remember that `o` lets you adjust both
423 ends of the selection.
424
425 In all other cases, use the `v` command to place the caret close to the text you
426 want to copy. Then move the caret in place using the various Caret
427 mode commands, hit `v` to start selecting, and move the again.
428
429 Use `y` to finish (or `<escape>` to abort). Alternatively, use the `<menu>` key
430 to open the context menu for the selection.
431
432 ### For Vim users
433
434 As seen above, Caret mode is obviously inspired by Vim’s Visual mode. However,
435 keep in mind that the point of Caret mode is to **copy text using the keyboard,
436 not mimicing Vim’s visual mode.** I’ve found that selecting text for _copying_
437 is different than selecting code for _editing._ Keep that in mind.
438
439 Working with text selection in webpages using code is a terrible mess full of
440 hacks. New commands will only be added if they _really_ are worth it.
441
442 A note on VimFx’s `b` and `w`: They work like Vim’s `b` and `w` (but a “word” is
443 according to Firefox’s definition, not Vim’s), except when there is selected
444 text and the caret is at the end of the selection. Then `b` works like Vim’s
445 `ge` and `w` works like Vim’s `e`. The idea is to keep it simple and only
446 provide two commands that do what you want, rather than many just to mimic Vim.
447
448
449 ## Ignore mode `<s-f1>`
450
451 Ignore mode is all about ignoring VimFx commands and sending the keys to the
452 page instead. Sometimes, though, you might want to run some VimFx command even
453 when in Ignore mode.
454
455 One way of doing that is to press `<s-escape>` to exit Ignore mode, run your
456 command and then enter Ignore mode again using `i`. However, it might be
457 inconvenient having to remember to re-enter Ignore mode, and sometimes that’s
458 not even possible, such as if you ran the `K` command to get to the next tab.
459
460 Another way is to press `<s-f1>` followed by the Normal mode command you wanted
461 to run. (`<s-f1>` is essentially the inverse of the `I` command, which passes
462 the next keypress on to the page. Internally they’re called “quote” and
463 “unquote.”) This is handy if you’d like to switch away from a [blacklisted]
464 page: Just press for example `<s-f1>K`.
465
466 `<s-f1>` was chosen as the default shortcut because on a typical keyboard `<f1>`
467 is located just beside `<escape>`, which makes it very similar to `<s-escape>`,
468 which is used to exit Ignore mode. Both of those are uncommonly used by web
469 pages, so they shouldn’t be in the way. If you ever actually do need to send any
470 of those to the page, you can prefix them with `<s-f1>`, because if the key you
471 press after `<s-f1>` is not part of any Normal mode command, the key is sent to
472 the page. (Another way is for example `<s-f1>I<s-escape>`.)
473
474 [blacklisted]: options.md#blacklist
Imprint / Impressum