]> git.gir.st - VimFx.git/blob - documentation/commands.md
Improve largest scrollable element detection
[VimFx.git] / documentation / commands.md
1 <!--
2 This is part of the VimFx documentation.
3 Copyright Simon Lydell 2015.
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.
14
15 [change those]: shortcuts.md
16
17 ## Counts
18
19 Some commands support _counts._ That means that you can type a number before a
20 command and it will change its behavior based on that number—the count. For
21 example, typing `12x` would close 12 tabs.
22
23 (As opposed to vim, you may only supply a count _before_ a command, not in the
24 middle of one. This is because VimFx’s commands are simple sequences, while
25 vim’s are operators and motions.)
26
27 ### `gu`
28
29 Goes _count_ levels up in the URL hierarchy.
30
31 ### `H` and `L`
32
33 Goes _count_ pages backward/forward in history.
34
35 ### Scrolling commands
36
37 Specifying a count make them scroll _count_ times as far.
38
39 ### `J`, `K`
40
41 Selects the tab _count_ tabs backward/forward.
42
43 If the count is greater than one they don’t wrap around when reaching the ends
44 of the tab bar, unless:
45
46 - the first tab is selected and `J` is used.
47 - the last tab is selected and `K` is used.
48
49 They only wrap around _once._
50
51 ### `gJ`, `gK`
52
53 Moves the current tab _count_ tabs forward/backward.
54
55 As opposed to `J` and `K`, pinned and non-pinned tabs are handled separately.
56 The first non-pinned tab wraps to the last tab, and the last tab wraps to the
57 first non-pinned tab, and vice versa for non-pinned tabs. Use `gp` to move a tab
58 between the pinned and non-pinned parts of the tab bar.
59
60 Other than the above, the count and wrap semantics work like `J` and `K`.
61
62 ### `g0`, `g^`, `g$`
63
64 `g0` selects the tab at index _count,_ counting from the start.
65
66 `g^` selects the tab at index _count,_ counting from the first non-pinned tab.
67
68 `g$` selects the tab at index _count,_ counting from the end.
69
70 ### `x`
71
72 Closes the current tab and _count_ minus one of the following tabs.
73
74 ### `X`
75
76 Restores the _count_ last closed tabs.
77
78 ### `I`
79
80 Passes on the next _count_ keypresses to the page, without activating VimFx
81 commands.
82
83 ### The `f` commands
84
85 Explained in the their own section below.
86
87 ### `gi`
88
89 Explained in its own section below.
90
91
92 ## Scrolling commands
93
94 Firefox lets you scroll with the arrow keys, page down, page up, home, end and
95 space by default. VimFx provides similar scrolling commands (and actually
96 overrides `<space>`), but they work a little bit differently.
97
98 They scroll _the currently focused element._ If the currently focused element
99 isn’t scrollable, the largest scrollable element on the page (if any, and
100 including the entire page itself) is scrolled.
101
102 You can focus scrollable elements using the `zf` command (or the `f` command).
103 The right border of hint markers for scrollable elements is styled to remind of
104 a scroll bar, making them easier to recognize among hints for links.
105
106 Note that `zf` and `f` do _not_ add a hint marker for the _largest_ scrollable
107 element (such as the entire page). There’s no need to focus that element, since
108 it is scrolled by default if no other scrollable element is focused, as
109 explained above. (This prevents the largest scrollable element from likely
110 eating your best hint char on most pages; see [The `f` commands]).
111
112 [The `f` commands]: #the-f-commands-1
113
114
115 ## `gi`
116
117 `gi` focuses the text input you last used, or the first one on the page. Note
118 that a [prevented autofocus] still counts as having focused and used a text
119 input. This allows you to have your cake and eat it too: You can enable
120 autofocus prevention, and type `gi` when you wish you hadn’t.
121
122 `gi` takes a count. It then selects the `counth` text input on the page. Note
123 that `gi` and `1gi` are different: The latter _always_ focuses the first input
124 of the page, regradless of which input you used last.
125
126 After having focused a text input using `gi`, `<tab>` and `<s-tab>` will _only
127 cycle between text inputs,_ instead of moving the focus between _all_ focusable
128 elements as they usually do. (See also the [`focus_previous_key` and
129 `focus_next_key`] advanced options.)
130
131 [prevented autofocus]: options.md#prevent-autofocus
132 [`focus_previous_key` and `focus_next_key`]: options.md#focus_previous_key-and-focus_next_key
133
134
135 ## The `f` commands
136
137 When invoking one of the `f` commands you enter Hints mode. In Hints mode,
138 markers with hints are shown for some elements. By typing the letters of a hint
139 something is done to that element, depending on the command.
140
141 Which elements get hints depends on the command as well:
142
143 - `f` and `af`: Anything clickable—links, buttons, form controls.
144 - `F` and `gf`: Anything that can be opened in a new tabs—links.
145 - `yf`: Anything that has something useful to copy—links (their URL) and text
146 inputs (their text).
147 - `zf`: Anything focusable—links, buttons, form controls, scrollable elements,
148 frames.
149
150 It might seem simpler to match the same set of elements for _all_ of the
151 commands. The reason that is not the case is because the fewer elements the
152 shorter the hints. (Also, what should happen if you tried to `F` a button?)
153
154 Another way to make hints shorter is to assign the same hint to all links with
155 the same URL. So don’t get surprised if you see the same hint repeated several
156 times.
157
158 VimFx also tries to give you shorter hints for elements that you are more likely
159 to click. This is done by the surprisingly simple rule: The larger the element,
160 the shorter the hint.
161
162 There are standardized elements which are always clickable—_semantically_
163 clickable elements. Unfortunately, many sites use unclickable elements and then
164 make them clickable using JavaScript—<em>un</em>semantically clickable elements.
165 Such elements are difficult to find. VimFx has a few techniques for doing so,
166 which works many times but not always, but unfortunately they sometimes produce
167 false positives. Many times those false positives are pretty large elements,
168 which according to the last paragraph would give them really short hints, making
169 other more important elements suffer by getting longer ones. Therefore VimFx
170 favors semantic elements over unsemantic ones and takes that into account when
171 deciding the hint length for elements.
172
173 Some hint characters are easier to type than others. The ones on the home row
174 are of course the best. When customizing the [hint chars] option you should put
175 the best keys to the left and the worst ones to the right. VimFx favors keys to
176 the left, so that should give you the optimal hints.
177
178 Hints are added on top of the corresponding element. If they obscure the display
179 too much you can hold shift to make them transparent. (See [Styling] if you’d
180 like to change that.) The hints can also sometimes cover each other. Press
181 `<space>` and `<s-space>` to switch which one should be on top.
182
183 When giving a count to an `f` command, all markers will be re-shown after you’ve
184 typed the hint characters of one of them, _count_ minus one times. All but the
185 last time, the marker’s link will be opened in a new background tab. The last
186 time the command opens links as normal (in the current tab (`f`) or in a new
187 background (`F`) or foreground tab (`gf`)).
188
189 Note that the `f` command adds markers not only to links, but to buttons and
190 form controls as well. What happens the _count_ minus one times then? Buttons,
191 checkboxes and the like are simply clicked, allowing you to quickly check many
192 checkboxes in one go, for example. Text inputs cancel the command.
193
194 `af` works as if you’d supplied an infinite count to `f`. (In fact, the `af`
195 command is implemented by running the same function as for the `f` command,
196 passing `Infinity` as the `count` argument!) Therefore the `af` command does not
197 accept a count itself.
198
199 The `zf` and `yf` commands do not accept counts.
200
201 Press `<enter>` to increase the count by one. This is useful when you’ve already
202 entered Hints mode but realize that you want to interact with yet a marker. This
203 can be faster than going into Hints mode once more.
204
205 If you’ve pressed `f` but realize that you’d rather open a link in a new tab you
206 can hold ctrl while typing the last hint character. This is similar to how you
207 can press `<c-enter>` on a focused link to open it in a new tab (while just
208 `<enter>` would have opened it in the same tab). Hold alt to open in a new
209 foreground tab. In other words, holding ctrl works as if you’d pressed `F` from
210 the beginning, and holding alt works as if you’d pressed `gf`.
211
212 For the `F` and `gf` commands, holding ctrl makes them open links in the same
213 tab instead, as if you’d used the `f` command. Holding alt toggles whether to
214 open tabs in the background or foreground—it makes `F` work like `gf`, and `gf`
215 like `F`.
216
217 (Also see the advanced prefs [hints\_toggle\_in\_tab] and
218 [hints\_toggle\_in\_background].)
219
220 [hint chars]: options.md#hint-chars
221 [Styling]: styling.md
222 [hints\_toggle\_in\_tab]: options.md#hints_toggle_in_tab
223 [hints\_toggle\_in\_background]: options.md#hints_toggle_in_background
224
225
226 ## Ignore mode `<s-f1>`
227
228 Ignore mode is all about ignoring VimFx commands and sending the keys to the
229 page instead. Sometimes, though, you might want to run some VimFx command even
230 when in Insert mode.
231
232 One way of doing that is to press `<s-escape>` to exit Ignore mode, run your
233 command and then enter Ignore mode again using `i`. However, it might be
234 inconvenient having to remember to re-enter Ignore mode, and sometimes that’s
235 not even possible, such as if you ran the `K` command to get to the next tab.
236
237 Another way is to press `<s-f1>` followed by the Normal mode command you wanted
238 to run. (`<s-f1>` is essentially the inverse of the `I` command, which passes
239 the next keypress on to the page. Internally they’re called “quote” and
240 “unquote.”) This is handy if you’d like to switch away from a [blacklisted]
241 page: Just press for example `<s-f1>K`.
242
243 `<s-f1>` was chosen as the default shortcut because on a typical keyboard `<f1>`
244 is located just beside `<escape>`, which makes it very similar to `<s-escape>`,
245 which is used to exit Ignore mode. Both of those are uncommonly used by web
246 pages, so they shouldn’t be in the way. If you ever actually do need to send any
247 of those to the page, you can prefix them with `<s-f1>`, because if the key you
248 press after `<s-f1>` is not part of any Normal mode command, the key is sent to
249 the page. (Another way is for example `<s-f1>I<s-escape>`.)
250
251 [blacklisted]: options.md#blacklist
252
253
254 ## Ex commands
255
256 vim has something called “ex” commands. Want something similar in VimFx? True to
257 its spirit, VimFx embraces a standard Firefox feature for this purpose: The
258 [Developer Toolbar]. That link also includes instructions on how to extend it
259 with your own commands.
260
261 In the future VimFx might even ship with a few extra “ex” commands by default.
262 We’re open for suggestions!
263
264 [Developer Toolbar]: https://developer.mozilla.org/en-US/docs/Tools/GCLI
Imprint / Impressum