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