summaryrefslogtreecommitdiff
path: root/qutebrowser/config/configdata.py
blob: 28cf41ac5b5df217755d19729d4c0b218b98bfd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:

# Copyright 2014-2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser.  If not, see <http://www.gnu.org/licenses/>.

"""Configuration data for config.py.

Module attributes:

FIRST_COMMENT: The initial comment header to place in the config.
SECTION_DESC: A dictionary with descriptions for sections.
DATA: A global read-only copy of the default config, an OrderedDict of
      sections.
"""

import sys
import re
import collections

from qutebrowser.config import configtypes as typ
from qutebrowser.config import sections as sect
from qutebrowser.config.value import SettingValue
from qutebrowser.utils.qtutils import MAXVALS
from qutebrowser.utils import usertypes, qtutils


FIRST_COMMENT = r"""
# vim: ft=dosini

# Configfile for qutebrowser.
#
# This configfile is parsed by python's configparser in extended
# interpolation mode. The format is very INI-like, so there are
# categories like [general] with "key = value"-pairs.
#
# Note that you shouldn't add your own comments, as this file is
# regenerated every time the config is saved.
#
# Interpolation looks like  ${value}  or  ${section:value} and will be
# replaced by the respective value.
#
# Some settings will expand environment variables. Note that, since
# interpolation is run first, you will need to escape the  $  char as
# described below.
#
# This is the default config, so if you want to remove anything from
# here (as opposed to change/add), for example a key binding, set it to
# an empty value.
#
# You will need to escape the following values:
#   - # at the start of the line (at the first position of the key) (\#)
#   - $ in a value ($$)
"""


SECTION_DESC = {
    'general': "General/miscellaneous options.",
    'ui': "General options related to the user interface.",
    'input': "Options related to input modes.",
    'network': "Settings related to the network.",
    'completion': "Options related to completion and command history.",
    'tabs': "Configuration of the tab bar.",
    'storage': "Settings related to cache and storage.",
    'content': "Loaded plugins/scripts and allowed actions.",
    'hints': "Hinting settings.",
    'searchengines': (
        "Definitions of search engines which can be used via the address "
        "bar.\n"
        "The searchengine named `DEFAULT` is used when "
        "`general -> auto-search` is true and something else than a URL was "
        "entered to be opened. Other search engines can be used by prepending "
        "the search engine name to the search term, e.g. "
        "`:open google qutebrowser`. The string `{}` will be replaced by the "
        "search term, use `{{` and `}}` for literal `{`/`}` signs."),
    'aliases': (
        "Aliases for commands.\n"
        "By default, no aliases are defined. Example which adds a new command "
        "`:qtb` to open qutebrowsers website:\n\n"
        "`qtb = open https://www.qutebrowser.org/`"),
    'colors': (
        "Colors used in the UI.\n"
        "A value can be in one of the following format:\n\n"
        " * `#RGB`/`#RRGGBB`/`#RRRGGGBBB`/`#RRRRGGGGBBBB`\n"
        " * An SVG color name as specified in http://www.w3.org/TR/SVG/"
        "types.html#ColorKeywords[the W3C specification].\n"
        " * transparent (no color)\n"
        " * `rgb(r, g, b)` / `rgba(r, g, b, a)` (values 0-255 or "
        "percentages)\n"
        " * `hsv(h, s, v)` / `hsva(h, s, v, a)` (values 0-255, hue 0-359)\n"
        " * A gradient as explained in http://doc.qt.io/qt-5/"
        "stylesheet-reference.html#list-of-property-types[the Qt "
        "documentation] under ``Gradient''.\n\n"
        "A *.system value determines the color system to use for color "
        "interpolation between similarly-named *.start and *.stop entries, "
        "regardless of how they are defined in the options. "
        "Valid values are 'rgb', 'hsv', and 'hsl'.\n\n"
        "The `hints.*` values are a special case as they're real CSS "
        "colors, not Qt-CSS colors. There, for a gradient, you need to use "
        "`-webkit-gradient`, see https://www.webkit.org/blog/175/introducing-"
        "css-gradients/[the WebKit documentation]."),
    'fonts': (
        "Fonts used for the UI, with optional style/weight/size.\n\n"
        " * Style: `normal`/`italic`/`oblique`\n"
        " * Weight: `normal`, `bold`, `100`..`900`\n"
        " * Size: _number_ `px`/`pt`"),
}


DEFAULT_FONT_SIZE = '10pt' if sys.platform == 'darwin' else '8pt'


def data(readonly=False):
    """Get the default config data.

    Return:
        A {name: section} OrderedDict.
    """
    return collections.OrderedDict([
        ('general', sect.KeyValue(
            ('ignore-case',
             SettingValue(typ.IgnoreCase(), 'smart'),
             "Whether to find text on a page case-insensitively."),

            ('startpage',
             SettingValue(typ.List(typ.String()),
                          'https://start.duckduckgo.com'),
             "The default page(s) to open at the start, separated by commas."),

            ('yank-ignored-url-parameters',
             SettingValue(typ.List(typ.String()),
                          'ref,utm_source,utm_medium,utm_campaign,utm_term,'
                          'utm_content'),
            "The URL parameters to strip with :yank url, separated by "
            "commas."),

            ('default-open-dispatcher',
             SettingValue(typ.String(none_ok=True), ''),
            "The default program used to open downloads. Set to an empty "
            "string to use the default internal handler.\n\n"
            "Any {} in the string will be expanded to the filename, else "
            "the filename will be appended."),

            ('default-page',
             SettingValue(typ.FuzzyUrl(), '${startpage}'),
             "The page to open if :open -t/-b/-w is used without URL. Use "
             "`about:blank` for a blank page."),

            ('auto-search',
             SettingValue(typ.AutoSearch(), 'naive'),
             "Whether to start a search when something else than a URL is "
             "entered."),

            ('auto-save-config',
             SettingValue(typ.Bool(), 'true'),
             "Whether to save the config automatically on quit."),

            ('auto-save-interval',
             SettingValue(typ.Int(minval=0, maxval=MAXVALS['int']), '15000'),
             "How often (in milliseconds) to auto-save config/cookies/etc."),

            ('editor',
             SettingValue(typ.ShellCommand(placeholder=True), 'gvim -f "{}"'),
             "The editor (and arguments) to use for the `open-editor` "
             "command.\n\n"
             "The arguments get split like in a shell, so you can use `\"` or "
             "`'` to quote them.\n"
             "`{}` gets replaced by the filename of the file to be edited."),

            ('editor-encoding',
             SettingValue(typ.Encoding(), 'utf-8'),
             "Encoding to use for editor."),

            ('private-browsing',
             SettingValue(typ.Bool(), 'false'),
             "Open new windows in private browsing mode which does not record "
             "visited pages."),

            ('developer-extras',
             SettingValue(typ.Bool(), 'false',
                          backends=[usertypes.Backend.QtWebKit]),
             "Enable extra tools for Web developers.\n\n"
             "This needs to be enabled for `:inspector` to work and also adds "
             "an _Inspect_ entry to the context menu. For QtWebEngine, see "
             "'qutebrowser --help' instead."),

            ('print-element-backgrounds',
             SettingValue(typ.Bool(), 'true',
                          backends=(
                              None if qtutils.version_check('5.8', strict=True)
                              else [usertypes.Backend.QtWebKit])),
             "Whether the background color and images are also drawn when the "
             "page is printed.\n"
             "This setting only works with Qt 5.8 or newer when using the "
             "QtWebEngine backend."),

            ('xss-auditing',
             SettingValue(typ.Bool(), 'false'),
             "Whether load requests should be monitored for cross-site "
             "scripting attempts.\n\n"
             "Suspicious scripts will be blocked and reported in the "
             "inspector's JavaScript console. Enabling this feature might "
             "have an impact on performance."),

            ('default-encoding',
             SettingValue(typ.String(), 'iso-8859-1'),
             "Default encoding to use for websites.\n\n"
             "The encoding must be a string describing an encoding such as "
             "_utf-8_, _iso-8859-1_, etc."),

            ('new-instance-open-target',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('tab', "Open a new tab in the existing "
                      "window and activate the window."),
                     ('tab-bg', "Open a new background tab in the "
                      "existing window and activate the "
                      "window."),
                     ('tab-silent', "Open a new tab in the existing "
                      "window without activating "
                      "the window."),
                     ('tab-bg-silent', "Open a new background tab "
                      "in the existing window "
                      "without activating the "
                      "window."),
                     ('window', "Open in a new window.")
                 )), 'tab'),
             "How to open links in an existing instance if a new one is "
             "launched."),

            ('new-instance-open-target.window',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('first-opened', "Open new tabs in the first (oldest) "
                                      "opened window."),
                     ('last-opened', "Open new tabs in the last (newest) "
                                     "opened window."),
                     ('last-focused', "Open new tabs in the most recently "
                                      "focused window."),
                     ('last-visible', "Open new tabs in the most recently "
                                      "visible window.")
                 )), 'last-focused'),
             "Which window to choose when opening links as new tabs."),

            ('log-javascript-console',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('none', "Don't log messages."),
                     ('debug', "Log messages with debug level."),
                     ('info', "Log messages with info level.")
                 )), 'debug'),
             "How to log javascript console messages."),

            ('save-session',
             SettingValue(typ.Bool(), 'false'),
             "Whether to always save the open pages."),

            ('session-default-name',
             SettingValue(typ.SessionName(none_ok=True), ''),
             "The name of the session to save by default, or empty for the "
             "last loaded session."),

            ('url-incdec-segments',
             SettingValue(
                 typ.FlagList(valid_values=typ.ValidValues(
                     'host', 'path', 'query', 'anchor')),
                 'path,query'),
             "The URL segments where `:navigate increment/decrement` will "
             "search for a number."),

            readonly=readonly
        )),

        ('ui', sect.KeyValue(
            ('history-session-interval',
             SettingValue(typ.Int(), '30'),
             "The maximum time in minutes between two history items for them "
             "to be considered being from the same session. Use -1 to "
             "disable separation."),

            ('zoom-levels',
             SettingValue(typ.List(typ.Perc(minval=0)),
                          '25%,33%,50%,67%,75%,90%,100%,110%,125%,150%,175%,'
                          '200%,250%,300%,400%,500%'),
             "The available zoom levels, separated by commas."),

            ('default-zoom',
             SettingValue(typ.Perc(), '100%'),
             "The default zoom level."),

            ('downloads-position',
             SettingValue(typ.VerticalPosition(), 'top'),
             "Where to show the downloaded files."),

            ('status-position',
             SettingValue(typ.VerticalPosition(), 'bottom'),
             "The position of the status bar."),

            ('message-timeout',
             SettingValue(typ.Int(minval=0), '2000'),
             "Time (in ms) to show messages in the statusbar for.\n"
             "Set to 0 to never clear messages."),

            ('message-unfocused',
             SettingValue(typ.Bool(), 'false'),
             "Whether to show messages in unfocused windows."),

            ('confirm-quit',
             SettingValue(typ.ConfirmQuit(), 'never'),
             "Whether to confirm quitting the application."),

            ('zoom-text-only',
             SettingValue(typ.Bool(), 'false',
                          backends=[usertypes.Backend.QtWebKit]),
             "Whether the zoom factor on a frame applies only to the text or "
             "to all content."),

            ('frame-flattening',
             SettingValue(typ.Bool(), 'false',
                          backends=[usertypes.Backend.QtWebKit]),
             "Whether to  expand each subframe to its contents.\n\n"
             "This will flatten all the frames to become one scrollable "
             "page."),

            ('user-stylesheet',
             SettingValue(typ.File(none_ok=True), ''),
             "User stylesheet to use (absolute filename or filename relative "
             "to the config directory). Will expand environment variables."),

            ('hide-scrollbar',
             SettingValue(typ.Bool(), 'true'),
             "Hide the main scrollbar."),

            ('smooth-scrolling',
             SettingValue(typ.Bool(), 'false'),
             "Whether to enable smooth scrolling for web pages. Note smooth "
             "scrolling does not work with the :scroll-px command."),

            ('remove-finished-downloads',
             SettingValue(typ.Int(minval=-1), '-1'),
             "Number of milliseconds to wait before removing finished "
             "downloads. Will not be removed if value is -1."),

            ('hide-statusbar',
             SettingValue(typ.Bool(), 'false'),
             "Whether to hide the statusbar unless a message is shown."),

            ('statusbar-padding',
             SettingValue(typ.Padding(), '1,1,0,0'),
             "Padding for statusbar (top, bottom, left, right)."),

            ('window-title-format',
             SettingValue(typ.FormatString(fields=['perc', 'perc_raw', 'title',
                                                   'title_sep', 'id',
                                                   'scroll_pos', 'host',
                                                   'backend', 'private']),
                          '{perc}{title}{title_sep}qutebrowser'),
             "The format to use for the window title. The following "
             "placeholders are defined:\n\n"
             "* `{perc}`: The percentage as a string like `[10%]`.\n"
             "* `{perc_raw}`: The raw percentage, e.g. `10`\n"
             "* `{title}`: The title of the current web page\n"
             "* `{title_sep}`: The string ` - ` if a title is set, empty "
             "otherwise.\n"
             "* `{id}`: The internal window ID of this window.\n"
             "* `{scroll_pos}`: The page scroll position.\n"
             "* `{host}`: The host of the current web page.\n"
             "* `{backend}`: Either 'webkit' or 'webengine'\n"
             "* `{private}` : Indicates when private mode is enabled.\n"),

            ('modal-js-dialog',
             SettingValue(typ.Bool(), 'false'),
             "Use standard JavaScript modal dialog for alert() and confirm()"),

            ('hide-wayland-decoration',
             SettingValue(typ.Bool(), 'false'),
             "Hide the window decoration when using wayland "
             "(requires restart)"),

            ('keyhint-blacklist',
             SettingValue(typ.List(typ.String(), none_ok=True), ''),
             "Keychains that shouldn't be shown in the keyhint dialog\n\n"
             "Globs are supported, so ';*' will blacklist all keychains"
             "starting with ';'. Use '*' to disable keyhints"),

            ('keyhint-delay',
             SettingValue(typ.Int(minval=0), '500'),
             "Time from pressing a key to seeing the keyhint dialog (ms)"),

            ('prompt-radius',
             SettingValue(typ.Int(minval=0), '8'),
             "The rounding radius for the edges of prompts."),

            ('prompt-filebrowser',
             SettingValue(typ.Bool(), 'true'),
             "Show a filebrowser in upload/download prompts."),

            readonly=readonly
        )),

        ('network', sect.KeyValue(
            ('do-not-track',
             SettingValue(typ.Bool(), 'true'),
             "Value to send in the `DNT` header."),

            ('accept-language',
             SettingValue(typ.String(none_ok=True), 'en-US,en'),
             "Value to send in the `accept-language` header."),

            ('referer-header',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('always', "Always send."),
                     ('never', "Never send; this is not recommended,"
                      " as some sites may break."),
                     ('same-domain', "Only send for the same domain."
                      " This will still protect your privacy, but"
                      " shouldn't break any sites.")
                 )), 'same-domain', backends=[usertypes.Backend.QtWebKit]),
             "Send the Referer header"),

            ('user-agent',
             SettingValue(typ.UserAgent(none_ok=True), ''),
             "User agent to send. Empty to send the default."),

            ('proxy',
             SettingValue(typ.Proxy(), 'system',
                          backends=(None if qtutils.version_check('5.8')
                                    else [usertypes.Backend.QtWebKit])),
             "The proxy to use.\n\n"
             "In addition to the listed values, you can use a `socks://...` "
             "or `http://...` URL.\n\n"
             "This setting only works with Qt 5.8 or newer when using the "
             "QtWebEngine backend."),

            ('proxy-dns-requests',
             SettingValue(typ.Bool(), 'true',
                          backends=[usertypes.Backend.QtWebKit]),
             "Whether to send DNS requests over the configured proxy."),

            ('ssl-strict',
             SettingValue(typ.BoolAsk(), 'ask'),
             "Whether to validate SSL handshakes."),

            ('dns-prefetch',
             SettingValue(typ.Bool(), 'true',
                          backends=[usertypes.Backend.QtWebKit]),
             "Whether to try to pre-fetch DNS entries to speed up browsing."),

            ('custom-headers',
             SettingValue(typ.HeaderDict(none_ok=True), ''),
             "Set custom headers for qutebrowser HTTP requests."),

            ('netrc-file',
             SettingValue(typ.File(none_ok=True), ''),
             "Set location of a netrc-file for HTTP authentication. If empty, "
             "~/.netrc is used."),

            readonly=readonly
        )),

        ('completion', sect.KeyValue(
            ('show',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('always', "Whenever a completion is available."),
                     ('auto', "Whenever a completion is requested."),
                     ('never', "Never.")
                 )), 'always'),
             "When to show the autocompletion window."),

            ('download-path-suggestion',
             SettingValue(
                 typ.String(valid_values=typ.ValidValues(
                     ('path', "Show only the download path."),
                     ('filename', "Show only download filename."),
                     ('both', "Show download path and filename."))),
                 'path'),
             "What to display in the download filename input."),

            ('timestamp-format',
             SettingValue(typ.TimestampTemplate(none_ok=True), '%Y-%m-%d'),
             "How to format timestamps (e.g. for history)"),

            ('height',
             SettingValue(typ.PercOrInt(minperc=0, maxperc=100, minint=1),
                          '50%'),
             "The height of the completion, in px or as percentage of the "
             "window."),

            ('cmd-history-max-items',
             SettingValue(typ.Int(minval=-1), '100'),
             "How many commands to save in the command history.\n\n"
             "0: no history / -1: unlimited"),

            ('web-history-max-items',
             SettingValue(typ.Int(minval=-1), '1000'),
             "How many URLs to show in the web history.\n\n"
             "0: no history / -1: unlimited"),

            ('quick-complete',
             SettingValue(typ.Bool(), 'true'),
             "Whether to move on to the next part when there's only one "
             "possible completion left."),

            ('shrink',
             SettingValue(typ.Bool(), 'false'),
             "Whether to shrink the completion to be smaller than the "
             "configured size if there are no scrollbars."),

            ('scrollbar-width',
             SettingValue(typ.Int(minval=0), '12'),
             "Width of the scrollbar in the completion window (in px)."),

            ('scrollbar-padding',
             SettingValue(typ.Int(minval=0), '2'),
             "Padding of scrollbar handle in completion window (in px)."),

            readonly=readonly
        )),

        ('input', sect.KeyValue(
            ('timeout',
             SettingValue(typ.Int(minval=0, maxval=MAXVALS['int']), '500'),
             "Timeout (in milliseconds) for ambiguous key bindings.\n\n"
             "If the current input forms both a complete match and a partial "
             "match, the complete match will be executed after this time."),

            ('partial-timeout',
             SettingValue(typ.Int(minval=0, maxval=MAXVALS['int']), '5000'),
             "Timeout (in milliseconds) for partially typed key bindings.\n\n"
             "If the current input forms only partial matches, the keystring "
             "will be cleared after this time."),

            ('insert-mode-on-plugins',
             SettingValue(typ.Bool(), 'false'),
             "Whether to switch to insert mode when clicking flash and other "
             "plugins."),

            ('auto-leave-insert-mode',
             SettingValue(typ.Bool(), 'true'),
             "Whether to leave insert mode if a non-editable element is "
             "clicked."),

            ('auto-insert-mode',
             SettingValue(typ.Bool(), 'false'),
             "Whether to automatically enter insert mode if an editable "
             "element is focused after page load."),

            ('forward-unbound-keys',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('all', "Forward all unbound keys."),
                     ('auto', "Forward unbound non-alphanumeric "
                      "keys."),
                     ('none', "Don't forward any keys.")
                 )), 'auto'),
             "Whether to forward unbound keys to the webview in normal mode."),

            ('spatial-navigation',
             SettingValue(typ.Bool(), 'false'),
             "Enables or disables the Spatial Navigation feature.\n\n"
             "Spatial navigation consists in the ability to navigate between "
             "focusable elements in a Web page, such as hyperlinks and form "
             "controls, by using Left, Right, Up and Down arrow keys. For "
             "example, if a user presses the Right key, heuristics determine "
             "whether there is an element he might be trying to reach towards "
             "the right and which element he probably wants."),

            ('links-included-in-focus-chain',
             SettingValue(typ.Bool(), 'true'),
             "Whether hyperlinks should be included in the keyboard focus "
             "chain."),

            ('rocker-gestures',
             SettingValue(typ.Bool(), 'false'),
             "Whether to enable Opera-like mouse rocker gestures. This "
             "disables the context menu."),

            ('mouse-zoom-divider',
             SettingValue(typ.Int(minval=0), '512'),
             "How much to divide the mouse wheel movements to translate them "
             "into zoom increments."),

            readonly=readonly
        )),

        ('tabs', sect.KeyValue(
            ('background-tabs',
             SettingValue(typ.Bool(), 'false'),
             "Whether to open new tabs (middleclick/ctrl+click) in "
             "background."),

            ('select-on-remove',
             SettingValue(typ.SelectOnRemove(), 'next'),
             "Which tab to select when the focused tab is removed."),

            ('new-tab-position',
             SettingValue(typ.NewTabPosition(), 'next'),
             "How new tabs are positioned."),

            ('new-tab-position-explicit',
             SettingValue(typ.NewTabPosition(), 'last'),
             "How new tabs opened explicitly are positioned."),

            ('last-close',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('ignore', "Don't do anything."),
                     ('blank', "Load a blank page."),
                     ('startpage', "Load the start page."),
                     ('default-page', "Load the default page."),
                     ('close', "Close the window.")
                 )), 'ignore'),
             "Behavior when the last tab is closed."),

            ('show',
             SettingValue(
                 typ.String(valid_values=typ.ValidValues(
                     ('always', "Always show the tab bar."),
                     ('never', "Always hide the tab bar."),
                     ('multiple', "Hide the tab bar if only one tab "
                      "is open."),
                     ('switching', "Show the tab bar when switching "
                      "tabs.")
                 )), 'always'),
             "When to show the tab bar"),

            ('show-switching-delay',
             SettingValue(typ.Int(), '800'),
             "Time to show the tab bar before hiding it when tabs->show is "
             "set to 'switching'."),

            ('wrap',
             SettingValue(typ.Bool(), 'true'),
             "Whether to wrap when changing tabs."),

            ('movable',
             SettingValue(typ.Bool(), 'true'),
             "Whether tabs should be movable."),

            ('close-mouse-button',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('right', "Close tabs on right-click."),
                     ('middle', "Close tabs on middle-click."),
                     ('none', "Don't close tabs using the mouse.")
                 )), 'middle'),
             "On which mouse button to close tabs."),

            ('position',
             SettingValue(typ.Position(), 'top'),
             "The position of the tab bar."),

            ('show-favicons',
             SettingValue(typ.Bool(), 'true'),
             "Whether to show favicons in the tab bar."),

            ('favicon-scale',
             SettingValue(typ.Float(minval=0.0), '1.0'),
             "Scale for favicons in the tab bar. The tab size is unchanged, "
             "so big favicons also require extra `tabs->padding`."),

            ('width',
             SettingValue(typ.PercOrInt(minperc=0, maxperc=100, minint=1),
                          '20%'),
             "The width of the tab bar if it's vertical, in px or as "
             "percentage of the window."),

            ('pinned-width',
             SettingValue(typ.Int(minval=10),
                          '43'),
             "The width for pinned tabs with a horizontal tabbar, in px."),

            ('indicator-width',
             SettingValue(typ.Int(minval=0), '3'),
             "Width of the progress indicator (0 to disable)."),

            ('tabs-are-windows',
             SettingValue(typ.Bool(), 'false'),
             "Whether to open windows instead of tabs."),

            ('title-format',
             SettingValue(typ.FormatString(
                 fields=['perc', 'perc_raw', 'title', 'title_sep', 'index',
                         'id', 'scroll_pos', 'host', 'private'], none_ok=True),
                 '{index}: {title}'),
             "The format to use for the tab title. The following placeholders "
             "are defined:\n\n"
             "* `{perc}`: The percentage as a string like `[10%]`.\n"
             "* `{perc_raw}`: The raw percentage, e.g. `10`\n"
             "* `{title}`: The title of the current web page\n"
             "* `{title_sep}`: The string ` - ` if a title is set, empty "
             "otherwise.\n"
             "* `{index}`: The index of this tab.\n"
             "* `{id}`: The internal tab ID of this tab.\n"
             "* `{scroll_pos}`: The page scroll position.\n"
             "* `{host}`: The host of the current web page.\n"
             "* `{backend}`: Either 'webkit' or 'webengine'\n"
             "* `{private}` : Indicates when private mode is enabled.\n"),

            ('title-format-pinned',
             SettingValue(typ.FormatString(
                 fields=['perc', 'perc_raw', 'title', 'title_sep', 'index',
                         'id', 'scroll_pos', 'host', 'private'], none_ok=True),
                 '{index}'),
             "The format to use for the tab title for pinned tabs. "
             "The same placeholders like for title-format are defined."),

            ('title-alignment',
             SettingValue(typ.TextAlignment(), 'left'),
             "Alignment of the text inside of tabs"),

            ('mousewheel-tab-switching',
             SettingValue(typ.Bool(), 'true'),
             "Switch between tabs using the mouse wheel."),

            ('padding',
             SettingValue(typ.Padding(), '0,0,5,5'),
             "Padding for tabs (top, bottom, left, right)."),

            ('indicator-padding',
             SettingValue(typ.Padding(), '2,2,0,4'),
             "Padding for indicators (top, bottom, left, right)."),

            readonly=readonly
        )),

        ('storage', sect.KeyValue(
            ('download-directory',
             SettingValue(typ.Directory(none_ok=True), ''),
             "The directory to save downloads to. An empty value selects a "
             "sensible os-specific default. Will expand environment "
             "variables."),

            ('prompt-download-directory',
             SettingValue(typ.Bool(), 'true'),
             "Whether to prompt the user for the download location.\n"
             "If set to false, 'download-directory' will be used."),

            ('remember-download-directory',
             SettingValue(typ.Bool(), 'true'),
             "Whether to remember the last used download directory."),

            # Defaults from QWebSettings::QWebSettings() in
            # qtwebkit/Source/WebKit/qt/Api/qwebsettings.cpp

            ('maximum-pages-in-cache',
             SettingValue(typ.Int(minval=0, maxval=MAXVALS['int']), '0',
                          backends=[usertypes.Backend.QtWebKit]),
             "The maximum number of pages to hold in the global memory page "
             "cache.\n\n"
             "The Page Cache allows for a nicer user experience when "
             "navigating forth or back to pages in the forward/back history, "
             "by pausing and resuming up to _n_ pages.\n\n"
             "For more information about the feature, please refer to: "
             "http://webkit.org/blog/427/webkit-page-cache-i-the-basics/"),

            ('offline-web-application-cache',
             SettingValue(typ.Bool(), 'true',
                          backends=[usertypes.Backend.QtWebKit]),
             "Whether support for the HTML 5 web application cache feature is "
             "enabled.\n\n"
             "An application cache acts like an HTTP cache in some sense. For "
             "documents that use the application cache via JavaScript, the "
             "loader engine will first ask the application cache for the "
             "contents, before hitting the network.\n\n"
             "The feature is described in details at: "
             "http://dev.w3.org/html5/spec/Overview.html#appcache"),

            ('local-storage',
             SettingValue(typ.Bool(), 'true'),
             "Whether support for HTML 5 local storage and Web SQL is "
             "enabled."),

            ('cache-size',
             SettingValue(typ.Int(none_ok=True, minval=0,
                                  maxval=MAXVALS['int64']), ''),
             "Size of the HTTP network cache. Empty to use the default "
             "value."),

            readonly=readonly
        )),

        ('content', sect.KeyValue(
            ('allow-images',
             SettingValue(typ.Bool(), 'true'),
             "Whether images are automatically loaded in web pages."),

            ('allow-javascript',
             SettingValue(typ.Bool(), 'true'),
             "Enables or disables the running of JavaScript programs."),

            ('allow-plugins',
             SettingValue(typ.Bool(), 'false'),
             "Enables or disables plugins in Web pages.\n\n"
             'Qt plugins with a mimetype such as "application/x-qt-plugin" '
             "are not affected by this setting."),

            ('webgl',
             SettingValue(typ.Bool(), 'true'),
             "Enables or disables WebGL."),

            ('hyperlink-auditing',
             SettingValue(typ.Bool(), 'false'),
             "Enable or disable hyperlink auditing (<a ping>)."),

            ('geolocation',
             SettingValue(typ.BoolAsk(), 'ask'),
             "Allow websites to request geolocations."),

            ('notifications',
             SettingValue(typ.BoolAsk(), 'ask'),
             "Allow websites to show notifications."),

            ('media-capture',
             SettingValue(typ.BoolAsk(), 'ask',
                          backends=[usertypes.Backend.QtWebEngine]),
             "Allow websites to record audio/video."),

            ('javascript-can-open-windows-automatically',
             SettingValue(typ.Bool(), 'false'),
             "Whether JavaScript programs can open new windows without user "
             "interaction."),

            ('javascript-can-close-windows',
             SettingValue(typ.Bool(), 'false',
                          backends=[usertypes.Backend.QtWebKit]),
             "Whether JavaScript programs can close windows."),

            ('javascript-can-access-clipboard',
             SettingValue(typ.Bool(), 'false'),
             "Whether JavaScript programs can read or write to the "
             "clipboard.\nWith QtWebEngine, writing the clipboard as response "
             "to a user interaction is always allowed."),

            ('ignore-javascript-prompt',
             SettingValue(typ.Bool(), 'false'),
             "Whether all javascript prompts should be ignored."),

            ('ignore-javascript-alert',
             SettingValue(typ.Bool(), 'false'),
             "Whether all javascript alerts should be ignored."),

            ('local-content-can-access-remote-urls',
             SettingValue(typ.Bool(), 'false'),
             "Whether locally loaded documents are allowed to access remote "
             "urls."),

            ('local-content-can-access-file-urls',
             SettingValue(typ.Bool(), 'true'),
             "Whether locally loaded documents are allowed to access other "
             "local urls."),

            ('cookies-accept',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('all', "Accept all cookies."),
                     ('no-3rdparty', "Accept cookies from the same"
                      " origin only."),
                     ('no-unknown-3rdparty', "Accept cookies from "
                      "the same origin only, unless a cookie is "
                      "already set for the domain."),
                     ('never', "Don't accept cookies at all.")
                 )), 'no-3rdparty', backends=[usertypes.Backend.QtWebKit]),
             "Control which cookies to accept."),

            ('cookies-store',
             SettingValue(typ.Bool(), 'true'),
             "Whether to store cookies. Note this option needs a restart with "
             "QtWebEngine on Qt < 5.9."),

            ('host-block-lists',
             SettingValue(
                 typ.List(typ.Url(), none_ok=True),
                 'https://www.malwaredomainlist.com/hostslist/hosts.txt,'
                 'http://someonewhocares.org/hosts/hosts,'
                 'http://winhelp2002.mvps.org/hosts.zip,'
                 'http://malwaredomains.lehigh.edu/files/justdomains.zip,'
                 'https://pgl.yoyo.org/adservers/serverlist.php?'
                 'hostformat=hosts&mimetype=plaintext'),
             "List of URLs of lists which contain hosts to block.\n\n"
             "The file can be in one of the following formats:\n\n"
             "- An '/etc/hosts'-like file\n"
             "- One host per line\n"
             "- A zip-file of any of the above, with either only one file, or "
             "a file named 'hosts' (with any extension)."),

            ('host-blocking-enabled',
             SettingValue(typ.Bool(), 'true'),
             "Whether host blocking is enabled."),

            ('host-blocking-whitelist',
             SettingValue(typ.List(typ.String(), none_ok=True), 'piwik.org'),
             "List of domains that should always be loaded, despite being "
             "ad-blocked.\n\n"
             "Domains may contain * and ? wildcards and are otherwise "
             "required to exactly match the requested domain.\n\n"
             "Local domains are always exempt from hostblocking."),

            ('enable-pdfjs', SettingValue(typ.Bool(), 'false'),
             "Enable pdf.js to view PDF files in the browser.\n\n"
             "Note that the files can still be downloaded by clicking"
             " the download button in the pdf.js viewer."),

            readonly=readonly
        )),

        ('hints', sect.KeyValue(
            ('border',
             SettingValue(typ.String(), '1px solid #E3BE23'),
             "CSS border value for hints."),

            ('mode',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('number', "Use numeric hints. (In this mode you can "
                      "also type letters form the hinted element to filter "
                      "and reduce the number of elements that are hinted.)"),
                     ('letter', "Use the chars in the hints -> "
                      "chars setting."),
                     ('word', "Use hints words based on the html "
                      "elements and the extra words."),
                 )), 'letter'),
             "Mode to use for hints."),

            ('chars',
             SettingValue(typ.UniqueCharString(minlen=2, completions=[
                 ('asdfghjkl', "Home row"),
                 ('aoeuidnths', "Home row (Dvorak)"),
                 ('abcdefghijklmnopqrstuvwxyz', "All letters"),
             ]), 'asdfghjkl'),
             "Chars used for hint strings."),

            ('min-chars',
             SettingValue(typ.Int(minval=1), '1'),
             "Minimum number of chars used for hint strings."),

            ('scatter',
             SettingValue(typ.Bool(), 'true'),
             "Whether to scatter hint key chains (like Vimium) or not (like "
             "dwb). Ignored for number hints."),

            ('uppercase',
             SettingValue(typ.Bool(), 'false'),
             "Make chars in hint strings uppercase."),

            ('dictionary',
             SettingValue(typ.File(required=False), '/usr/share/dict/words'),
             "The dictionary file to be used by the word hints."),

            ('auto-follow',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('always', "Auto-follow whenever there is only a single "
                      "hint on a page."),
                     ('unique-match', "Auto-follow whenever there is a unique "
                      "non-empty match in either the hint string (word mode) "
                      "or filter (number mode)."),
                     ('full-match', "Follow the hint when the user typed the "
                      "whole hint (letter, word or number mode) or the "
                      "element's text (only in number mode)."),
                     ('never', "The user will always need to press Enter to "
                      "follow a hint."),
                 )), 'unique-match'),
             "Controls when a hint can be automatically followed without the "
             "user pressing Enter."),

            ('auto-follow-timeout',
             SettingValue(typ.Int(), '0'),
             "A timeout (in milliseconds) to inhibit normal-mode key bindings "
             "after a successful auto-follow."),

            ('next-regexes',
             SettingValue(typ.List(typ.Regex(flags=re.IGNORECASE)),
                          r'\bnext\b,\bmore\b,\bnewer\b,\b[>→≫]\b,\b(>>|»)\b,'
                          r'\bcontinue\b'),
             "A comma-separated list of regexes to use for 'next' links."),

            ('prev-regexes',
             SettingValue(typ.List(typ.Regex(flags=re.IGNORECASE)),
                          r'\bprev(ious)?\b,\bback\b,\bolder\b,\b[<←≪]\b,'
                          r'\b(<<|«)\b'),
             "A comma-separated list of regexes to use for 'prev' links."),

            ('find-implementation',
             SettingValue(typ.String(
                 valid_values=typ.ValidValues(
                     ('javascript', "Better but slower"),
                     ('python', "Slightly worse but faster"),
                 )), 'python'),
             "Which implementation to use to find elements to hint."),

            ('hide-unmatched-rapid-hints',
             SettingValue(typ.Bool(), 'true'),
             "Controls hiding unmatched hints in rapid mode."),

            readonly=readonly
        )),

        ('searchengines', sect.ValueList(
            typ.SearchEngineName(), typ.SearchEngineUrl(),
            ('DEFAULT', 'https://duckduckgo.com/?q={}'),

            readonly=readonly
        )),

        ('aliases', sect.ValueList(
            typ.String(forbidden=' '), typ.Command(),

            readonly=readonly
        )),

        ('colors', sect.KeyValue(
            ('completion.fg',
             SettingValue(typ.QtColor(), 'white'),
             "Text color of the completion widget."),

            ('completion.bg',
             SettingValue(typ.QssColor(), '#333333'),
             "Background color of the completion widget."),

            ('completion.alternate-bg',
             SettingValue(typ.QssColor(), '#444444'),
             "Alternating background color of the completion widget."),

            ('completion.category.fg',
             SettingValue(typ.QtColor(), 'white'),
             "Foreground color of completion widget category headers."),

            ('completion.category.bg',
             SettingValue(typ.QssColor(), 'qlineargradient(x1:0, y1:0, x2:0, '
                          'y2:1, stop:0 #888888, stop:1 #505050)'),
             "Background color of the completion widget category headers."),

            ('completion.category.border.top',
             SettingValue(typ.QssColor(), 'black'),
             "Top border color of the completion widget category headers."),

            ('completion.category.border.bottom',
             SettingValue(typ.QssColor(), '${completion.category.border.top}'),
             "Bottom border color of the completion widget category headers."),

            ('completion.item.selected.fg',
             SettingValue(typ.QtColor(), 'black'),
             "Foreground color of the selected completion item."),

            ('completion.item.selected.bg',
             SettingValue(typ.QssColor(), '#e8c000'),
             "Background color of the selected completion item."),

            ('completion.item.selected.border.top',
             SettingValue(typ.QssColor(), '#bbbb00'),
             "Top border color of the completion widget category headers."),

            ('completion.item.selected.border.bottom',
             SettingValue(
                 typ.QssColor(), '${completion.item.selected.border.top}'),
             "Bottom border color of the selected completion item."),

            ('completion.match.fg',
             SettingValue(typ.QssColor(), '#ff4444'),
             "Foreground color of the matched text in the completion."),

            ('completion.scrollbar.fg',
             SettingValue(typ.QssColor(), '${completion.fg}'),
             "Color of the scrollbar handle in completion view."),

            ('completion.scrollbar.bg',
             SettingValue(typ.QssColor(), '${completion.bg}'),
             "Color of the scrollbar in completion view"),

            ('statusbar.fg',
             SettingValue(typ.QssColor(), 'white'),
             "Foreground color of the statusbar."),

            ('statusbar.bg',
             SettingValue(typ.QssColor(), 'black'),
             "Background color of the statusbar."),

            ('statusbar.fg.private',
             SettingValue(typ.QssColor(), '${statusbar.fg}'),
             "Foreground color of the statusbar in private browsing mode."),

            ('statusbar.bg.private',
             SettingValue(typ.QssColor(), '#666666'),
             "Background color of the statusbar in private browsing mode."),

            ('statusbar.fg.insert',
             SettingValue(typ.QssColor(), '${statusbar.fg}'),
             "Foreground color of the statusbar in insert mode."),

            ('statusbar.bg.insert',
             SettingValue(typ.QssColor(), 'darkgreen'),
             "Background color of the statusbar in insert mode."),

            ('statusbar.fg.command',
             SettingValue(typ.QssColor(), '${statusbar.fg}'),
             "Foreground color of the statusbar in command mode."),

            ('statusbar.bg.command',
             SettingValue(typ.QssColor(), '${statusbar.bg}'),
             "Background color of the statusbar in command mode."),

            ('statusbar.fg.command.private',
             SettingValue(typ.QssColor(), '${statusbar.fg.private}'),
             "Foreground color of the statusbar in private browsing + command "
             "mode."),

            ('statusbar.bg.command.private',
             SettingValue(typ.QssColor(), '${statusbar.bg.private}'),
             "Background color of the statusbar in private browsing + command "
             "mode."),

            ('statusbar.fg.caret',
             SettingValue(typ.QssColor(), '${statusbar.fg}'),
             "Foreground color of the statusbar in caret mode."),

            ('statusbar.bg.caret',
             SettingValue(typ.QssColor(), 'purple'),
             "Background color of the statusbar in caret mode."),

            ('statusbar.fg.caret-selection',
             SettingValue(typ.QssColor(), '${statusbar.fg}'),
             "Foreground color of the statusbar in caret mode with a "
             "selection"),

            ('statusbar.bg.caret-selection',
             SettingValue(typ.QssColor(), '#a12dff'),
             "Background color of the statusbar in caret mode with a "
             "selection"),

            ('statusbar.progress.bg',
             SettingValue(typ.QssColor(), 'white'),
             "Background color of the progress bar."),

            ('statusbar.url.fg',
             SettingValue(typ.QssColor(), '${statusbar.fg}'),
             "Default foreground color of the URL in the statusbar."),

            ('statusbar.url.fg.success',
             SettingValue(typ.QssColor(), 'white'),
             "Foreground color of the URL in the statusbar on successful "
             "load (http)."),

            ('statusbar.url.fg.success.https',
             SettingValue(typ.QssColor(), 'lime'),
             "Foreground color of the URL in the statusbar on successful "
             "load (https)."),

            ('statusbar.url.fg.error',
             SettingValue(typ.QssColor(), 'orange'),
             "Foreground color of the URL in the statusbar on error."),

            ('statusbar.url.fg.warn',
             SettingValue(typ.QssColor(), 'yellow'),
             "Foreground color of the URL in the statusbar when there's a "
             "warning."),

            ('statusbar.url.fg.hover',
             SettingValue(typ.QssColor(), 'aqua'),
             "Foreground color of the URL in the statusbar for hovered "
             "links."),

            ('tabs.fg.odd',
             SettingValue(typ.QtColor(), 'white'),
             "Foreground color of unselected odd tabs."),

            ('tabs.bg.odd',
             SettingValue(typ.QtColor(), 'grey'),
             "Background color of unselected odd tabs."),

            ('tabs.fg.even',
             SettingValue(typ.QtColor(), 'white'),
             "Foreground color of unselected even tabs."),

            ('tabs.bg.even',
             SettingValue(typ.QtColor(), 'darkgrey'),
             "Background color of unselected even tabs."),

            ('tabs.fg.selected.odd',
             SettingValue(typ.QtColor(), 'white'),
             "Foreground color of selected odd tabs."),

            ('tabs.bg.selected.odd',
             SettingValue(typ.QtColor(), 'black'),
             "Background color of selected odd tabs."),

            ('tabs.fg.selected.even',
             SettingValue(typ.QtColor(), '${tabs.fg.selected.odd}'),
             "Foreground color of selected even tabs."),

            ('tabs.bg.selected.even',
             SettingValue(typ.QtColor(), '${tabs.bg.selected.odd}'),
             "Background color of selected even tabs."),

            ('tabs.bg.bar',
             SettingValue(typ.QtColor(), '#555555'),
             "Background color of the tab bar."),

            ('tabs.indicator.start',
             SettingValue(typ.QtColor(), '#0000aa'),
             "Color gradient start for the tab indicator."),

            ('tabs.indicator.stop',
             SettingValue(typ.QtColor(), '#00aa00'),
             "Color gradient end for the tab indicator."),

            ('tabs.indicator.error',
             SettingValue(typ.QtColor(), '#ff0000'),
             "Color for the tab indicator on errors.."),

            ('tabs.indicator.system',
             SettingValue(typ.ColorSystem(), 'rgb'),
             "Color gradient interpolation system for the tab indicator."),

            ('hints.fg',
             SettingValue(typ.QssColor(), 'black'),
             "Font color for hints."),

            ('hints.bg',
             SettingValue(typ.QssColor(), 'qlineargradient(x1:0, y1:0, x2:0, '
                          'y2:1, stop:0 rgba(255, 247, 133, 0.8), '
                          'stop:1 rgba(255, 197, 66, 0.8))'),
             "Background color for hints. Note that you can use a `rgba(...)` "
             "value for transparency."),

            ('hints.fg.match',
             SettingValue(typ.QssColor(), 'green'),
             "Font color for the matched part of hints."),

            ('downloads.bg.bar',
             SettingValue(typ.QssColor(), 'black'),
             "Background color for the download bar."),

            ('downloads.fg.start',
             SettingValue(typ.QtColor(), 'white'),
             "Color gradient start for download text."),

            ('downloads.bg.start',
             SettingValue(typ.QtColor(), '#0000aa'),
             "Color gradient start for download backgrounds."),

            ('downloads.fg.stop',
             SettingValue(typ.QtColor(), '${downloads.fg.start}'),
             "Color gradient end for download text."),

            ('downloads.bg.stop',
             SettingValue(typ.QtColor(), '#00aa00'),
             "Color gradient stop for download backgrounds."),

            ('downloads.fg.system',
             SettingValue(typ.ColorSystem(), 'rgb'),
             "Color gradient interpolation system for download text."),

            ('downloads.bg.system',
             SettingValue(typ.ColorSystem(), 'rgb'),
             "Color gradient interpolation system for download backgrounds."),

            ('downloads.fg.error',
             SettingValue(typ.QtColor(), 'white'),
             "Foreground color for downloads with errors."),

            ('downloads.bg.error',
             SettingValue(typ.QtColor(), 'red'),
             "Background color for downloads with errors."),

            ('webpage.bg',
             SettingValue(typ.QtColor(none_ok=True), 'white'),
             "Background color for webpages if unset (or empty to use the "
             "theme's color)"),

            ('keyhint.fg',
             SettingValue(typ.QssColor(), '#FFFFFF'),
             "Text color for the keyhint widget."),

            ('keyhint.fg.suffix',
             SettingValue(typ.CssColor(), '#FFFF00'),
             "Highlight color for keys to complete the current keychain"),

            ('keyhint.bg',
             SettingValue(typ.QssColor(), 'rgba(0, 0, 0, 80%)'),
             "Background color of the keyhint widget."),

            ('messages.fg.error',
             SettingValue(typ.QssColor(), 'white'),
             "Foreground color of an error message."),

            ('messages.bg.error',
             SettingValue(typ.QssColor(), 'red'),
             "Background color of an error message."),

            ('messages.border.error',
             SettingValue(typ.QssColor(), '#bb0000'),
             "Border color of an error message."),

            ('messages.fg.warning',
             SettingValue(typ.QssColor(), 'white'),
             "Foreground color a warning message."),

            ('messages.bg.warning',
             SettingValue(typ.QssColor(), 'darkorange'),
             "Background color of a warning message."),

            ('messages.border.warning',
             SettingValue(typ.QssColor(), '#d47300'),
             "Border color of an error message."),

            ('messages.fg.info',
             SettingValue(typ.QssColor(), 'white'),
             "Foreground color an info message."),

            ('messages.bg.info',
             SettingValue(typ.QssColor(), 'black'),
             "Background color of an info message."),

            ('messages.border.info',
             SettingValue(typ.QssColor(), '#333333'),
             "Border color of an info message."),

            ('prompts.fg',
             SettingValue(typ.QssColor(), 'white'),
             "Foreground color for prompts."),

            ('prompts.bg',
             SettingValue(typ.QssColor(), 'darkblue'),
             "Background color for prompts."),

            ('prompts.selected.bg',
             SettingValue(typ.QssColor(), '#308cc6'),
             "Background color for the selected item in filename prompts."),

            readonly=readonly
        )),

        ('fonts', sect.KeyValue(
            ('_monospace',
             SettingValue(typ.Font(), 'xos4 Terminus, Terminus, Monospace, '
                          '"DejaVu Sans Mono", Monaco, '
                          '"Bitstream Vera Sans Mono", "Andale Mono", '
                          '"Courier New", Courier, "Liberation Mono", '
                          'monospace, Fixed, Consolas, Terminal'),
             "Default monospace fonts."),

            ('completion',
             SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
             "Font used in the completion widget."),

            ('completion.category',
             SettingValue(typ.Font(), 'bold ${completion}'),
             "Font used in the completion categories."),

            ('tabbar',
             SettingValue(typ.QtFont(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
             "Font used in the tab bar."),

            ('statusbar',
             SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
             "Font used in the statusbar."),

            ('downloads',
             SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
             "Font used for the downloadbar."),

            ('hints',
             SettingValue(typ.Font(), 'bold 13px ${_monospace}'),
             "Font used for the hints."),

            ('debug-console',
             SettingValue(typ.QtFont(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
             "Font used for the debugging console."),

            ('web-family-standard',
             SettingValue(typ.FontFamily(none_ok=True), ''),
             "Font family for standard fonts."),

            ('web-family-fixed',
             SettingValue(typ.FontFamily(none_ok=True), ''),
             "Font family for fixed fonts."),

            ('web-family-serif',
             SettingValue(typ.FontFamily(none_ok=True), ''),
             "Font family for serif fonts."),

            ('web-family-sans-serif',
             SettingValue(typ.FontFamily(none_ok=True), ''),
             "Font family for sans-serif fonts."),

            ('web-family-cursive',
             SettingValue(typ.FontFamily(none_ok=True), ''),
             "Font family for cursive fonts."),

            ('web-family-fantasy',
             SettingValue(typ.FontFamily(none_ok=True), ''),
             "Font family for fantasy fonts."),

            # Defaults for web-size-* from WebEngineSettings::initDefaults in
            # qtwebengine/src/core/web_engine_settings.cpp and
            # QWebSettings::QWebSettings() in
            # qtwebkit/Source/WebKit/qt/Api/qwebsettings.cpp

            ('web-size-minimum',
             SettingValue(typ.Int(minval=0, maxval=MAXVALS['int']), '0'),
             "The hard minimum font size."),

            # This is 0 as default on QtWebKit, and 6 on QtWebEngine - so let's
            # just go for 6 here.
            ('web-size-minimum-logical',
             SettingValue(typ.Int(minval=0, maxval=MAXVALS['int']), '6'),
             "The minimum logical font size that is applied when zooming "
             "out."),

            ('web-size-default',
             SettingValue(typ.Int(minval=1, maxval=MAXVALS['int']), '16'),
             "The default font size for regular text."),

            ('web-size-default-fixed',
             SettingValue(typ.Int(minval=1, maxval=MAXVALS['int']), '13'),
             "The default font size for fixed-pitch text."),

            ('keyhint',
             SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
             "Font used in the keyhint widget."),

            ('messages.error',
             SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
             "Font used for error messages."),

            ('messages.warning',
             SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
             "Font used for warning messages."),

            ('messages.info',
             SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' ${_monospace}'),
             "Font used for info messages."),

            ('prompts',
             SettingValue(typ.Font(), DEFAULT_FONT_SIZE + ' sans-serif'),
             "Font used for prompts."),

            readonly=readonly
        )),
    ])


DATA = data(readonly=True)


KEY_FIRST_COMMENT = """
# vim: ft=conf
#
# In this config file, qutebrowser's key bindings are configured.
# The format looks like this:
#
# [keymode]
#
# command
#   keychain
#   keychain2
#   ...
#
# All blank lines and lines starting with '#' are ignored.
# Inline-comments are not permitted.
#
# keymode is a comma separated list of modes in which the key binding should be
# active. If keymode starts with !, the key binding is active in all modes
# except the listed modes.
#
# For special keys (can't be part of a keychain), enclose them in `<`...`>`.
# For modifiers, you can use either `-` or `+` as delimiters, and these names:
#
#  * Control: `Control`, `Ctrl`
#  * Meta:    `Meta`, `Windows`, `Mod4`
#  * Alt:     `Alt`, `Mod1`
#  * Shift:   `Shift`
#
# For simple keys (no `<>`-signs), a capital letter means the key is pressed
# with Shift. For special keys (with `<>`-signs), you need to explicitly add
# `Shift-` to match a key pressed with shift.
#
# Note that default keybindings are always bound, and need to be explicitly
# unbound if you wish to remove them:
#
# <unbound>
#   keychain
#   keychain2
#   ...
"""

KEY_SECTION_DESC = {
    'all': "Keybindings active in all modes.",
    'normal': "Keybindings for normal mode.",
    'insert': (
        "Keybindings for insert mode.\n"
        "Since normal keypresses are passed through, only special keys are "
        "supported in this mode.\n"
        "Useful hidden commands to map in this section:\n\n"
        " * `open-editor`: Open a texteditor with the focused field.\n"
        " * `paste-primary`: Paste primary selection at cursor position."),
    'hint': (
        "Keybindings for hint mode.\n"
        "Since normal keypresses are passed through, only special keys are "
        "supported in this mode.\n"
        "Useful hidden commands to map in this section:\n\n"
        " * `follow-hint`: Follow the currently selected hint."),
    'passthrough': (
        "Keybindings for passthrough mode.\n"
        "Since normal keypresses are passed through, only special keys are "
        "supported in this mode."),
    'command': (
        "Keybindings for command mode.\n"
        "Since normal keypresses are passed through, only special keys are "
        "supported in this mode.\n"
        "Useful hidden commands to map in this section:\n\n"
        " * `command-history-prev`: Switch to previous command in history.\n"
        " * `command-history-next`: Switch to next command in history.\n"
        " * `completion-item-focus`: Select another item in completion.\n"
        " * `command-accept`: Execute the command currently in the "
        "commandline."),
    'prompt': (
        "Keybindings for prompts in the status line.\n"
        "You can bind normal keys in this mode, but they will be only active "
        "when a yes/no-prompt is asked. For other prompt modes, you can only "
        "bind special keys.\n"
        "Useful hidden commands to map in this section:\n\n"
        " * `prompt-accept`: Confirm the entered value.\n"
        " * `prompt-accept yes`: Answer yes to a yes/no question.\n"
        " * `prompt-accept no`: Answer no to a yes/no question."),
    'caret': (
        ""),
}

# Keys which are similar to Return and should be bound by default where Return
# is bound.

RETURN_KEYS = ['<Return>', '<Ctrl-M>', '<Ctrl-J>', '<Shift-Return>', '<Enter>',
               '<Shift-Enter>']


KEY_DATA = collections.OrderedDict([
    ('!normal', collections.OrderedDict([
        ('leave-mode', ['<Escape>', '<Ctrl-[>']),
    ])),

    ('normal', collections.OrderedDict([
        ('clear-keychain ;; search ;; fullscreen --leave',
            ['<Escape>', '<Ctrl-[>']),
        ('set-cmd-text -s :open', ['o']),
        ('set-cmd-text :open {url:pretty}', ['go']),
        ('set-cmd-text -s :open -t', ['O']),
        ('set-cmd-text :open -t -i {url:pretty}', ['gO']),
        ('set-cmd-text -s :open -b', ['xo']),
        ('set-cmd-text :open -b -i {url:pretty}', ['xO']),
        ('set-cmd-text -s :open -w', ['wo']),
        ('set-cmd-text :open -w {url:pretty}', ['wO']),
        ('set-cmd-text /', ['/']),
        ('set-cmd-text ?', ['?']),
        ('set-cmd-text :', [':']),
        ('open -t', ['ga', '<Ctrl-T>']),
        ('open -w', ['<Ctrl-N>']),
        ('tab-close', ['d', '<Ctrl-W>']),
        ('tab-close -o', ['D']),
        ('tab-only', ['co']),
        ('tab-focus', ['T']),
        ('tab-move', ['gm']),
        ('tab-move -', ['gl']),
        ('tab-move +', ['gr']),
        ('tab-next', ['J', '<Ctrl-PgDown>']),
        ('tab-prev', ['K', '<Ctrl-PgUp>']),
        ('tab-clone', ['gC']),
        ('reload', ['r', '<F5>']),
        ('reload -f', ['R', '<Ctrl-F5>']),
        ('back', ['H', '<back>']),
        ('back -t', ['th']),
        ('back -w', ['wh']),
        ('forward', ['L', '<forward>']),
        ('forward -t', ['tl']),
        ('forward -w', ['wl']),
        ('fullscreen', ['<F11>']),
        ('hint', ['f']),
        ('hint all tab', ['F']),
        ('hint all window', ['wf']),
        ('hint all tab-bg', [';b']),
        ('hint all tab-fg', [';f']),
        ('hint all hover', [';h']),
        ('hint images', [';i']),
        ('hint images tab', [';I']),
        ('hint links fill :open {hint-url}', [';o']),
        ('hint links fill :open -t -i {hint-url}', [';O']),
        ('hint links yank', [';y']),
        ('hint links yank-primary', [';Y']),
        ('hint --rapid links tab-bg', [';r']),
        ('hint --rapid links window', [';R']),
        ('hint links download', [';d']),
        ('hint inputs', [';t']),
        ('scroll left', ['h']),
        ('scroll down', ['j']),
        ('scroll up', ['k']),
        ('scroll right', ['l']),
        ('undo', ['u', '<Ctrl-Shift-T>']),
        ('scroll-perc 0', ['gg']),
        ('scroll-perc', ['G']),
        ('search-next', ['n']),
        ('search-prev', ['N']),
        ('enter-mode insert', ['i']),
        ('enter-mode caret', ['v']),
        ('enter-mode set_mark', ['`']),
        ('enter-mode jump_mark', ["'"]),
        ('yank', ['yy']),
        ('yank -s', ['yY']),
        ('yank title', ['yt']),
        ('yank title -s', ['yT']),
        ('yank domain', ['yd']),
        ('yank domain -s', ['yD']),
        ('yank pretty-url', ['yp']),
        ('yank pretty-url -s', ['yP']),
        ('open -- {clipboard}', ['pp']),
        ('open -- {primary}', ['pP']),
        ('open -t -- {clipboard}', ['Pp']),
        ('open -t -- {primary}', ['PP']),
        ('open -w -- {clipboard}', ['wp']),
        ('open -w -- {primary}', ['wP']),
        ('quickmark-save', ['m']),
        ('set-cmd-text -s :quickmark-load', ['b']),
        ('set-cmd-text -s :quickmark-load -t', ['B']),
        ('set-cmd-text -s :quickmark-load -w', ['wb']),
        ('bookmark-add', ['M']),
        ('set-cmd-text -s :bookmark-load', ['gb']),
        ('set-cmd-text -s :bookmark-load -t', ['gB']),
        ('set-cmd-text -s :bookmark-load -w', ['wB']),
        ('save', ['sf']),
        ('set-cmd-text -s :set', ['ss']),
        ('set-cmd-text -s :set -t', ['sl']),
        ('set-cmd-text -s :bind', ['sk']),
        ('zoom-out', ['-']),
        ('zoom-in', ['+']),
        ('zoom', ['=']),
        ('navigate prev', ['[[']),
        ('navigate next', [']]']),
        ('navigate prev -t', ['{{']),
        ('navigate next -t', ['}}']),
        ('navigate up', ['gu']),
        ('navigate up -t', ['gU']),
        ('navigate increment', ['<Ctrl-A>']),
        ('navigate decrement', ['<Ctrl-X>']),
        ('inspector', ['wi']),
        ('download', ['gd']),
        ('download-cancel', ['ad']),
        ('download-clear', ['cd']),
        ('view-source', ['gf']),
        ('set-cmd-text -s :buffer', ['gt']),
        ('tab-focus last', ['<Ctrl-Tab>', '<Ctrl-6>', '<Ctrl-^>']),
        ('enter-mode passthrough', ['<Ctrl-V>']),
        ('quit', ['<Ctrl-Q>', 'ZQ']),
        ('wq', ['ZZ']),
        ('scroll-page 0 1', ['<Ctrl-F>']),
        ('scroll-page 0 -1', ['<Ctrl-B>']),
        ('scroll-page 0 0.5', ['<Ctrl-D>']),
        ('scroll-page 0 -0.5', ['<Ctrl-U>']),
        ('tab-focus 1', ['<Alt-1>', 'g0', 'g^']),
        ('tab-focus 2', ['<Alt-2>']),
        ('tab-focus 3', ['<Alt-3>']),
        ('tab-focus 4', ['<Alt-4>']),
        ('tab-focus 5', ['<Alt-5>']),
        ('tab-focus 6', ['<Alt-6>']),
        ('tab-focus 7', ['<Alt-7>']),
        ('tab-focus 8', ['<Alt-8>']),
        ('tab-focus -1', ['<Alt-9>', 'g$']),
        ('home', ['<Ctrl-h>']),
        ('stop', ['<Ctrl-s>']),
        ('print', ['<Ctrl-Alt-p>']),
        ('open qute://settings', ['Ss']),
        ('follow-selected', RETURN_KEYS),
        ('follow-selected -t', ['<Ctrl-Return>', '<Ctrl-Enter>']),
        ('repeat-command', ['.']),
        ('tab-pin', ['<Ctrl-p>']),
        ('record-macro', ['q']),
        ('run-macro', ['@']),
    ])),

    ('insert', collections.OrderedDict([
        ('open-editor', ['<Ctrl-E>']),
        ('insert-text {primary}', ['<Shift-Ins>']),
    ])),

    ('hint', collections.OrderedDict([
        ('follow-hint', RETURN_KEYS),
        ('hint --rapid links tab-bg', ['<Ctrl-R>']),
        ('hint links', ['<Ctrl-F>']),
        ('hint all tab-bg', ['<Ctrl-B>']),
    ])),

    ('passthrough', {}),

    ('command', collections.OrderedDict([
        ('command-history-prev', ['<Ctrl-P>']),
        ('command-history-next', ['<Ctrl-N>']),
        ('completion-item-focus prev', ['<Shift-Tab>', '<Up>']),
        ('completion-item-focus next', ['<Tab>', '<Down>']),
        ('completion-item-focus next-category', ['<Ctrl-Tab>']),
        ('completion-item-focus prev-category', ['<Ctrl-Shift-Tab>']),
        ('completion-item-del', ['<Ctrl-D>']),
        ('command-accept', RETURN_KEYS),
    ])),

    ('prompt', collections.OrderedDict([
        ('prompt-accept', RETURN_KEYS),
        ('prompt-accept yes', ['y']),
        ('prompt-accept no', ['n']),
        ('prompt-open-download', ['<Ctrl-X>']),
        ('prompt-item-focus prev', ['<Shift-Tab>', '<Up>']),
        ('prompt-item-focus next', ['<Tab>', '<Down>']),
    ])),

    ('command,prompt', collections.OrderedDict([
        ('rl-backward-char', ['<Ctrl-B>']),
        ('rl-forward-char', ['<Ctrl-F>']),
        ('rl-backward-word', ['<Alt-B>']),
        ('rl-forward-word', ['<Alt-F>']),
        ('rl-beginning-of-line', ['<Ctrl-A>']),
        ('rl-end-of-line', ['<Ctrl-E>']),
        ('rl-unix-line-discard', ['<Ctrl-U>']),
        ('rl-kill-line', ['<Ctrl-K>']),
        ('rl-kill-word', ['<Alt-D>']),
        ('rl-unix-word-rubout', ['<Ctrl-W>']),
        ('rl-backward-kill-word', ['<Alt-Backspace>']),
        ('rl-yank', ['<Ctrl-Y>']),
        ('rl-delete-char', ['<Ctrl-?>']),
        ('rl-backward-delete-char', ['<Ctrl-H>']),
    ])),

    ('caret', collections.OrderedDict([
        ('toggle-selection', ['v', '<Space>']),
        ('drop-selection', ['<Ctrl-Space>']),
        ('enter-mode normal', ['c']),
        ('move-to-next-line', ['j']),
        ('move-to-prev-line', ['k']),
        ('move-to-next-char', ['l']),
        ('move-to-prev-char', ['h']),
        ('move-to-end-of-word', ['e']),
        ('move-to-next-word', ['w']),
        ('move-to-prev-word', ['b']),
        ('move-to-start-of-next-block', [']']),
        ('move-to-start-of-prev-block', ['[']),
        ('move-to-end-of-next-block', ['}']),
        ('move-to-end-of-prev-block', ['{']),
        ('move-to-start-of-line', ['0']),
        ('move-to-end-of-line', ['$']),
        ('move-to-start-of-document', ['gg']),
        ('move-to-end-of-document', ['G']),
        ('yank selection -s', ['Y']),
        ('yank selection', ['y'] + RETURN_KEYS),
        ('scroll left', ['H']),
        ('scroll down', ['J']),
        ('scroll up', ['K']),
        ('scroll right', ['L']),
    ])),
])


# A list of (regex, replacement) tuples of changed key commands.

CHANGED_KEY_COMMANDS = [
    (re.compile(r'^open -([twb]) about:blank$'), r'open -\1'),

    (re.compile(r'^download-page$'), r'download'),
    (re.compile(r'^cancel-download$'), r'download-cancel'),

    (re.compile(r"""^search (''|"")$"""),
        r'clear-keychain ;; search ;; fullscreen --leave'),
    (re.compile(r'^search$'),
        r'clear-keychain ;; search ;; fullscreen --leave'),
    (re.compile(r'^clear-keychain ;; search$'),
        r'clear-keychain ;; search ;; fullscreen --leave'),

    (re.compile(r"""^set-cmd-text ['"](.*) ['"]$"""), r'set-cmd-text -s \1'),
    (re.compile(r"""^set-cmd-text ['"](.*)['"]$"""), r'set-cmd-text \1'),

    (re.compile(r"^hint links rapid$"), r'hint --rapid links tab-bg'),
    (re.compile(r"^hint links rapid-win$"), r'hint --rapid links window'),

    (re.compile(r'^scroll -50 0$'), r'scroll left'),
    (re.compile(r'^scroll 0 50$'), r'scroll down'),
    (re.compile(r'^scroll 0 -50$'), r'scroll up'),
    (re.compile(r'^scroll 50 0$'), r'scroll right'),
    (re.compile(r'^scroll ([-\d]+ [-\d]+)$'), r'scroll-px \1'),

    (re.compile(r'^search *;; *clear-keychain$'),
        r'clear-keychain ;; search ;; fullscreen --leave'),
    (re.compile(r'^clear-keychain *;; *leave-mode$'), r'leave-mode'),

    (re.compile(r'^download-remove --all$'), r'download-clear'),

    (re.compile(r'^hint links fill "([^"]*)"$'), r'hint links fill \1'),

    (re.compile(r'^yank -t(\S+)'), r'yank title -\1'),
    (re.compile(r'^yank -t'), r'yank title'),
    (re.compile(r'^yank -d(\S+)'), r'yank domain -\1'),
    (re.compile(r'^yank -d'), r'yank domain'),
    (re.compile(r'^yank -p(\S+)'), r'yank pretty-url -\1'),
    (re.compile(r'^yank -p'), r'yank pretty-url'),
    (re.compile(r'^yank-selected -p'), r'yank selection -s'),
    (re.compile(r'^yank-selected'), r'yank selection'),

    (re.compile(r'^paste$'), r'open -- {clipboard}'),
    (re.compile(r'^paste -s$'), r'open -- {primary}'),
    (re.compile(r'^paste -([twb])$'), r'open -\1 -- {clipboard}'),
    (re.compile(r'^paste -([twb])s$'), r'open -\1 -- {primary}'),
    (re.compile(r'^paste -s([twb])$'), r'open -\1 -- {primary}'),

    (re.compile(r'^completion-item-next'), r'completion-item-focus next'),
    (re.compile(r'^completion-item-prev'), r'completion-item-focus prev'),

    (re.compile(r'^open {clipboard}$'), r'open -- {clipboard}'),
    (re.compile(r'^open -([twb]) {clipboard}$'), r'open -\1 -- {clipboard}'),
    (re.compile(r'^open {primary}$'), r'open -- {primary}'),
    (re.compile(r'^open -([twb]) {primary}$'), r'open -\1 -- {primary}'),

    (re.compile(r'^paste-primary$'), r'insert-text {primary}'),

    (re.compile(r'^set-cmd-text -s :search$'), r'set-cmd-text /'),
    (re.compile(r'^set-cmd-text -s :search -r$'), r'set-cmd-text ?'),
    (re.compile(r'^set-cmd-text -s :$'), r'set-cmd-text :'),
    (re.compile(r'^set-cmd-text -s :set keybind$'), r'set-cmd-text -s :bind'),

    (re.compile(r'^prompt-yes$'), r'prompt-accept yes'),
    (re.compile(r'^prompt-no$'), r'prompt-accept no'),

    (re.compile(r'^tab-close -l$'), r'tab-close --prev'),
    (re.compile(r'^tab-close --left$'), r'tab-close --prev'),
    (re.compile(r'^tab-close -r$'), r'tab-close --next'),
    (re.compile(r'^tab-close --right$'), r'tab-close --next'),

    (re.compile(r'^tab-only -l$'), r'tab-only --prev'),
    (re.compile(r'^tab-only --left$'), r'tab-only --prev'),
    (re.compile(r'^tab-only -r$'), r'tab-only --next'),
    (re.compile(r'^tab-only --right$'), r'tab-only --next'),
]