forked from mawww/kakoune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
2010 lines (1489 loc) · 71.4 KB
/
notes.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
Notes
-----
Look up *prompt*, *info*, and *on-key* commands
A word is a sequence of alphanumeric characters or underscore, a WORD is a
sequence of non whitespace characters.
Shift usually extend selection of movement commands. wWW selects 3 consecutive
words: first `w` selects a word, then `WW` extends the selection two words
further. f/F/ selects up to and including the second `/` character forward.
See also 3W
---------------------------------------
map [switches] <scope> <mode> <key> <keys>
unmap <scope> <mode> <key> [<expected>]
---------------------------------------
The *map* command makes *key* behave as if the *keys* sequence was typed.
mode dictates in what context the mapping will be available.
Available modes:
insert : insert mode
normal : normal mode
prompt : prompts, such as when entering a command through *:*, or a regex through */*
user : mode entered when the user prefix is hit (default: '<space>')
goto : mode entered when the goto key is hit (default: 'g')
view : mode entered when the view key is hit (default: 'v')
object : mode entered when an object selection is triggered (e.g. '<a-i>')
The context of execution of the above modes is always the current one at the
time of execution of the mapping, except for *user* mode (always executed
in a 'normal' context). Refer to <<modes#,`:doc modes`>> for more details.
If you make a normal-mode mapping, you can prefix it with a count or a register
name like any other normal-mode key. You can forward this information to the
command you invoke with the `%val{count}` and `%val{register}` expansions
(See <<expansions#,`:doc expansions`>>). For example:
----
map global normal = ':echo Got count %val{count} and reg %val{register}<ret>'
----
NORMAL
h : select the character on the left of selection end
j : select the character below the selection end
k : select the character above the selection end
l : select the character on the right of selection end
w : select the word and following whitespaces on the right of selection end
<a-w> : same as w, but select WORD instead of word
b : select preceding whitespaces and the word on the left of selection end
<a-b> : same as b, but select WORD instead of word
e : select preceding whitespaces and the word on the right of selection end
<a-e> : same as e, but select WORD instead of word
f : select to (including) the next occurrence of the given character
<a-f> : same as f but in the other direction
t : select until (excluding) the next occurrence of the given character
<a-t> : same as t but in the other direction
m : select to matching character
M : extend selection to matching character
<a-m> : select to the previous sequence enclosed by matching characters, see the
`matching_pairs` option in <<options#,`:doc options`>>
<a-M> : extend the current selection to the previous sequence enclosed by matching
characters, see the `matching_pairs` option in <<options#,`:doc options`>>
x : expand selections to contain full lines (including end-of-lines)
<a-x> : trim selections to only contain full lines (not including last end-of-line)
% : select whole buffer
<a-h>, <home> : select to line begin
<a-l>, <end> : select to line end
/ : search (select next match)
<a-/> : search (select previous match)
? : search (extend to next match)
<a-?> : search (extend to previous match)
n : select next match
N : add a new selection with next match
<a-n> : select previous match
<a-N> : add a new selection with previous match
pageup, <c-b> : scroll one page up
pagedown, <c-f> : scroll one page down
<c-u> : scroll half a page up
<c-d> : scroll half a page down
) : rotate selections (the main selection becomes the next one)
( : rotate selections backwards
; : reduce selections to their cursor
<a-;> : flip the selections' direction
<a-:> : ensure selections are in forward direction (cursor after anchor)
<a-.> : repeat last object or `f`/`t` selection command.
_ : unselect whitespace surrounding each selection, drop those that only
contain whitespace
\ : Prefix any normal mode command with \ to disable hooks. \i disables hooks
for entire insertion session
CHANGES/SELECTION
i : enter insert mode before each selection
a : enter insert mode after each selection
d : yank and delete each selection
c : yank and delete each selection and enter insert mode
. : repeat last insert mode change (`i`, `a`, or `c`, including
the inserted text)
<a-d> : delete each selection
<a-c> : delete each selection and enter insert mode
I : enter insert mode at each selection begin line start
A : enter insert mode at each selection end line end
o : enter insert mode in one (or given count) new lines below
each selection end
O : enter insert mode in one (or given count) new lines above
each selection begin
<a-o> : add an empty line below each cursor
<a-O> : add an empty line above each cursor
y : yank selections
p : paste after each selection end
P : paste before each selection begin
<a-p> : paste all after each selection end
<a-P> : paste all before each selection begin
R : replace each selection with yanked text
<a-R> : replace each selection with every yanked text
r : replace each character with the next entered one
<a-j> : join selected lines
<a-J> : join selected lines and select spaces inserted
in place of line breaks
<a-_> : merge contiguous selections together (works across lines as well)
<plus> : duplicate each selection (generating overlapping selections)
<a-plus> : merge overlapping selections
<gt> (>) : indent selected lines
<a-gt>, <a-\> : indent selected lines, including empty lines
<lt> (<) : deindent selected lines
<a-lt> : deindent selected lines, do not remove incomplete
indent (3 leading spaces when indent is 4)
| : pipe each selection through the given external filter program
and replace the selection with its output.
<a-|> : pipe each selection through the given external filter program
and ignore its output
! : insert and select command output before each selection
<a-!> : append and select command output after each selection
u : undo last change
<c-k> : move backward in history
<a-u> : undo last selection change
U : redo last change
<c-j> : move forward in history
<a-U> : redo last selection change
& : align selections, align the cursor of selections by inserting
spaces before the first character of the selection
<a-&> : copy indent, copy the indentation of the main selection
(or the count one if a count is given) to all other ones
` : to lower case
~ : to upper case
<a-`> : swap case
@ : convert selected tabs to spaces, uses the buffer tabstop option or
the count parameter for tabstop.
<a-@> : convert selected spaces to tabs, uses the buffer tabstop option
or the count parameter for tabstop.
<a-)> : rotate selections content, if specified, the count groups
selections, so `3<a-)>` rotate (1, 2, 3) and (4, 5, 6)
independently.
<a-(> : rotate selections content backwards
Goto commands. Commands beginning with `g` are used to goto certain position
and or buffer. If a count is given prior to hitting `g`, `g` will jump to
the given line. Using `G` will extend the selection rather than jump.
View commands. Commands beginning with `v` permit to center or scroll the current
view. Using `V` will lock view mode until `<esc>` is hit
Marks. Current selections position can be saved in a register and restored later on.
These are "marks".
Jump list. Some commands, like the goto commands, buffer switch or search commands,
push the previous selections to the client's jump list.
INSERT
<esc> : leave insert mode
<backspace> : delete characters before cursors
<del> : delete characters under cursors
<left> : move cursors in given direction
<right> : move cursors in given direction
<up> : move cursors in given direction
<down> : move cursors in given direction
<home> : move cursors to line beginning
<end> : move cursors to line ending
<c-n> : select next completion candidate
<c-p> : select previous completion candidate
<c-x, f> : explicit insert completion query, followed by explicit file completion
<c-x, w> : explicit insert completion query, followed by explicit word completion
in the current buffer
<c-x, W> : explicit insert completion query, followed by explicit word completion
from all buffers
<c-x, l> : explicit insert completion query, followed by explicit line completion
from the curren buffer
<c-x, L> : explicit insert completion query, followed by explicit line completion
from the all buffers
<c-o> : disable automatic completion for this insert session
<c-r> : insert contents of the register given by next key
<c-v> : insert next keystroke directly into the buffer, without interpreting it
<c-u> : commit changes up to now as a single undo group
<a-;> : escape to normal mode for a single command; selections not modified,
other modes can be entered (nested into) and you're returned to the
original insert mode. Prefer this for scripting to <esc>
SEARCHING/SELECTION
Searches use the `/` register by default
/ : select next match after each selection
<a-/> : select previous match before each selection
? : extend to next match after each selection
<a-?> : extend to previous match before each selection
s : multi-select search pattern (pattern shared with `/`)
S : split selection on search pattern; try splitting on ,-sep lists
<a-s> : split selection on line boundaries
<a-S> : select first and last characters of each selection
n : select next match after main selection
N : add a new selection with next match after the main selection
<a-n> : select previous match before the main selection
<a-N> : add a new selection with previous match before the main selection
* : set search pattern to the main selection (detects word boundaries)
<a-*> : set search pattern to the main selection (verbatim)
C : duplicate selections on the lines that follow them
<a-C> : duplicate selections on the lines that precede them
, : clear selections to only keep the main one
<a-,> : clear the main selection
<a-k> : keep selections that match the given regex
<a-K> : clear selections that match the given regex
$ : pipe each selection to the given shell command and keep the ones
for which the shell returned 0. Shell expansions are available,
To clear multiple selections, use `,`. To keep only the nth selection
use `n` followed by `,`, in order to remove a selection, use `<a-,>`.
GOTO MODE
count, G : When a `count` is specified, *G* only extends the selection to the given line
count, g : sends the anchor to the given line
g, h : go to line begin
g, l : go to line end
g, i : go to non blank line start
g, g : go to the first line
G, g : extend selection to the first line
g, k : go to the first line
G, k : extend selection to the first line
g, j : go to the last line
G, j : extend selection to the last line
g, e : go to last char of last line
G, e : extend selection to last char of last line
g, t : go to the first displayed line
G, t : extend selection to the first displayed line
g, c : go to the middle displayed line
G, c : extend selection to the middle displayed line
g, b : go to the last displayed line
G, b : extend selection to the last displayed line
g, . : go to last buffer modification position
G, . : extend selection to last buffer modification position
g, a : go to the previous (alternate) buffer
g, f : open the file whose name is selected
VIEW MODE
V : enters lock view mode (which will be left when the <esc> is hit)
v : v modifies the current view; a menu is then displayed which waits
for one of the following additional keys:
v, v : center the main selection in the window (vertically)
v, c : center the main selection in the window (vertically)
v, m : center the main selection in the window (horizontally)
v, t : scroll to put the main selection on the top line of the window
v, b : scroll to put the main selection on the bottom line of the window
v, h : scroll the window `count` columns left
v, j : scroll the window `count` line downward
v, k : scroll the window `count` line upward
v, l : scroll the window `count` columns right
MARKS
Current selections position can be saved in a register and restored later on.
Marks use the `^` register by default.
Z : save selections to the register
z : restore selections from the register
<a-z> : combines selections from the register with the current ones, whereas
<a-Z> : combines current selections with the ones in the register; a menu
is then displayed which waits for one of the additional keys
<a-z>, a : append selections
<a-Z>, a : append selections
<a-z>, u : keep a union of selections
<a-Z>, u : keep a union of selections
<a-z>, i : keep an intersection of selections
<a-Z>, i : keep an intersection of selections
<a-z>, < : select the selection with the leftmost cursor for each pair
<a-Z>, < : select the selection with the leftmost cursor for each pair
<a-z>, > : select the selection with the rightmost cursor for each pair
<a-Z>, > : select the selection with the rightmost cursor for each pair
<a-z>, + : select the longest selection
<a-Z>, + : select the longest selection
<a-z>, - : select the shortest selection
<a-Z>, - : select the shortest selection
MACROS
Macros use the @ register by default
Q : start or end macro recording
q : play a recorded macro
<esc> : end macro recording
JUMP LIST
Some commands, like the goto commands, buffer switch or search commands,
push the previous selections to the client's jump list. It is possible
to skim through the jump list using:
<c-i> : jump forward
<c-o> : jump backward
<c-s> : create a jump step, but also save the current selection to have it be
restored when the step is subsequently cycled through
OBJECT SELECTION
For nestable objects, a `count` can be used in order to specify which surrounding
level to select. Object selections are repeatable using <a-.>
A 'whole object' is an object *including* its surrounding characters.
For example, for a quoted string this will select the quotes, and
for a word this will select trailing spaces.
<a-a> : select the whole object
[ ... : select to the whole object start
] ... : select to the whole object end
{ ... : extend selections to the whole object start
} ... : extend selections to the whole object end
An 'inner object' is an object *excluding* its surrounding characters.
For example, for a quoted string this will *not* select the quotes, and
for a word this will *not* select trailing spaces.
<a-i> ... : select the inner object
<a-[> ... : select to the inner object start
<a-]> ... : select to the inner object end
<a-{> ... : extend selections to the inner object start
<a-}> ... : extend selections to the inner object end
After the keys described above, a second key needs to be entered
in order to specify the wanted object (the ..., previously):
b ( ) : select the enclosing parenthesis
B { } : select the enclosing {} block
r [ ] : select the enclosing [] block
a < > : select the enclosing <> block
Q " : select the enclosing double quoted string
q ' : select the enclosing single quoted string
g ` : select the enclosing grave quoted string
w : select the whole word
<a-w> : select the whole WORD
s : select the sentence
p : select the paragraph
<space> : select the whitespaces
i : select the current indentation block
n : select the number
u : select the argument
c : select user defined object, will prompt for open and close text
<a-;> : run a command with additional expansions describing
the selection context (See `:doc expansions`)
If any other punctuation character is entered, it will act as
the delimiter. For instance, if the cursor is on the `o` of `/home/bar`,
typing `<a-a>/` will select `/home/`.
PROMPT COMMANDS
When pressing `:` in normal mode, Kakoune will open a prompt to enter
a command. The executed command line is stored in the *:* register
(See `:doc registers`).
During editing, a transient *clipboard* is available, its content is
empty at the start of prompt edition, and is not preserved afterwards.
The following keys are usable in prompt mode. Many are emacs/readline-esque.
<ret> : submit prompt
<esc> : abandon without submitting prompt
<left>, <c-b> : move cursor to previous character
<right>, <c-f> : move cursor to next character
<home>, <c-a> : move cursor to first character
<end>, <c-e> : move cursor past the last character
<backspace>, <c-h> : erase character before cursor
<del>, <c-d> : erase character under cursor
<a-f> : advance to next word begin
<a-F> : advance to next WORD begin
<a-b> : go back to previous word begin
<a-B> : go back to previous WORD begin
<a-e> : advance to next word end
<a-E> : advance to next WORD end
<c-w> : erase to previous word begin, save erased content to *clipboard*
<c-W> : erase to previous WORD begin, save erased content to *clipboard*
<a-d> : erase to next word begin, save erased content to *clipboard*
<a-D> : erase to next WORD begin, save erased content to *clipboard*
<c-k> : erase to end of line, save erased content to *clipboard*
<c-u> : erase to begin of line, save erased content to *clipboard*
<c-y> : insert *clipboard* content before cursor
<up>, <c-p> : select previous entry in history
<down>, <c-n> : select next entry in history
<tab> : select next completion candidate
<s-tab> : select previous completion candidate
<c-r> : insert then content of the register given by next key, if next key
has the Alt modifier, it will insert all values in the register
joined with spaces, else it will insert the main one
<c-v> : insert next keystroke without interpreting it
<c-x>, f : explicit filename completion
<c-x>, w : explicit word completion (from current buffer)
<c-o> : toggle automatic completion
<a-!> : expand the typed expansions in currently entered text
(See `:doc expansions`)
<a-;> : escape to normal mode for a single command (why would you want this
in prompt mode?)
USER MODE
<space> : enter user mode (See `:doc mode user-mode`)
CANCELING OPERATIONS
These cannot be remapped.
<c-c> : Stop any external processes; causes Kakoune to send the SIGINT signal
to its entire process group.
<c-g> : Cancel a long-running Kakoune operation, such as a regex search on a
very large file. Clears Kakoune's input buffer, so any commands that
were waiting on the operation are also cancelled.
USING THE DOCUMENTATION BROWSER
Documentation buffers are regular buffers. They can also
contain links: <<doc#demonstration-target,like this>>. If a link takes you to
a different documentation topic, return to the original with `:buffer`.
EXPANSIONS
While parsing a command, Kakoune supports expansions.
Every expansion consists of a `%`, followed by the expansion type, a quoting
character, and then all the text up to the next quoting character. It doesn't
matter which character is used, but `{}` are most common.
Expansions are processed when unquoted and anywhere inside double-quoted
strings, but not inside unquoted words, inside single-quoted strings, or
inside %-strings or other expansions. For example:
* `echo %val{session}` echoes the current session ID
* `echo x%val{session}x` echoes the literal text `x%val{session}x`
* `echo '%val{session}'` echoes the literal text `%val{session}`
* `echo "x%val{session}x"` echoes the current session ID, surrounded by `x`
* `echo %{%val{session}}` echoes the the literal text `%val{session}`
* `echo %sh{ echo %val{session} }` echoes the literal text `%val{session}`
See `:doc command-parsing typed-expansions` for details
== Argument expansions
Expansions with the type `arg` can only be used inside the "commands" parameter
of the `define-command` command (See <<commands#declaring-new-commands,`:doc
commands declaring-new-commands`>>).
The following expansions are available:
*%arg{n}*::
(where _n_ is a decimal number) +
expands to argument number _n_ of the current command
*%arg{@}*::
expands to all the arguments of the current command, as individual words
== Option expansions
Expansions with the type `opt` expand to the value associated with the named
option in the current scope (See <<options#,`:doc options`>>).
For example, `%opt{BOM}` expands to `utf8` or to `none`, according to the
current state of the `BOM` option.
== Register expansions
Expansions with the type `reg` expand to the contents of the named
register. For registers named after symbols (like the search register
`/`), the expansion can use either the symbol or the alphabetic name (See
<<registers#,`:doc registers`>>).
For example, `%reg{/}` expands to the content of the `/` register, and so does
`%reg{slash}`.
== Shell expansions
Expansions with the type `sh` are executed as shell-scripts, and whatever
the script prints to standard output replaces the expansion. For example,
the command `echo %sh{date}` will echo the output of the `date` command.
TIP: If a shell expansion writes to standard error, that output is appended to
Kakoune's `\*debug*` buffer. If you're trying to debug a shell expansion,
check the debug buffer with `:buffer \*debug*` to see if anything shows up.
Because Kakoune does not expand expansions inside the text of an expansion,
you can't use normal expansions inside `%sh{}`. Instead, Kakoune can export
expansions as environment variables to make them available to the shell.
Here's how expansion patterns map to variable names:
*%arg{n}*::
(where _n_ is a decimal number) +
becomes `$_n_`. For example, `%arg{3}` becomes `$3`.
*%arg{@}*::
becomes `$@`
*%opt{x}*::
becomes `$kak_opt_x`
*%reg{x}*::
(where _x_ is the alphabetic name of a register) +
`$kak_reg_x` contains all the selections in register _x_ +
`$kak_main_reg_x` contains only the main selection
*%val{x}*::
becomes `$kak_x`
Values can be quoted with a shell compatible quoting by using `$kak_quoted_`
as a prefix, this is mostly useful for list-type options and registers, as
it allows to correctly work with lists where elements might contains
whitespaces:
----
eval set -- "$kak_quoted_selections"
while [ $# -gt 0 ]; do
# ... do a thing with $1 ...
shift
done
----
The `eval` command will take the expanded `$kak_quoted_selections`
and unquote them, then execute the resulting `set` command, which sets
the shell's argument variables to the items from `$kak_selections`. The
`while` loop with `shift` iterates through the arguments one by one.
Only variables actually mentioned in the body of the shell expansion will
be exported into the shell's environment. For example:
----
echo %sh{ env | grep ^kak_ }
----
... will find none of Kakoune's special environment variables, but:
----
echo %sh{ env | grep ^kak_ # kak_session }
----
... will find the `$kak_session` variable because it was mentioned by name
in a comment, even though it wasn't directly used.
TIP: These environment variables are also available in other contexts where
Kakoune uses a shell command, such as the `|`, `!` or `$` normal mode commands
(See <<keys#,`:doc keys`>>).
=== Command and Response fifo
Inside shell expansions, `$kak_command_fifo` refers to a named pipe that
accepts Kakoune commands to be executed as soon as the fifo is closed. This
named pipe can be opened and closed multiple times which makes it possible
to interleave shell and Kakoune commands. `$kak_response_fifo` refers to
a named pipe that can be used to return data from Kakoune.
----
%sh{
echo "write $kak_response_fifo" > $kak_command_fifo
content="$(cat $kak_response_fifo)"
}
----
This also makes it possible to pass data bigger than the system environment
size limit.
== File expansions
Expansions with the type `file` will expand to the content of the filename
given in argument as read from the host filesystem.
For example, this command stores the entire content of `/etc/passwd` into the
`a` register.
----
set-register a %file{/etc/passwd}
----
== Value expansions
Expansions with the type `val` give access to Kakoune internal data that is
not stored in an option or a register. Some value expansions can only be used
in certain contexts, like `%val{hook_param}` that expands to the parameter
string of the currently-executing hook, and is not available outside a hook.
The following expansions are supported (with required context _in italics_):
*%val{buffile}*::
_in buffer, window scope_ +
full path of the file or same as `%val{bufname}` when there’s no
associated file
*%val{buf_line_count}*::
_in buffer, window scope_ +
number of lines in the current buffer
*%val{buflist}*::
quoted list of the names of currently-open buffers (as seen in
`%val{bufname}`)
*%val{bufname}*::
_in buffer, window scope_ +
name of the current buffer
*%val{client_env_X}*::
_in window scope_ +
value of the `$X` environment variable in the client displaying the current
window (e.g. `%val{client_env_SHELL}` is `$SHELL` in the client's
environment)
*%val{client_list}*::
unquoted list of the names of clients (as seen in `%val{client}`)
connected to the current session
*%val{client}*::
_in window scope_ +
name of the client displaying the current window
*%val{client_pid}*::
_in window scope_ +
process id of the client displaying the current window
*%val{config}*::
directory containing the user configuration
*%val{count}*::
_in `map` command <keys> parameter and `<a-;>` from object menu_ +
current count when the mapping was triggered, defaults to 0 if no
count given
*%val{cursor_byte_offset}*::
_in window scope_ +
offset of the main cursor from the beginning of the buffer (in bytes)
*%val{cursor_char_column}*::
_in window scope_ +
1-based offset from the start of the line to the cursor position in
Unicode codepoints, which may differ from visible columns if the document
contains full-width codepoints (which occupy two columns) or zero-width
codepoints
*%val{cursor_display_column}*::
_in window scope_ +
1-based offset from the start of the line to the cursor position in
display column, taking into account tabs and character width.
*%val{cursor_char_value}*::
_in window scope_ +
unicode value of the codepoint under the main cursor
*%val{cursor_column}*::
_in window scope_ +
1-based offset from the start of the line to the first byte of the
character under the main cursor (in bytes), the fourth component of
`%val{selection_desc}`
*%val{cursor_line}*::
_in window scope_ +
line of the main cursor, the third component of `%val{selection_desc}`
*%val{error}*::
_in `try` command's <on_error_commands> parameter_ +
the text of the error that cancelled execution of the <commands> parameter
(or the previous <on_error_commands> parameter)
*%val{history}*::
_in buffer, window scope_ +
the full change history of the buffer, including undo forks, in terms
of `parent committed redo_child modification0 modification1 ...`
entries, where _parent_ is the index of the entry's predecessor (entry
0, which is the root of the history tree, will always have `-` here),
_committed_ is a count in seconds from Kakoune's steady clock's epoch
of the creation of the history entry, _redo_child_ is the index of the
child which will be visited for `U` (always `-` at the leaves of the
history), and each _modification_ is presented as in
`%val{uncommitted_modifications}`.
*%val{history_id}*::
_in buffer, window scope_ +
history id of the current buffer, an integer value which refers to a
specific buffer version in the undo tree (see also `%val{timestamp}`)
*%val{hook_param_capture_n}*::
_in `hook` command <command> parameter_ +
text captured by capture group _n_, if the executing hook's filter regex
used capture groups
*%val{hook_param}*::
_in `hook` command <command> parameter_ +
the complete parameter string of the executing hook
*%val{modified}*::
_in buffer, window scope_ +
`true` if the buffer has modifications not saved, otherwise `false`
*%val{object_flags}*::
_for commands executed from the object menu's `<a-;>` only_ +
a pipe-separted list of words including `inner` if the user wants
an inner selection, `to_begin` if the user wants to select to the
beginning, and `to_end` if the user wants to select to the end
*%val{register}*::
_in `map` command <keys> parameter and `<a-;>` from the object menu_ +
current register when the mapping was triggered
*%val{runtime}*::
the directory containing the kak support files, which is determined from
Kakoune's binary location if `$KAKOUNE_RUNTIME` is not set
*%val{select_mode}*::
_for commands executed from the object menu's `<a-;>` only_ +
`replace` if the new selection should replace the existing, `extend`
otherwise
*%val{selection}*::
_in window scope_ +
content of the main selection
*%val{selections}*::
_in window scope_ +
quoted list of the contents of all selections
*%val{selection_desc}*::
_in window scope_ +
range of the main selection, represented as `a.b,c.d` where _a_ is the
anchor line, _b_ is the number of bytes from the start of the line to the
anchor, _c_ is the cursor line (like `%val{cursor_line}`), _d_ is
the number of bytes from the start of the line to the cursor (like
`%val{cursor_column}`), and all are 1-based decimal integers
*%val{selections_char_desc}*::
_in window scope_ +
unquoted list of the ranges of all selections, in the same format as
`%val{selection_desc}`, except that the columns are in codepoints rather
than bytes
*%val{selections_display_column_desc}*::
_in window scope_ +
unquoted list of the ranges of all selections, in the same format as
`%val{selection_desc}`, except that the columns are in display columns rather
than bytes
*%val{selections_desc}*::
_in window scope_ +
unquoted list of the ranges of all selections, in the same format as
`%val{selection_desc}`
*%val{selection_length}*::
_in window scope_ +
length (in codepoints) of the main selection
*%val{selections_length}*::
_in window scope_ +
unquoted list of the lengths (in codepoints) of the selections
*%val{selection_count}*::
_in window scope_ +
the number of selections
*%val{session}*::
name of the current session
*%val{source}*::
_in `.kak` file_ +
path of the file currently getting executed (through the source command)
*%val{text}*::
_in `prompt` command <command> parameter_ +
the text entered by the user in response to the `prompt` command
*%val{timestamp}*::
_in buffer, window scope_ +
timestamp of the current buffer, an integer that increments each time the
buffer is modified, including undoing and redoing previous modifications
(see also `%val{history_id}`)
*%val{uncommitted_modifications}*::
_in buffer, window scope_ +
a list of quoted insertions (in the format `+line.column|text`) and
deletions (`-line.column|text`) not yet saved to the history (e.g. typing
in insert mode before pressing `<esc>`), where _line_ is the 1-based line
of the change, _column_ is the 1-based _byte_ of the change start (see
`%val{cursor_column}`), and _text_ is the content of the insertion or
deletion (see also `%val{history}`)
*%val{user_modes}*::
unquoted list of user modes.
*%val{version}*::
version of the current Kakoune server (git hash or release name)
*%val{window_height}*::
_in window scope_ +
height of the current Kakoune window
*%val{window_width}*::
_in window scope_ +
width of the current Kakoune window
*%val{window_range}*::
_in window scope_ +
list of coordinates and dimensions of the buffer-space
available on the current window, in the following format:
`<coord_y> <coord_x> <height> <width>`
Values in the above list that do not mention a context are available
everywhere.
A value described as a "quoted list" will follow the rules of Kakoune string
quoting (See <<command-parsing#,`:doc command-parsing`>>). An "unquoted list"
cannot contain any special characters that would require quoting.
== Recursive Expansions
Expansions with the type `exp` expand their content, the same way doubly
quoted strings do.
= Options
== Description
Kakoune can store named and typed values that can be used both to
customize the core editor behaviour, and to store data used by extension
scripts.
[[set-option]]
Options can be modified using the `set-option` command:
--------------------------------------------
set-option [-add|-remove] <scope> <name> <values>...
--------------------------------------------
<scope> can be *global*, *buffer*, *window* or *current* (See
<<scopes#,`:doc scopes`>>). *current* relates to the narrowest scope in
which the option is already set.
When the option is a list or a map, multiple <values> can be given as
separate arguments, or can be omitted altogether in order to empty the
option.
If `-add` or `-remove` is specified, the new value is respectively *added*
to or *removed* from the current one instead of replacing it (the exact
outcome depends on the type, see below).
[[unset-option]]
Option values can be unset in a specific scope with the `unset-option`
command:
---------------------------
unset-option <scope> <name>
---------------------------
Unsetting an option will make it fallback to the value of its parent scope,
hence options cannot be unset from the *global* scope.
[[declare-option]]
New options can be declared using the `declare-option` command:
---------------------------------------------------
declare-option [-hidden] <type> <name> [<value>...]
---------------------------------------------------
If `-hidden` is specified, the option will not be displayed in completion
suggestions.
[[update-option]]
Certain option type can be *updated*, usually to match potential changes
in the buffer they relate to. This can be triggered by the `update-option`
command:
----------------------------
update-option <scope> <name>
----------------------------
== Types
All options have a type, which defines how they are translated to/from
text and their set of valid values.
Some types are usable for user defined options while some other types
are exclusively available to built-in options.
*int*::
an integer number.
`set -add` performs a math addition. +
`set -remove` performs a math substraction. +
*bool*::
a boolean value, yes/true or no/false
*str*::
a string, some freeform text
*regex*::
as a string but the set commands will complain if the entered text
is not a valid regex
*coord*::
a line, column pair (separated by a comma)
Cannot be used with `declare-option`
*<type>-list*::
a list, elements are specified as separate arguments to the command.
`set -add` appends the new element to the list. +
`set -remove` removes each given element from the list. +
Only `int-list` and `str-list` options can be created with
`declare-option`.
*range-specs*::
a timestamp (like `%val{timestamp}`,
see <<expansions#value-expansions,`:doc expansions value-expansions`>>)
followed by a list of range descriptors.
Each range descriptor must use the syntax `a.b,c.d|string` or
`a.b+length|string`, with:
* _a_ is the line containing the first character
* _b_ is the number of bytes from the start of the line to the