/
dial.txt
1601 lines (1344 loc) · 46.8 KB
/
dial.txt
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
*dial.txt* Lua plugin that extends CTRL-A / CTRL-X
A package that extends the standard Vim commands CTRL-A / CTRL-X to allow
increment/decrement of various strings, not limited to alphanumeric
characters.
Author: Mogami Shinichi (@monaqa) <cmonaqa{at}google.com>
Version: 0.3.0
License: MIT license
<https://github.com/monaqa/dial.nvim/blob/master/LICENSE>
==============================================================================
CONTENTS *dial-contents*
Requirements |dial-requirements|
Introduction |dial-introduction|
Features |dial-features|
Usage |dial-usage|
Configurations |dial-config|
Aliases |dial-aliases|
Augends |dial-augends|
Number |dial-augends-number|
Date |dial-augends-date|
Constant |dial-augends-constant|
Case |dial-augends-case|
Hexcolor |dial-augends-hexcolor|
Semver |dial-augends-semver|
Paren |dial-augends-paren|
Misc |dial-augends-misc|
User |dial-augends-user|
Advanced Usage |dial-advanced-usage|
Dot Repeating |dial-dot-repeating|
Additive Dot Repeating |dial-additive-dot-repeating|
Interface |dial-interface|
Mapping |dial-mapping|
Command |dial-command|
Lua API |dial-lua-api|
==============================================================================
REQUIREMENTS *dial-requirements*
* Neovim 0.6.1 or later
(0.5.0 or later will probably work, but not guaranteed)
==============================================================================
INTRODUCTION *dial-introduction*
*dial.nvim* is a package that increments/decrements strings of various
formats. It extends the standard Vim commands such as CTRL-A, CTRL-X, and g
CTRL-A in VISUAL mode. For example, the following strings are covered.
------------------------------------------------------------------------------
FEATURES *dial-features*
Increment/Decrement of various type of string~
You can increment/decrement a wide variety of strings, as follows:
* n-ary (`2 <= n <= 36`) integers
* date
* constant (toggle a specific string, such as a keyword or operator)
* `true` ⇄ `false`
* `&&` ⇄ `||`
* `a` ⇄ `b` ⇄ ... ⇄ `z`
* hex colors
* semantic version
You can also define new increment/decrement rules.
Flexible configuration of target (augends)~
|dial.nvim| provides a lot of rules, and you can select and activate only
the ones you really need.
Although some rules of |dial.nvim| have conflicts, such as dates in
`mm/dd/yyyy` format and dates in `dd/mm/yyyy` format, you can enable only
one of them to perform operations without conflicts.
It is also possible to change the target only for a specific buffer or
|filetype|.
Support counter~
You can change addends (the number of additions) by typing `10<C-a>` as
well as the usual CTRL-A / CTRL-X.
Support dot repeating~
You can repeat the previous operation with |.|.
|dial.nvim| remembers the last increment or decrement target type. For
example, if the last increment was "month in `yyyy/mm/dd` format",
dot-repeat will find and increment the same type, "month in `yyyy/mm/dd`
format", even if there is another string to increment or decrement before
it.
Support VISUAL mode~
You can also use |dial.nvim|'s operation in VISUAL mode.
==============================================================================
USAGE *dial-usage*
Since this plugin does not replace the default key-mapping, you need to add
the following description to the configuration file after installing the
plugin.
>
nmap <C-a> <Plug>(dial-increment)
nmap <C-x> <Plug>(dial-decrement)
nmap g<C-a> g<Plug>(dial-increment)
nmap g<C-x> g<Plug>(dial-decrement)
vmap <C-a> <Plug>(dial-increment)
vmap <C-x> <Plug>(dial-decrement)
vmap g<C-a> g<Plug>(dial-increment)
vmap g<C-x> g<Plug>(dial-decrement)
<
Alternatively, you can configure with Lua as follows:
>
vim.keymap.set("n", "<C-a>", function()
require("dial.map").manipulate("increment", "normal")
end)
vim.keymap.set("n", "<C-x>", function()
require("dial.map").manipulate("decrement", "normal")
end)
vim.keymap.set("n", "g<C-a>", function()
require("dial.map").manipulate("increment", "gnormal")
end)
vim.keymap.set("n", "g<C-x>", function()
require("dial.map").manipulate("decrement", "gnormal")
end)
vim.keymap.set("v", "<C-a>", function()
require("dial.map").manipulate("increment", "visual")
end)
vim.keymap.set("v", "<C-x>", function()
require("dial.map").manipulate("decrement", "visual")
end)
vim.keymap.set("v", "g<C-a>", function()
require("dial.map").manipulate("increment", "gvisual")
end)
vim.keymap.set("v", "g<C-x>", function()
require("dial.map").manipulate("decrement", "gvisual")
end)
<
==============================================================================
CONFIGURATIONS *dial-config*
In this plugin, flexible increment/decrement rules can be set by using augend
and group, where augend represents the target of the increment/decrement
operation, and group represents a group of multiple augends.
>
local augend = require("dial.augend")
require("dial.config").augends:register_group{
-- default augends used when no group name is specified
default = {
augend.integer.alias.decimal, -- nonnegative decimal number
augend.integer.alias.hex, -- nonnegative hex number
-- date (2022/02/19, etc.)
augend.date.new {
pattern = "%Y/%m/%d",
default_kind = "day",
},
},
-- augends used when group with name `mygroup` is specified
mygroup = {
augend.integer.alias.decimal,
augend.constant.alias.bool, -- boolean value (true <-> false)
-- date (02/19/2022, etc.)
augend.date.new {
pattern = "%m/%d/%Y",
default_kind = "day",
},
}
}
<
To define a group, use the `augends:register_group` function in the
`"dial.config"` module. The arguments is a dictionary whose keys are the group
names and whose values are the list of augends.
Various augends are defined `"dial.augend"` by default. See also:
|dial-augends| and |dial-aliases|.
To specify the group of augends, you can use expression register |@=| as follows:
>
"=mygroup<CR><C-a>
<
If it is tedious to specify the expression register for each increase or
decrease, you can "map" it:
>
nmap <Leader>a "=mygroup<CR><Plug>(dial-increment)
<
Alternatively, you can set the same mapping without expression register:
>
vim.api.nvim_set_keymap(
"n",
"<Leader>a",
require("dial.map").inc_normal("mygroup"),
{noremap = true}
)
<
*dial-config-augends-default*
Default Augend Group~
`default` group is a special group, which is specified by default.
If you don't specify the group name with expression register or other, the
augends in the `default` group is used instead.
If no settings are made, it is equivalent to having the following settings:
>
local augend = require("dial.augend")
require("dial.config").augends:register_group{
default = {
augend.integer.alias.decimal,
augend.integer.alias.hex,
augend.date.new {
pattern = "%Y/%m/%d",
default_kind = "day",
},
augend.date.new {
pattern = "%Y-%m-%d",
default_kind = "day",
},
augend.date.new {
pattern = "%m/%d",
default_kind = "day",
only_valid = true,
},
augend.date.new {
pattern = "%H:%M",
default_kind = "day",
only_valid = true,
},
augend.constant.alias.ja_weekday_full,
},
}
<
Augends Only Valid in VISUAL Mode~
>
local augend = require("dial.augend")
require("dial.config").augends:register_group{
visual = {
augend.integer.alias.decimal,
augend.integer.alias.hex,
augend.date.new {
pattern = "%Y/%m/%d",
default_kind = "day",
},
augend.constant.alias.alpha,
augend.constant.alias.Alpha,
},
}
-- change augends in VISUAL mode
vim.api.nvim_set_keymap(
"v", "<C-a>", require("dial.map").inc_normal("visual"), {noremap = true}
)
vim.api.nvim_set_keymap(
"v", "<C-x>", require("dial.map").dec_normal("visual"), {noremap = true}
)
<
Augends Only Valid in Specific File Type~
The `augends:on_filetype()` function can be used to change the augends used
for a particular filetype.
>
lua << EOF
local augend = require("dial.augend")
require("dial.config").augends:on_filetype {
typescript = {
augend.integer.alias.decimal,
augend.integer.alias.hex,
augend.constant.new { elements = { "true", "false" } },
augend.constant.new { elements = {"let", "const"} },
},
lua = {
augend.integer.alias.decimal,
augend.constant.new { elements = { "true", "false" } },
},
markdown = {
augend.integer.alias.decimal,
augend.misc.alias.markdown_header,
}
}
EOF
------------------------------------------------------------------------------
ALIASES *dial-aliases*
The following aliases are provided by default (See |dial-augends| for detail):
integer:
`augend.integer.alias.decimal`
`augend.integer.alias.decimal_int`
`augend.integer.alias.hex`
`augend.integer.alias.octal`
`augend.integer.alias.binary`
date:
`augend.date.alias["%Y/%m/%d"]`
`augend.date.alias["%m/%d/%Y"]`
`augend.date.alias["%d/%m/%Y"]`
`augend.date.alias["%m/%d/%y"]`
`augend.date.alias["%d/%m/%y"]`
`augend.date.alias["%m/%d"]`
`augend.date.alias["%-m/%-d"]`
`augend.date.alias["%Y-%m-%d"]`
`augend.date.alias["%Y年%-m月%-d日"]`
`augend.date.alias["%Y年%-m月%-d日(%ja)"]`
`augend.date.alias["%H:%M:%S"]`
`augend.date.alias["%H:%M"]`
constant:
`augend.constant.alias.ja_weekday`
`augend.constant.alias.ja_weekday_full`
`augend.constant.alias.bool`
`augend.constant.alias.alpha`
`augend.constant.alias.Alpha`
semver:
`augend.semver.alias.semver`
paren:
`augend.paren.alias.quote`
`augend.paren.alias.brackets`
`augend.paren.alias.lua_str_literal`
`augend.paren.alias.rust_str_literal`
misc:
`augend.misc.alias.markdown_header`
NOTE: aliases in `augend.date.alias` are deprecated. These will be removed in
future release.
------------------------------------------------------------------------------
AUGENDS *dial-augends*
For simplicity, we define the variable `augend` as follows.
>
local augend = require("dial.augend")
<
NUMBER *dial-augends-number*
------
Represents n-ary integer.
>
require("dial.config").augends:register_group{
default = {
-- uppercase hex number (0x1A1A, 0xEEFE, etc.)
augend.integer.new{
radix = 16,
prefix = "0x",
natural = true,
case = "upper",
},
},
}
<
The argument table of `augend.integer.new` can take the following keys:
radix (number, default: 10)
represents radix of the number, e.g., 10 in decimal system and
2 in binary system.
prefix (string, default: "")
can be used to specify a string to be prepended to a number,
e.g., `0x`.
natural (boolean, default: true)
toggles whether or not a number should be treated as a natural
number. If true, the augend matches only natural numbers. That
is, if the cursor is on `-1`, it does not match `-1` but `1`.
case ("upper" | "lower", default: "lower")
represents the case of the alphabet used for numbers with
radix larger than 10, such as hexadecimal numbers.
delimiter (char, default: "")
represents a numerical separator. For example, giving ",", the
augend will match the following numbers:
>
1,234,567
1,23,4,5,67
<
In every situation, the separator is simply ignored when
evaluating the number, but when incrementing/decrementing, the
position of the separator is formatted as an n-digit
separator. The value of n can be controlled by the value of
`delimiter_digits`, described below.
delimiter_digits (number, default: 3)
specifies how many digits to split a number when `delimiter`
is specified.
It is meaningless if `delimiter` is an empty string.
augend.integer.alias.decimal~
Increments/decrements a non-negative decimal number. It matches such as
>
0
123
3141592
<
and each increment increases that number by one. Unlike the standard CTRL-A
command, it does not consider any `-` at the beginning oc the number. If you
perform |<Plug>(dial-increment)| with the cursor at `1` of the following
string:
>
file-1.jpg
<
then you will get the following result.
>
file-2.jpg
<
augend.integer.alias.decimal_int~
Basically the same as augend.integer.alias.decimal, but this one also matches
negative integers. If you perform |<Plug>(dial-increment)| with the cursor at
`1` of the following string:
>
file-1.jpg
<
then you will get the following result.
>
file0.jpg
<
augend.integer.alias.hex~
Matches a hexadecimal non-negative integer and increments/decrements in
hexadecimal notation. It matches strings such as:
>
0x12
0xafbf
0xAFBF
<
augend.integer.alias.octal~
Matches a octal non-negative integer and increments/decrements in octal
notation. It matches strings such as:
>
0o37
0o567
0o01212
<
augend.integer.alias.binary~
Matches a binary non-negative integer and increments/decrements in binary
notation. It matches strings such as:
>
0b00
0b1010
0b10100101
<
DATE *dial-augends-date*
-----
Matches dates and times.
>
require("dial.config").augends:register_group{
default = {
augend.date.new{
pattern = "%Y/%m/%d",
default_kind = "day",
only_valid = true,
word = false,
},
},
}
<
The argument table of `augend.date.new` can take the following keys:
pattern (string, required)
date pattern to match. See |dial-augends-date-pattern| for
details.
default_kind (string, required)
represents in which unit the date to be incremented/decremented
when the cursor position is far from the date or in VISUAL mode.
Choose from the following values:
* `year`
* `month`
* `day`
* `hour`
* `min`
* `sec`
only_valid (boolean, default: false)
When true, it doesn't match non-existent dates or times, such as
`2022/13/52` and `27:30`. It is useful to avoid matching an
unintended range.
When false, it matches non-existent dates or times, and corrects
them to the existent ones. For example, when you increment the
date `2022/06/31` by one day, the original string is interpreted
as the date `2022/07/01` and the final date becomes `2022/07/02`.
word (boolean, default: false)
If true, the augend matches only if the string matching
elements is on a word boundary.
clamp (boolean, default: false)
See |dial-augends-date-clamp|.
end_sensitive (boolean, default: false)
See |dial-augends-date-end-sensitive|.
custom_date_elements (table<string, dateelement>, default: {})
Advanced option to define the custom date elements by user.
Refer to |dial-augends-date-custom-format| for detail.
*dial-augends-date-pattern*
The argument `pattern` can be a string like the following:
>
%Y/%m/%d (e.g. 2022/02/06)
%H:%M:%S (e.g. 15:30:00)
%-m/%-d (e.g. 2/6)
<
`%` is an escape character to represent a date elements and can be used by the
following pattern.
* `%` + a single alphabetical character.
`%Y` 4-digit year. (e.g. `2022`)
`%y` Last 2 digits of year.
The upper 2 digits are interpreted as `20`. (e.g. `22`)
`%m` 2-digit month. (e.g. `09`)
`%d` 2-digit day. (e.g. `28`)
`%H` 2-digit hour, expressed in 24 hours. (e.g. `15`)
`%I` 2-digit hour, expressed in 12 hours. (e.g. `03`)
`%M` 2-digit minute. (e.g. `05`)
`%S` 2-digit second. (e.g. `08`)
`%a` English weekdays (`Sun`, `Mon`, ..., `Sat`)
`%A` English full weekdays (`Sunday`, `Monday`, ..., `Saturday`)
`%b` English month names (`Jan`, ..., `Dec`)
`%B` English month full names (`January`, ..., `December`)
`%p` `AM` or `PM`.
`%J` Japanese weekdays (`日`, `月`, ..., `土`)
* `%-` + a single alphabetical character.
`%-y` 1- or 2-digit year. (e.g. `9` represents 2009)
`%-m` 1- or 2-digit month. (e.g. `9`)
`%-d` 1- or 2-digit day. (e.g. `28`)
`%-H` 1- or 2-digit hour, expressed in 24 hours. (e.g. `15`)
`%-I` 1- or 2-digit hour, expressed in 12 hours. (e.g. `3`)
`%-M` 1- or 2-digit minute. (e.g. `5`)
`%-S` 1- or 2-digit second. (e.g. `8`)
* `%%`. This is used to represent `%` itself.
* Text of the form `%(element_name)` (|dial-augends-date-custom-format|),
where `element_name` can be any string in which the `)` character does not
appear.
NOTE: patterns must contain information about date or time. For example, the
string that only contains `%a` cannot be a pattern, because the day of the
week alone is not enough to infer the date.
*dial-augends-date-custom-format*
In date patterns, `%(element_name)` is a special placeholder that can be
defined by the user. The placeholder can be given in the
`custom_date_elements` argument of `augend.date.new`.
For example, consider the following configuration:
>
local WEEKDAYS_FLUSHRIGHT = {
" Sunday",
" Monday",
" Tuesday",
"Wednesday",
" Thursday",
" Friday",
" Saturday",
}
require("dial.config").augends:register_group {
default = {
augend.date.new {
pattern = "%d/%m/%y %(week_flushright)",
default_kind = "day",
custom_date_elements = {
week_flushright = {
kind = nil,
regex = common.enum_to_regex(WEEKDAYS_FLUSHRIGHT),
update_date = function(_, date)
return date
end,
format = function(time)
local wday = os.date("*t", time).wday
return WEEKDAYS_FLUSHRIGHT[wday]
end,
}
}
}
},
}
<
This example defines a custom date element named `week_flushright` and uses
the element with `%(week_flushright)`. As the result, this rule matches the
following string:
>
18/10/22 Tuesday
<
and pressing <C-a> on the date increments it to the following string:
>
19/10/22 Wednesday
<
The following fileds are required in the custom_date_elements value:
kind (string | nil, default: nil)
which information is tied to the element on the date.
* `year`
* `month`
* `day`
* `hour`
* `min`
* `sec`
regex (string, required)
regular expression to search the element.
update_date (function, required)
How the date is updated by reading the element: the first argument
is a string matching the placeholder, and the second argument is
information about the date before the update (a table of the same
form as `os.date("*t")`).
format (function, required)
Given a date (and time), how the element should be converted to a
string. unix time is passed as an integer for the first argument.
Yes, it is really flexible! Flexible, but complicated. We recommend to use
existing elements such as `%a` and `%y`, if possible.
*dial-augends-date-clamp*
*dial-augends-date-end-sensitive*
When operating increment/decrement such as "1 month later" or "1 year later",
the date it represents may not be obvious. For example, given the date
`2022-01-31` in `yyyy-mm-dd` format, one might think that 1 month later of
`2022-01-31` is `2022-03-31` with 31 days added, or `2022-02-28`, tha last day
of the month following January. To accomodate various cases, augend.date has
two options `clamp` and `end_sensitive.`
For example, consider one month after `2022-01-31`. The straightforward answer
is `2022-02-31`, but such a date does not exist. When `clamp = false`, it is
automatically corrected to a date that exists by carrying forward to the next
month:
>
2022-01-31 --(+1 month)--> 2022-02-31 (that does not exist)
~~> 2022-03-03 (FINAL RESULT)
<
On the other hand, when `clamp = false`, it is automatically corrected by
truncating it preserving the month.
>
2022-01-31 --(+1 month)--> 2022-02-31 (that does not exist)
~~> 2022-02-28 (FINAL RESULT)
<
By using `end_sensitive` option, the last day of the month is treated
specially.
When `end_sensitive = true` and the date to operate is the last day of the
month, incrementing/decrementing the year or month will force the conversion
to the last day of the month, regardless of the `clamp` option.
>
2022-01-31 --(+1 month)--> 2022-02-28
<
`clamp` and `end_sensitive` are very similar, but work slightly differently.
Choose the best value that fits your use case, respectively.
* When `clamp = false, end_sensitive = false`
>
2022-01-30 --(+1 month)--> 2022-03-02
2022-01-31 --(+1 month)--> 2022-03-03
2022-02-28 --(+1 month)--> 2022-03-28
2022-03-31 --(-1 month)--> 2022-03-03
<
* When `clamp = true, end_sensitive = false`
>
2022-01-30 --(+1 month)--> 2022-02-28 # Clamped!
2022-01-31 --(+1 month)--> 2022-02-28 # Clamped!
2022-02-28 --(+1 month)--> 2022-03-28
2022-03-31 --(-1 month)--> 2022-02-28 # Clamped!
<
* When `clamp = false, end_sensitive = true`
>
2022-01-30 --(+1 month)--> 2022-03-02
2022-01-31 --(+1 month)--> 2022-02-28 # Last day of the month!
2022-02-28 --(+1 month)--> 2022-03-31 # Last day of the month!
2022-03-31 --(-1 month)--> 2022-02-28 # Last day of the month!
<
* When `clamp = true, end_sensitive = true`
>
2022-01-30 --(+1 month)--> 2022-02-28 # Clamped!
2022-01-31 --(+1 month)--> 2022-02-28 # Last day of the month!
2022-02-28 --(+1 month)--> 2022-03-31 # Last day of the month!
2022-03-31 --(-1 month)--> 2022-02-28 # Last day of the month!
<
*dial-augends-date-aliases*
There are some aliases in `augend.date`.
NOTE: the following aliases are remnants of a time when it was hard and
tedious to specify date formats. Now that you can freely specify the date
format, the aliases are losing their value. They are currently retained for
compatibility, but will be removed in the future.
augend.date.alias["%Y/%m/%d"]~
Matches dates with the following format (year/month/day):
>
1970/12/31
2021/01/01
2021/02/13
<
If the cursor is to the left of the format, the increment is always done in
date units, but if the cursor is on the format, the increment depends on the
specific position of the cursor.
Let's take `1970/12/31` as an example.
When the cursor is over any of the four `1970` characters, the year will be
incremented as shown below.
>
1971/12/31
<
When the cursor is over any of the three `/12` characters, the month will be
incremented as shown below.
>
1971/01/31
<
When the cursor is over any of the three `/31` characters, the day will be
incremented as shown below.
>
1971/01/01
<
The format matches dates that do not exist in reality such as:
>
2021/02/29
2021/14/59
<
The date is corrected to a date that actually exists when incrementing.
augend.date.alias["%m/%d/%Y"]~
Matches dates with the following format:
>
12/31/1970
01/01/2021
02/13/2021
<
To avoid matching an unintended range, it doesn't match non-existent dates.
augend.date.alias["%m/%d/%y"]~
Matches dates with the following format:
>
12/31/70
01/01/21
02/13/21
<
To avoid matching an unintended range, it doesn't match non-existent dates.
augend.date.alias["%d/%m/%y"]~
Matches dates with the following format:
>
31/12/19
01/01/20
13/02/20
<
To avoid matching an unintended range, it doesn't match non-existent dates.
augend.date.alias["%m/%d"]~
Matches dates with the following format:
>
12/31
01/01
02/13
<
`12/31` の例の場合、
* カーソルが `12` より左にある場合:日付
* カーソルが `12` のいずれかの上にある場合:月
* カーソルが `/31` のいずれかの上にある場合:日付
がインクリメントされます。
現実に存在しない日付でもマッチし、操作の際に現実に存在する日付へと強制的に修正
されます。
augend.date.alias["%-m/%-d"]~
Matches dates with the following format:
>
12/31
1/1
2/13
<
To avoid matching an unintended range, it doesn't match non-existent dates.
augend.date.alias["%Y-%m-%d"]~
Matches dates with the following format:
>
1970-12-31
2021-01-01
2021-02-13
<
It matches non-existent dates and corrects them to the existent ones.
augend.date.alias["%d.%m.%Y"]~
Matches dates with the following format:
>
31.12.1970
01.01.2021
13.02.2021
<
It matches non-existent dates and corrects them to the existent ones.
augend.date.alias["%d.%m.%y"]~
Matches dates with the following format:
>
31.12.70
01.01.21
13.02.21
<
It matches non-existent dates and corrects them to the existent ones.
augend.date.alias["%d.%m."]~
Matches dates with the following format:
>
31.12.
01.01.
13.02.
<
It matches non-existent dates and corrects them to the existent ones.
augend.date.alias["%-d.%-m."]~
Matches dates with the following format:
>
31.12.
1.1.
13.2.
<
It matches non-existent dates and corrects them to the existent ones.
augend.date.alias["%Y年%-m月%-d日"]~
Matches dates with the following format:
>
1970年12月31日
2021年1月1日
2021年2月13日
<
It matches non-existent dates and corrects them to the existent ones.
augend.date.alias["%Y年%-m月%-d日(%ja)"]~
Matches dates with the following format:
>
1970年12月31日(木)
2021年1月1日(金)
2021年2月13日(土)
<
It matches non-existent dates and corrects them to the existent ones.
augend.date.alias["%H:%M:%S"]~
Matches times with the following format:
>
00:00:00
12:34:56
<
If we take `12:34:56` as an example, the following rules will determine the
target of the increment.
* If the cursor is to the left of `12`: second
* If the cursor is over any of `12`: hour
* If the cursor is over any of `:34`: minute
* If the cursor is over any of `:56`: second
The format matches times that do not exist in reality such as `52:27:93`, and
the time is corrected to a date that actually exists when incrementing.
augend.date.alias["%H:%M"]~
Matches times with the following format:
>
00:00
12:34
<
If we take `12:34` as an example, the following rules will determine the
target of the increment.
* If the cursor is to the left of `12`: minute
* If the cursor is over any of `12`: hour
* If the cursor is over any of `:34`: minute
The format matches times that do not exist in reality such as `52:99`, and
the time is corrected to a date that actually exists when incrementing.
CONSTANT *dial-augends-constant*
--------
Predefined sequence of strings. You can use this rule with
`augend.constant.new{ ...opts }` .
>
require("dial.config").augends:register_group{
default = {
-- uppercase hex number (0x1A1A, 0xEEFE, etc.)
augend.constant.new{
elements = {"and", "or"},
word = true, -- if false, "sand" is incremented into "sor", "doctor" into "doctand", etc.
cyclic = true, -- "or" is incremented into "and".
},
augend.constant.new{
elements = {"&&", "||"},
word = false,
cyclic = true,
},
},
}
<
The argument table of `augend.constant.new` can take the following keys:
elements (string[], required)
An array of strings you want to cross-convert.
word (boolean, default: true)
If true, the augend matches only if the string matching
elements is on a word boundary.
cyclic (boolean, default: true)
If true, the augend circulates the patterns for
increment/decrement operations.
preserve_case (boolean, default: false)
If true, the augend attempts to preserve the pattern of
uppercase/lowercase letters for conversion.
pattern_regexp (string, default: `\C\V\<\(%s\)\>`)
A regular expression used in search. `%s` represents the string
specified in `elements.`
NOTE: Set `cyclic` to false when cross-converting strings consisting of
symbols, such as `&&` and `||`.
NOTE: When `preserve_case` is true, it matches the string specified for
elements, ignoring case. The case pattern is preserved only if the string
matches one of the following three patterns:
* All lowercase (e.g.: `true <-> false`)
* All uppercase (g.g.: `TRUE <-> FALSE`)
* Only the first letter is uppercase (e.g.: `True <-> False`)
Otherwise the string is converted to lowercase.
augend.constant.alias.ja_weekday~
Matches Japanese day names:
>
月
火
水
木
金
土
日
<
Each of these matches a |word| in the Vim sense, so some Japanese idioms such
as `日用品` will not match.
augend.constant.alias.ja_weekday_full~
Matches Japanese day names:
>
月曜日
火曜日
水曜日
木曜日
金曜日
土曜日
日曜日
<
Unlike |augend.constant.alias.ja_weekday|, this simply matches a string (not a
|word|), so even if you have a series of kanji characters, such as `毎週火曜日
`, it will match.
augend.constant.alias.de_weekday~
Matches German day names:
>
Mo
Di
Mi
Do
Fr
Sa
So
<
Each of these matches a |word| in the Vim sense.