-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathmini.txt
4639 lines (3810 loc) · 201 KB
/
mini.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
==============================================================================
------------------------------------------------------------------------------
*mini.nvim*
*mini.txt* Collection of minimal, independent and fast Lua modules
Author: Evgeni Chasnovski
License: MIT
|mini.nvim| is a collection of minimal, independent, and fast Lua modules
dedicated to improve Neovim (version 0.5 and higher) experience. Each
module can be considered as a separate sub-plugin.
Table of contents:
General overview.................................................|mini.nvim|
Plugin colorscheme..............................................|minischeme|
Base16 colorscheme creation....................................|mini.base16|
Remove buffers..............................................|mini.bufremove|
Comment.......................................................|mini.comment|
Completion and signature help..............................|mini.completion|
Highlight word under cursor................................|mini.cursorword|
Generate help files...............................................|mini.doc|
Fuzzy matching..................................................|mini.fuzzy|
Visualize and operate on indent scope.....................|mini.indentscope|
Jump cursor to a single character................................|mini.jump|
Jump within visible lines......................................|mini.jump2d|
Miscellaneous functions..........................................|mini.misc|
Autopairs.......................................................|mini.pairs|
Session management...........................................|mini.sessions|
Start screen..................................................|mini.starter|
Statusline.................................................|mini.statusline|
Surround.....................................................|mini.surround|
Tabline.......................................................|mini.tabline|
Trailspace (highlight and remove)..........................|mini.trailspace|
# General principles~
- <Design>. Each module is designed to solve a particular problem targeting
balance between feature-richness (handling as many edge-cases as
possible) and simplicity of implementation/support. Granted, not all of
them ended up with the same balance, but it is the goal nevertheless.
- <Independence>. Modules are independent of each other and can be run
without external dependencies. Although some of them may need
dependencies for full experience.
- <Structure>. Each module is a submodule for a placeholder "mini" module. So,
for example, "surround" module should be referred to as "mini.surround".
As later will be explained, this plugin can also be referred to
as "MiniSurround".
- <Setup>:
- Each module (if needed) should be setup separately with
`require(<name of module>).setup({})`
(possibly replace {} with your config table or omit to use defaults).
You can supply only values which differ from defaults, which will be
used for the rest ones.
- Call to module's `setup()` always creates a global Lua object with
coherent camel-case name: `require('mini.surround').setup()` creates
`_G.MiniSurround`. This allows for a simpler usage of plugin
functionality: instead of `require('mini.surround')` use
`MiniSurround` (or manually `:lua MiniSurround.*` in command line);
available from `v:lua` like `v:lua.MiniSurround`. Considering this,
"module" and "Lua object" names can be used interchangeably:
'mini.surround' and 'MiniSurround' will mean the same thing.
- Each supplied `config` table (after extending with default values) is
stored in `config` field of global object. Like `MiniSurround.config`.
- Values of `config`, which affect runtime activity, can be changed on
the fly to have effect. For example, `MiniSurround.config.n_lines`
can be changed during runtime; but changing
`MiniSurround.config.mappings` won't have any effect (as mappings are
created once during `setup()`).
- <Disabling>. Each module's core functionality can be disabled globally or
buffer-locally by creating appropriate global or buffer-scoped variables
equal to |v:true|. See |mini.nvim-disabling-recipes| for common recipes.
- <Highlight groups>. Appearance of module's output is controlled by
certain highlight group (see |highlight-groups|). To customize them, use
|highlight| command. Note: currently not many Neovim themes support this
plugin's highlight groups; fixing this situation is highly appreciated.
To see a more calibrated look, use |MiniBase16| or plugin's colorscheme
`minischeme`.
- <Stability>. Each module upon release is considered to be relatively
stable: both in terms of setup and functionality. Any
non-bugfix backward-incompatible change will be released gradually as
much as possible.
# List of modules~
- |MiniBase16| - fast implementation of base16 theme for manually supplied
palette. Has unique palette generator which needs only background and
foreground colors.
- |MiniBufremove| - buffer removing (unshow, delete, wipeout) while saving
window layout.
- |MiniComment| - fast and familiar per-line code commenting.
- |MiniCompletion| - async (with customizable 'debounce' delay) 'two-stage
chain completion': first builtin LSP, then configurable fallback. Also
has functionality for completion item info and function signature (both
in floating window appearing after customizable delay).
- |MiniCursorword| - automatic highlighting of word under cursor (displayed
after customizable delay). Current word under cursor can be highlighted
differently.
- |MiniDoc| - generation of help files from EmmyLua-like annotations.
Allows flexible customization of output via hook functions. Used for
documenting this plugin.
- |MiniFuzzy| - functions for fast and simple fuzzy matching. It has
not only functions to perform fuzzy matching of one string to others, but
also a sorter for |telescope.nvim|.
- |MiniIndentscope| - Visualize and operate on indent scope. Supports
customization of debounce delay, animation style, and different
granularity of options for scope computing algorithm.
- |MiniJump| - minimal and fast module for smarter jumping to a single
character.
- |MiniJump2d| - minimal and fast Lua plugin for jumping (moving cursor)
within visible lines via iterative label filtering. Supports custom jump
targets (spots), labels, hooks, allowed windows and lines, and more.
- |MiniMisc| - collection of miscellaneous useful functions. Like `put()`
and `put_text()` which print Lua objects to command line and current
buffer respectively.
- |MiniPairs| - autopairs plugin which has minimal defaults and
functionality to do per-key expression mappings.
- |MiniSessions| - session management (read, write, delete) which works
using |mksession|. Implements both global (from configured directory) and
local (from current directory) sessions.
- |MiniStarter| - minimal, fast, and flexible start screen. Displayed items
are fully customizable both in terms of what they do and how they look
(with reasonable defaults). Item selection can be done using prefix query
with instant visual feedback.
- |MiniStatusline| - minimal and fast statusline. Has ability to use custom
content supplied with concise function (using module's provided section
functions) along with builtin default. For full experience needs [Nerd
font](https://www.nerdfonts.com/),
[gitsigns.nvim](https://github.com/lewis6991/gitsigns.nvim) plugin, and
[nvim-web-devicons](https://github.com/kyazdani42/nvim-web-devicons)
plugin (but works without any them).
- |MiniSurround| - fast surround plugin. Add, delete, replace, find,
highlight surrounding (like pair of parenthesis, quotes, etc.). Has
special "function call", "tag", and "interactive" surroundings. Supports
dot-repeatability, textobject, motions.
- |MiniTabline| - minimal tabline which always shows listed (see 'buflisted')
buffers. Allows showing extra information section in case of multiple vim
tabpages. For full experience needs
[nvim-web-devicons](https://github.com/kyazdani42/nvim-web-devicons).
- |MiniTrailspace| - automatic highlighting of trailing whitespace with
functionality to remove it.
------------------------------------------------------------------------------
*mini.nvim-disabling-recipes*
Common recipes for disabling functionality
Each module's core functionality can be disabled globally or buffer-locally
by creating appropriate global or buffer-scoped variables equal to
|v:true|. Functionality is disabled if at least one of `g:` or `b:`
variables is equal to `v:true`.
Variable names have the same structure: `{g,b}:mini*_disable` where `*` is
module's lowercase name. For example, `g:minicursorword_disable` disables
|mini.cursorword| globally and `b:minicursorword_disable` - for
corresponding buffer. Note: in this section disabling 'mini.cursorword' is
used as example; everything holds for other module variables.
Considering high number of different scenarios and customization intentions,
writing exact rules for disabling module's functionality is left to user.
# Manual disabling~
- Disable globally:
Lua - `:lua vim.g.minicursorword_disable=true`
Vimscript - `:let g:minicursorword_disable=v:true`
- Disable for current buffer:
Lua - `:lua vim.b.minicursorword_disable=true`
Vimscript - `:let b:minicursorword_disable=v:true`
- Toggle (disable if enabled, enable if disabled):
Globally - `:lua vim.g.minicursorword_disable = not vim.g.minicursorword_disable`
For buffer - `:lua vim.b.minicursorword_disable = not vim.b.minicursorword_disable`
# Automated disabling~
- Disable for a certain |filetype| (for example, "markdown"):
`autocmd Filetype markdown lua vim.b.minicursorword_disable = true`
- Enable only for certain filetypes (for example, "lua" and "python"):
`au FileType * if index(['lua', 'python'], &ft) < 0 | let b:minicursorword_disable=v:true | endif`
- Disable in Insert mode (use similar pattern for Terminal mode or indeed
any other mode change with |ModeChanged| starting from Neovim 0.7.0):
`au InsertEnter * lua vim.b.minicursorword_disable = true`
`au InsertLeave * lua vim.b.minicursorword_disable = false`
- Disable in Terminal buffer:
`au TermOpen * lua vim.b.minicursorword_disable = true`
------------------------------------------------------------------------------
*minischeme*
# Plugin colorscheme~
This plugin comes with an official colorscheme named `minischeme`. This is
a |MiniBase16| theme created with faster version of the following Lua code: >
require('mini.base16').setup({
palette = palette, name = 'minischeme', use_cterm = true
})
where `palette` is:
- For dark 'background':
`require('mini.base16').mini_palette('#112641', '#e2e98f', 75)`
- For light 'background':
`require('mini.base16').mini_palette('#e2e5ca', '#002a83', 75)`
Activate it as a regular |colorscheme|.
==============================================================================
------------------------------------------------------------------------------
*mini.base16*
*MiniBase16*
Minimal and fast Lua module which implements
[base16](http://chriskempson.com/projects/base16/) color scheme (with
Copyright (C) 2012 Chris Kempson) adapated for modern Neovim 0.5 Lua
plugins. Extra features:
- Configurable automatic support of cterm colors (see |highlight-cterm|).
- Opinionated palette generator based only on background and foreground
colors.
# Setup~
This module needs a setup with `require('mini.base16').setup({})` (replace
`{}` with your `config` table). It will create global Lua table
`MiniBase16` which you can use for scripting or manually (with
`:lua MiniBase16.*`).
See |MiniBase16.config| for `config` structure and default values.
Example:
>
require('mini.base16').setup({
palette = {
base00 = '#112641',
base01 = '#3a475e',
base02 = '#606b81',
base03 = '#8691a7',
base04 = '#d5dc81',
base05 = '#e2e98f',
base06 = '#eff69c',
base07 = '#fcffaa',
base08 = '#ffcfa0',
base09 = '#cc7e46',
base0A = '#46a436',
base0B = '#9ff895',
base0C = '#ca6ecf',
base0D = '#42f7ff',
base0E = '#ffc4ff',
base0F = '#00a5c5',
},
use_cterm = true,
})
<
# Notes~
1. This module is used to create plugin's colorscheme (see |minischeme|).
2. Using `setup()` doesn't actually create a |colorscheme|. It basically
creates a coordinated set of |highlight|s. To create your own theme:
- Put "myscheme.lua" file (name after your chosen theme name) inside
any "colors" directory reachable from 'runtimepath' ("colors" inside
your Neovim config directory is usually enough).
- Inside "myscheme.lua" call `require('mini.base16').setup()` with your
palette and only after that set |g:colors_name| to "myscheme".
------------------------------------------------------------------------------
*MiniBase16.setup()*
`MiniBase16.setup`({config})
Module setup
Setup is done by applying base16 palette to enable colorscheme. Highlight
groups make an extended set from original
[base16-vim](https://github.com/chriskempson/base16-vim/) plugin. It is a
good idea to have `config.palette` respect the original [styling
principles](https://github.com/chriskempson/base16/blob/master/styling.md).
By default only 'gui highlighting' (see |highlight-gui| and
|termguicolors|) is supported. To support 'cterm highlighting' (see
|highlight-cterm|) supply `config.use_cterm` argument in one of the formats:
- `true` to auto-generate from `palette` (as closest colors).
- Table with similar structure to `palette` but having terminal colors
(integers from 0 to 255) instead of hex strings.
Parameters~
{config} `(table)` Module config table. See |MiniBase16.config|.
Usage~
`require('mini.base16').setup({})` (replace `{}` with your `config`
table; `config.palette` should be a table with colors)
------------------------------------------------------------------------------
*MiniBase16.config*
`MiniBase16.config`
Module config
Default values:
>
MiniBase16.config = {
-- Table with names from `base00` to `base0F` and values being strings of
-- HEX colors with format "#RRGGBB". NOTE: this should be explicitly
-- supplied in `setup()`.
palette = nil,
-- Whether to support cterm colors. Can be boolean, `nil` (same as
-- `false`), or table with cterm colors. See `setup()` documentation for
-- more information.
use_cterm = nil,
}
<
------------------------------------------------------------------------------
*MiniBase16.mini_palette()*
`MiniBase16.mini_palette`({background}, {foreground}, {accent_chroma})
Create 'mini' palette
Create base16 palette based on the HEX (string '#RRGGBB') colors of main
background and foreground with optional setting of accent chroma (see
details).
# Algorithm design~
- Main operating color space is
[CIELCh(uv)](https://en.wikipedia.org/wiki/CIELUV#Cylindrical_representation_(CIELCh))
which is a cylindrical representation of a perceptually uniform CIELUV
color space. It defines color by three values: lightness L (values from 0
to 100), chroma (positive values), and hue (circular values from 0 to 360
degress). Useful converting tool: https://www.easyrgb.com/en/convert.php
- There are four important lightness values: background, foreground, focus
(around the middle of background and foreground, leaning towards
foreground), and edge (extreme lightness closest to foreground).
- First four colors have the same chroma and hue as `background` but
lightness progresses from background towards focus.
- Second four colors have the same chroma and hue as `foreground` but
lightness progresses from foreground towards edge in such a way that
'base05' color is main foreground color.
- The rest eight colors are accent colors which are created in pairs
- Each pair has same hue from set of hues 'most different' to
background and foreground hues (if respective chorma is positive).
- All colors have the same chroma equal to `accent_chroma` (if not
provided, chroma of foreground is used, as they will appear next
to each other). Note: this means that in case of low foreground
chroma, it is a good idea to set `accent_chroma` manually.
Values from 30 (low chorma) to 80 (high chroma) are common.
- Within pair there is base lightness (equal to foreground
lightness) and alternative (equal to focus lightness). Base
lightness goes to colors which will be used more frequently in
code: base08 (variables), base0B (strings), base0D (functions),
base0E (keywords).
How exactly accent colors are mapped to base16 palette is a result of
trial and error. One rule of thumb was: colors within one hue pair should
be more often seen next to each other. This is because it is easier to
distinguish them and seems to be more visually appealing. That is why
`base0D` and `base0F` have same hues because they usually represent
functions and delimiter (brackets included).
Parameters~
{background} `(string)` Background HEX color (formatted as `#RRGGBB`).
{foreground} `(string)` Foreground HEX color (formatted as `#RRGGBB`).
{accent_chroma} `(number)` Optional positive number (usually between 0
and 100). Default: chroma of foreground color.
Return~
`(table)` Table with base16 palette.
Usage~
`local palette = require('mini.base16').mini_palette('#112641', '#e2e98f', 75)`
`require('mini.base16').setup({palette = palette})`
------------------------------------------------------------------------------
*MiniBase16.rgb_palette_to_cterm_palette()*
`MiniBase16.rgb_palette_to_cterm_palette`({palette})
Converts palette with RGB colors to terminal colors
Useful for caching `use_cterm` variable to increase speed.
Parameters~
{palette} `(table)` Table with base16 palette (same as in
`MiniBase16.config.palette`).
Return~
`(table)` Table with base16 palette using |highlight-cterm|.
==============================================================================
------------------------------------------------------------------------------
*mini.bufremove*
*MiniBufremove*
Lua module for minimal buffer removing (unshow, delete, wipeout), which
saves window layout (opposite to builtin Neovim's commands). This is mostly
a Lua implementation of
[bclose.vim](https://vim.fandom.com/wiki/Deleting_a_buffer_without_closing_the_window).
Other alternatives:
- [vim-bbye](https://github.com/moll/vim-bbye)
- [vim-sayonara](https://github.com/mhinz/vim-sayonara)
# Setup~
This module doesn't need setup, but it can be done to improve usability.
Setup with `require('mini.bufremove').setup({})` (replace `{}` with your
`config` table). It will create global Lua table `MiniBufremove` which you
can use for scripting or manually (with `:lua MiniBufremove.*`).
See |MiniBufremove.config| for `config` structure and default values.
# Notes~
1. Which buffer to show in window(s) after its current buffer is removed is
decided by the algorithm:
- If alternate buffer (see |CTRL-^|) is listed (see |buflisted()|), use it.
- If previous listed buffer (see |bprevious|) is different, use it.
- Otherwise create a scratch one with `nvim_create_buf(true, true)` and use
it.
# Disabling~
To disable core functionality, set `g:minibufremove_disable` (globally) or
`b:minibufremove_disable` (for a buffer) to `v:true`. Considering high
number of different scenarios and customization intentions, writing exact
rules for disabling module's functionality is left to user. See
|mini.nvim-disabling-recipes| for common recipes.
------------------------------------------------------------------------------
*MiniBufremove.setup()*
`MiniBufremove.setup`({config})
Module setup
Parameters~
{config} `(table)` Module config table. See |MiniBufremove.config|.
Usage~
`require('mini.bufremove').setup({})` (replace `{}` with your `config` table)
------------------------------------------------------------------------------
*MiniBufremove.config*
`MiniBufremove.config`
Module config
Default values:
>
MiniBufremove.config = {
-- Whether to set Vim's settings for buffers (allow hidden buffers)
set_vim_settings = true,
}
<
------------------------------------------------------------------------------
*MiniBufremove.delete()*
`MiniBufremove.delete`({buf_id}, {force})
Delete buffer `buf_id` with |:bdelete| after unshowing it
Parameters~
{buf_id} `(number)` Buffer identifier (see |bufnr()|) to use. Default:
0 for current.
{force} `(boolean)` Whether to ignore unsaved changes (using `!` version of
command). Default: `false`.
Return~
`(boolean)` Whether operation was successful.
------------------------------------------------------------------------------
*MiniBufremove.wipeout()*
`MiniBufremove.wipeout`({buf_id}, {force})
Wipeout buffer `buf_id` with |:bwipeout| after unshowing it
Parameters~
{buf_id} `(number)` Buffer identifier (see |bufnr()|) to use. Default:
0 for current.
{force} `(boolean)` Whether to ignore unsaved changes (using `!` version of
command). Default: `false`.
Return~
`(boolean)` Whether operation was successful.
------------------------------------------------------------------------------
*MiniBufremove.unshow()*
`MiniBufremove.unshow`({buf_id})
Stop showing buffer `buf_id` in all windows
Parameters~
{buf_id} `(number)` Buffer identifier (see |bufnr()|) to use. Default:
0 for current.
Return~
`(boolean)` Whether operation was successful.
------------------------------------------------------------------------------
*MiniBufremove.unshow_in_window()*
`MiniBufremove.unshow_in_window`({win_id})
Stop showing current buffer of window `win_id`
Parameters~
{win_id} `(number)` Window identifier (see |win_getid()|) to use.
Default: 0 for current.
Return~
`(boolean)` Whether operation was successful.
==============================================================================
------------------------------------------------------------------------------
*mini.comment*
*MiniComment*
Minimal and fast Lua module for code commenting. This is basically a
reimplementation of "tpope/vim-commentary". Commenting in Normal mode
respects |count| and is dot-repeatable. Comment structure is inferred
from 'commentstring'. Handles both tab and space indenting (but not when
they are mixed). Allows custom hooks before and after successful commeting.
What it doesn't do:
- Block and sub-line comments. This will only support per-line commenting.
- Configurable (from module) comment structure. Modify |commentstring|
instead. To enhance support for commenting in multi-language files, see
"JoosepAlviste/nvim-ts-context-commentstring" plugin along with `hooks`
option of this module (see |MiniComment.config|).
- Handle indentation with mixed tab and space.
- Preserve trailing whitespace in empty lines.
# Setup~
This module needs a setup with `require('mini.comment').setup({})` (replace
`{}` with your `config` table). It will create global Lua table
`MiniComment` which you can use for scripting or manually (with
`:lua MiniComment.*`).
See |MiniComment.config| for `config` structure and default values.
# Disabling~
To disable core functionality, set `g:minicomment_disable` (globally) or
`b:minicomment_disable` (for a buffer) to `v:true`. Considering high number
of different scenarios and customization intentions, writing exact rules
for disabling module's functionality is left to user. See
|mini.nvim-disabling-recipes| for common recipes.
------------------------------------------------------------------------------
*MiniComment.setup()*
`MiniComment.setup`({config})
Module setup
Parameters~
{config} `(table)` Module config table. See |MiniComment.config|.
Usage~
`require('mini.comment').setup({})` (replace `{}` with your `config` table)
------------------------------------------------------------------------------
*MiniComment.config*
`MiniComment.config`
Module config
Default values:
>
MiniComment.config = {
-- Module mappings. Use `''` (empty string) to disable one.
mappings = {
-- Toggle comment (like `gcip` - comment inner paragraph) for both
-- Normal and Visual modes
comment = 'gc',
-- Toggle comment on current line
comment_line = 'gcc',
-- Define 'comment' textobject (like `dgc` - delete whole comment block)
textobject = 'gc',
},
-- Hook functions to be executed at certain stage of commenting
hooks = {
-- Before successful commenting. Does nothing by default.
pre = function() end,
-- After successful commenting. Does nothing by default.
post = function() end,
},
}
<
------------------------------------------------------------------------------
*MiniComment.operator()*
`MiniComment.operator`({mode})
Main function to be mapped
It is meant to be used in expression mappings (see |map-<expr>|) to enable
dot-repeatability and commenting on range. There is no need to do this
manually, everything is done inside |MiniComment.setup()|.
It has a somewhat unintuitive logic (because of how expression mapping with
dot-repeatability works): it should be called without arguments inside
expression mapping and with argument when action should be performed.
Parameters~
{mode} `(string)` Optional string with 'operatorfunc' mode (see |g@|).
Return~
`(string)` 'g@' if called without argument, '' otherwise (but after
performing action).
------------------------------------------------------------------------------
*MiniComment.toggle_lines()*
`MiniComment.toggle_lines`({line_start}, {line_end})
Toggle comments between two line numbers
It uncomments if lines are comment (every line is a comment) and comments
otherwise. It respects indentation and doesn't insert trailing
whitespace. Toggle commenting not in visual mode is also dot-repeatable
and respects |count|.
Before successful commenting it executes `MiniComment.config.hooks.pre`.
After successful commenting it executes `MiniComment.config.hooks.post`.
# Notes~
1. Currently call to this function will remove marks inside written range.
Use |lockmarks| to preserve marks.
Parameters~
{line_start} `(number)` Start line number (inclusive from 1 to number of lines).
{line_end} `(number)` End line number (inclusive from 1 to number of lines).
------------------------------------------------------------------------------
*MiniComment.textobject()*
`MiniComment.textobject`()
Comment textobject
This selects all commented lines adjacent to cursor line (if it itself is
commented). Designed to be used with operator mode mappings (see |mapmode-o|).
Before successful textobject usage it executes `MiniComment.config.hooks.pre`.
After successful textobject usage it executes `MiniComment.config.hooks.post`.
==============================================================================
------------------------------------------------------------------------------
*mini.completion*
*MiniCompletion*
Custom somewhat minimal autocompletion Lua plugin. Key design ideas:
- Have an async (with customizable 'debounce' delay) 'two-stage chain
completion': first try to get completion items from LSP client (if set
up) and if no result, fallback to custom action.
- Managing completion is done as much with Neovim's built-in tools as
possible.
Features:
- Two-stage chain completion:
- First stage is an LSP completion implemented via
|MiniCompletion.completefunc_lsp()|. It should be set up as either
|completefunc| or |omnifunc|. It tries to get completion items from
LSP client (via 'textDocument/completion' request). Custom
preprocessing of response items is possible (with
`MiniCompletion.config.lsp_completion.process_items`), for example
with fuzzy matching. By default items which are not snippets and
directly start with completed word are kept and sorted according to
LSP specification. Supports `additionalTextEdits`, like auto-import
and others (see 'Notes').
- If first stage is not set up or resulted into no candidates, fallback
action is executed. The most tested actions are Neovim's built-in
insert completion (see |ins-completion|).
- Automatic display in floating window of completion item info (via
'completionItem/resolve' request) and signature help (with highlighting
of active parameter if LSP server provides such information). After
opening, window for signature help is fixed and is closed when there is
nothing to show, text is different or
when leaving Insert mode.
- Automatic actions are done after some configurable amount of delay. This
reduces computational load and allows fast typing (completion and
signature help) and item selection (item info)
- Autoactions are triggered on Neovim's built-in events.
- User can force two-stage completion via
|MiniCompletion.complete_twostage()| (by default is mapped to
`<C-Space>`) or fallback completion via
|MiniCompletion.complete_fallback()| (maped to `<M-Space>`).
What it doesn't do:
- Snippet expansion.
- Many configurable sources.
- Automatic mapping of `<CR>`, `<Tab>`, etc., as those tend to have highly
variable user expectations. See 'Helpful key mappings' for suggestions.
# Setup~
This module needs a setup with `require('mini.completion').setup({})`
(replace `{}` with your `config` table). It will create global Lua table
`MiniCompletion` which you can use for scripting or manually (with
`:lua MiniCompletion.*`).
See |MiniCompletion.config| for `config` structure and default values.
# Notes~
- More appropriate, albeit slightly advanced, LSP completion setup is to set
it not on every `BufEnter` event (default), but on every attach of LSP
client. To do that:
- Use in initial config:
`lsp_completion = {source_func = 'omnifunc', auto_setup = false}`.
- In `on_attach()` of every LSP client set 'omnifunc' option to exactly
`v:lua.MiniCompletion.completefunc_lsp`.
- If you have trouble using custom (overriden) |vim.ui.input| (like from
'stevearc/dressing.nvim'), make automated disable of 'mini.completion'
for input buffer. For example, currently for 'dressing.nvim' it can be
with `au FileType DressingInput lua vim.b.minicompletion_disable = true`.
- Support of `additionalTextEdits` tries to handle both types of servers:
- When `additionalTextEdits` are supplied in response to
'textDocument/completion' request (like currently in 'pyright').
- When `additionalTextEdits` are supplied in response to
'completionItem/resolve' request (like currently in
'typescript-language-server'). In this case to apply edits user needs
to trigger such request, i.e. select completion item and wait for
`MiniCompletion.config.delay.info` time plus server response time.
# Comparisons~
- 'nvim-cmp':
- More complex design which allows multiple sources each in form of
separate plugin. `MiniCompletion` has two built in: LSP and fallback.
- Supports snippet expansion.
- Doesn't have customizable delays for basic actions.
- Doesn't allow fallback action.
- Doesn't provide signature help.
# Helpful key mappings~
To use `<Tab>` and `<S-Tab>` for navigation through completion list, make
these key mappings:
`vim.api.nvim_set_keymap('i', '<Tab>', [[pumvisible() ? "\<C-n>" : "\<Tab>"]], { noremap = true, expr = true })`
`vim.api.nvim_set_keymap('i', '<S-Tab>', [[pumvisible() ? "\<C-p>" : "\<S-Tab>"]], { noremap = true, expr = true })`
To get more consistent behavior of `<CR>`, you can use this template in
your 'init.lua' to make customized mapping: >
local keys = {
['cr'] = vim.api.nvim_replace_termcodes('<CR>', true, true, true),
['ctrl-y'] = vim.api.nvim_replace_termcodes('<C-y>', true, true, true),
['ctrl-y_cr'] = vim.api.nvim_replace_termcodes('<C-y><CR>', true, true, true),
}
_G.cr_action = function()
if vim.fn.pumvisible() ~= 0 then
-- If popup is visible, confirm selected item or add new line otherwise
local item_selected = vim.fn.complete_info()['selected'] ~= -1
return item_selected and keys['ctrl-y'] or keys['ctrl-y_cr']
else
-- If popup is not visible, use plain `<CR>`. You might want to customize
-- according to other plugins. For example, to use 'mini.pairs', replace
-- next line with `return require('mini.pairs').cr()`
return keys['cr']
end
end
vim.api.nvim_set_keymap('i', '<CR>', 'v:lua._G.cr_action()', { noremap = true, expr = true })
<
# Highlight groups~
* `MiniCompletionActiveParameter` - highlighting of signature active parameter.
By default displayed as plain underline.
To change any highlight group, modify it directly with |:highlight|.
# Disabling~
To disable, set `g:minicompletion_disable` (globally) or
`b:minicompletion_disable` (for a buffer) to `v:true`. Considering high
number of different scenarios and customization intentions, writing exact
rules for disabling module's functionality is left to user. See
|mini.nvim-disabling-recipes| for common recipes.
------------------------------------------------------------------------------
*MiniCompletion.setup()*
`MiniCompletion.setup`({config})
Module setup
Parameters~
{config} `(table)` Module config table. See |MiniCompletion.config|.
Usage~
`require('mini.completion').setup({})` (replace `{}` with your `config` table)
------------------------------------------------------------------------------
*MiniCompletion.config*
`MiniCompletion.config`
Module config
Default values:
>
MiniCompletion.config = {
-- Delay (debounce type, in ms) between certain Neovim event and action.
-- This can be used to (virtually) disable certain automatic actions by
-- setting very high delay time (like 10^7).
delay = { completion = 100, info = 100, signature = 50 },
-- Maximum dimensions of floating windows for certain actions. Action
-- entry should be a table with 'height' and 'width' fields.
window_dimensions = {
info = { height = 25, width = 80 },
signature = { height = 25, width = 80 },
},
-- Way of how module does LSP completion
lsp_completion = {
-- `source_func` should be one of 'completefunc' or 'omnifunc'.
source_func = 'completefunc',
-- `auto_setup` should be boolean indicating if LSP completion is set up
-- on every `BufEnter` event.
auto_setup = true,
-- `process_items` should be a function which takes LSP
-- 'textDocument/completion' response items and word to complete. Its
-- output should be a table of the same nature as input items. The most
-- common use-cases are custom filtering and sorting. You can use
-- default `process_items` as `MiniCompletion.default_process_items()`.
process_items = --<function: filters out snippets; sorts by LSP specs>,
},
-- Fallback action. It will always be run in Insert mode. To use Neovim's
-- built-in completion (see `:h ins-completion`), supply its mapping as
-- string. Example: to use 'whole lines' completion, supply '<C-x><C-l>'.
fallback_action = --<function: like `<C-n>` completion>,
-- Module mappings. Use `''` (empty string) to disable one. Some of them
-- might conflict with system mappings.
mappings = {
force_twostep = '<C-Space>', -- Force two-step completion
force_fallback = '<A-Space>', -- Force fallback completion
},
-- Whether to set Vim's settings for better experience (modifies
-- `shortmess` and `completeopt`)
set_vim_settings = true,
}
<
------------------------------------------------------------------------------
*MiniCompletion.auto_completion()*
`MiniCompletion.auto_completion`()
Auto completion
Designed to be used with |autocmd|. No need to use it directly, everything
is setup in |MiniCompletion.setup|.
------------------------------------------------------------------------------
*MiniCompletion.complete_twostage()*
`MiniCompletion.complete_twostage`({fallback}, {force})
Run two-stage completion
Parameters~
{fallback} `(boolean)` Whether to use fallback completion.
{force} `(boolean)` Whether to force update of completion popup.
------------------------------------------------------------------------------
*MiniCompletion.complete_fallback()*
`MiniCompletion.complete_fallback`()
Run fallback completion
------------------------------------------------------------------------------
*MiniCompletion.auto_info()*
`MiniCompletion.auto_info`()
Auto completion entry information
Designed to be used with |autocmd|. No need to use it directly, everything
is setup in |MiniCompletion.setup|.
------------------------------------------------------------------------------
*MiniCompletion.auto_signature()*
`MiniCompletion.auto_signature`()
Auto function signature
Designed to be used with |autocmd|. No need to use it directly, everything
is setup in |MiniCompletion.setup|.
------------------------------------------------------------------------------
*MiniCompletion.stop()*
`MiniCompletion.stop`({actions})
Stop actions
This stops currently active (because of module delay or LSP answer delay)
actions.
Designed to be used with |autocmd|. No need to use it directly, everything
is setup in |MiniCompletion.setup|.
Parameters~
{actions} `(table)` Array containing any of 'completion', 'info', or
'signature' string.
------------------------------------------------------------------------------
*MiniCompletion.on_text_changed_i()*
`MiniCompletion.on_text_changed_i`()
Act on every |TextChangedI|
------------------------------------------------------------------------------
*MiniCompletion.on_text_changed_p()*
`MiniCompletion.on_text_changed_p`()
Act on every |TextChangedP|
------------------------------------------------------------------------------
*MiniCompletion.completefunc_lsp()*
`MiniCompletion.completefunc_lsp`({findstart}, {base})
Module's |complete-function|
This is the main function which enables two-stage completion. It should be
set as one of |completefunc| or |omnifunc|.
No need to use it directly, everything is setup in |MiniCompletion.setup|.
------------------------------------------------------------------------------
*MiniCompletion.default_process_items()*
`MiniCompletion.default_process_items`({items}, {base})
Default `MiniCompletion.config.lsp_completion.process_items`
==============================================================================
------------------------------------------------------------------------------
*mini.cursorword*
*MiniCursorword*
Minimal and fast module for autohighlighting word under cursor with
customizable delay. Current word under cursor can be highlighted
differently. Highlighting is triggered only if current cursor character is
a |[:keyword:]|. "Word under cursor" is meant as in Vim's |<cword>|:
something user would get as 'iw' text object. Highlighting stops in insert
and terminal modes.
# Setup~
This module needs a setup with `require('mini.cursorword').setup({})`
(replace `{}` with your `config` table). It will create global Lua table
`MiniCursorword` which you can use for scripting or manually (with
`:lua MiniCursorword.*`).
See |MiniCursorword.config| for `config` structure and default values.
# Highlight groups~
* `MiniCursorword` - highlight group of cursor word. Default: plain underline.
* `MiniCursorwordCurrent` - highlight group of a current word under
cursor. It will be displayed on top of `MiniCursorword`
(so `:hi clear MiniCursorwordCurrent` will lead to showing
`MiniCursorword` highlight group). Note: To not highlight it, use
`:hi! MiniCursorwordCurrent gui=nocombine guifg=NONE guibg=NONE` .
To change any highlight group, modify it directly with |:highlight|.
# Disabling~
To disable core functionality, set `g:minicursorword_disable` (globally) or
`b:minicursorword_disable` (for a buffer) to `v:true`. Considering high
number of different scenarios and customization intentions, writing exact
rules for disabling module's functionality is left to user. See
|mini.nvim-disabling-recipes| for common recipes. Note: after disabling
there might be highlighting left; it will be removed after next
highlighting update.
Module-specific disabling:
- Don't show highlighting if cursor is on the word that is in a blocklist
of current filetype. In this example, blocklist for "lua" is "local" and
"require" words, for "javascript" - "import":
>
_G.cursorword_blocklist = function()
local curword = vim.fn.expand('<cword>')
local filetype = vim.api.nvim_buf_get_option(0, 'filetype')
-- Add any disabling global or filetype-specific logic here
local blocklist = {}
if filetype == 'lua' then
blocklist = { 'local', 'require' }
elseif filetype == 'javascript' then
blocklist = { 'import' }
end
vim.b.minicursorword_disable = vim.tbl_contains(blocklist, curword)
end
-- Make sure to add this autocommand *before* calling module's `setup()`.
vim.cmd('au CursorMoved * lua _G.cursorword_blocklist()')
------------------------------------------------------------------------------
*MiniCursorword.setup()*
`MiniCursorword.setup`({config})
Module setup
Parameters~
{config} `(table)` Module config table. See |MiniCursorword.config|.
Usage~
`require('mini.cursorword').setup({})` (replace `{}` with your `config` table)
------------------------------------------------------------------------------
*MiniCursorword.config*
`MiniCursorword.config`
Module config
Default values:
>
MiniCursorword.config = {
-- Delay (in ms) between when cursor moved and when highlighting appeared
delay = 100,
}
<
------------------------------------------------------------------------------
*MiniCursorword.auto_highlight()*
`MiniCursorword.auto_highlight`()
Auto highlight word under cursor
Designed to be used with |autocmd|. No need to use it directly,
everything is setup in |MiniCursorword.setup|.
------------------------------------------------------------------------------
*MiniCursorword.auto_unhighlight()*
`MiniCursorword.auto_unhighlight`()
Auto unhighlight word under cursor