forked from neoclide/coc.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coc.txt
4144 lines (2854 loc) · 131 KB
/
coc.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
*coc-nvim.txt* NodeJS client for Vim & Neovim.
Version: 0.0.82
Author: Qiming Zhao <chemzqm at gmail.com>
CONTENTS *coc-contents*
Introduction |coc-introduction|
Requirements |coc-requirements|
Installation |coc-installation|
Extensions |coc-extensions|
Configuration |coc-configuration|
Floating windows |coc-floating|
LSP features |coc-lsp|
Document |coc-document|
Hover |coc-hover|
Completion |coc-completion|
Diagnostics |coc-diagnostics|
Pull diagnostics |coc-pullDiagnostics|
Locations |coc-locations|
Rename |coc-rename|
Signature help |coc-signature|
Inlay hint |coc-inlayHint|
Format |coc-format|
Code action |coc-code-actions|
Document highlights |coc-document-highlights|
Document colors |coc-document-colors|
Document links |coc-document-links|
Snippets |coc-snippets|
Workspace |coc-workspace|
Cursors |coc-cursors|
Outline |coc-outline|
Call hierarchy |coc-callHierarchy|
Type hierarchy |coc-typeHierarchy|
Semantic highlights |coc-semantic-highlights|
Fold |coc-fold|
Selection range |coc-selection-range|
Code Lens |coc-code-lens|
Linked editing |coc-linked-editing|
Interface |coc-interface|
Key mappings |coc-key-mappings|
Variables |coc-variables|
Buffer variables |coc-buffer-variables|
Global variables |coc-global-variables|
Functions |coc-functions|
Commands |coc-commands|
Autocmds |coc-autocmds|
Highlights |coc-highlights|
Tree |coc-tree|
Tree mappings |coc-tree-mappings|
Tree filter |coc-tree-filter|
List |coc-list|
List command |coc-list-command|
List command options |coc-list-options|
List configuration |coc-list-configuration|
List mappings |coc-list-mappings|
list sources |coc-list-sources|
Dialog |coc-dialog|
Dialog basic |coc-dialog-basic|
Dialog confirm |coc-dialog-confirm|
Dialog input |coc-dialog-input|
Dialog menu |coc-dialog-menu|
Dialog picker |coc-dialog-picker|
Notification |coc-notification|
Statusline integration |coc-status|
Manual |coc-status-manual|
Airline |coc-status-airline|
Lightline |coc-status-lightline|
Create plugins |coc-plugins|
FAQ |coc-faq|
Change log |coc-changelog|
==============================================================================
INTRODUCTION *coc-introduction*
Coc.nvim enhances your (Neo)Vim to match the user experience provided by
VSCode through a rich extension ecosystem and implemented the client features
specified by Language Server Protocol (3.17 for now), see |coc-lsp|.
Some features (like completion) automatically works by default, all of them
can be disabled by |coc-configuration|.
Some key features:~
• Typescript APIs compatible with both Vim8 and Neovim.
• Loading VSCode-like extensions |coc-api-extension|.
• Configuring coc.nvim and its extensions with JSON configuration
|coc-configuration|.
• Configuring Language Servers that using Language Server Protocol (LSP)
|coc-config-languageserver|.
It is designed for best possible integration with other Vim plugins.
Note: coc.nvim doesn't come with support for any specific language. You
will need to install coc.nvim extensions |coc-extensions| or set up the
language server by use |coc-config-languageserver|.
Note: multiple language servers for same document is allowed, but you should
avoid configure same language server that already used by coc.nvim extension.
Note: automatic completion plugins can't play nicely together, you can disable
automatic completion of coc.nvim by use `"suggest.autoTrigger": "none"` (or
`"suggest.autoTrigger": "trigger"`) in your |coc-configuration|.
==============================================================================
REQUIREMENTS *coc-requirements*
Neovim >= 0.4.0 or Vim >= 8.1.1719.
NodeJS https://nodejs.org/ >= 14.14.0.
Yarn https://yarnpkg.com/ required to build coc.nvim from typescript source
code.
==============================================================================
INSTALLATION *coc-installation*
If you're using [vim-plug](https://github.com/junegunn/vim-plug), add this to
your `init.vim` or `.vimrc`: >
Plug 'neoclide/coc.nvim', {'branch': 'release'}
<
And run: >
:PlugInstall
For other plugin managers, make sure to use the release branch (unless you
need to build from typescript source code).
To use Vim's native |packages| on Linux or MaxOS, use script like: >
#!/bin/sh
# for vim8
mkdir -p ~/.vim/pack/coc/start
cd ~/.vim/pack/coc/start
curl --fail -L https://github.com/neoclide/coc.nvim/archive/release.tar.gz|tar xzfv -
vim -c 'helptags ~/.vim/pack/coc/start/doc|q'
# for neovim
mkdir -p ~/.local/share/nvim/site/pack/coc/start
cd ~/.local/share/nvim/site/pack/coc/start
curl --fail -L https://github.com/neoclide/coc.nvim/archive/release.tar.gz|tar xzfv -
nvim -c 'helptags ~/.local/share/nvim/site/pack/coc/start|q'
when using source code of coc.nvim, you'll have to install
https://yarnpkg.com/ and run `yarn install` in project root of coc.nvim.
==============================================================================
EXTENSIONS *coc-extensions*
To provide LSP features of different filetypes, the user have to config
|coc-config-languageserver| or install coc extensions.
Extensions are more powerful since they could contribute json schemes,
commands, and use middleware methods of languageserver to provide better
results. It's also possible to provide features that beyond LSP.
*coc-extensions-folder*
Extensions are loaded from `"extensions"` folder inside
|coc#util#get_data_home()| and folders in 'runtimepath' when detected.
Use `let $COC_NO_PLUGINS = '1'` in vimrc to disable the load of extensions.
See |coc-api-extension| for the guide to create coc.nvim extension.
Install extensions from git (not recommended):~
• Download the source code.
• In project root, install dependencies and compile the code by `yarn install`
(needed by most coc extensions).
• Add the project root to vim's runtimepath by `set runtimepath^=/path/to/project`
Plugin manager like [vim-plug] can be used as well.
Note: use coc.nvim extensions from source code requires install dependencies,
which may take huge disk usage.
*coc-extensions-npm*
Install global extensions from npm (recommended):~
Use |:CocInstall| to install coc extensions from vim's command line.
To make coc.nvim install extensions on startup, use |g:coc_global_extensions|.
To use package manager other than npm (like `yarn` or `pnpm`), use
|coc-config-npm-binPath|.
To customize npm registry for coc.nvim add `coc.nvim:registry` in your
`~/.npmrc`, like:
>
coc.nvim:registry=https://registry.mycompany.org/
<
To customize extension folder, configure |g:coc_data_home|.
Uninstall global extensions:~
Use |:CocUninstall|.
Update global extensions:~
Use |:CocUpdate| or |:CocUpdateSync|.
To update extensions automatically, config |coc-preferences-extensionUpdateCheck|.
Manage extensions list:~
Use |coc-list-extensions| or |CocAction('extensionStats')| to get list of extensions.
==============================================================================
CONFIGURATION *coc-configuration*
The configuration of coc.nvim is stored in file named "coc-settings.json".
Configuration properties are contributed by coc.nvim itself and coc.nvim
extensions. See |coc-config| for builtin configurations.
The configuration files are all in JSON format (with comment supported), it's
recommended to enable JSON completion and validation by install the `coc-json`
extension:
>
:CocInstall coc-json
<
To fix the highlight of comment, use:
>
autocmd FileType json syntax match Comment +\/\/.\+$+
<
in your vimrc.
Global configuration file:~
Command |:CocConfig| will open (create when necessary) a user settings
file in the folder returned by |coc#util#get_config_home()|.
The user configuration value could be overwritten by API |coc#config()| or
|g:coc_user_config|.
The global configuration file can be created in another directory by setting
|g:coc_config_home| in your vimrc like: >
let g:coc_config_home = '/path/to/folder'
Folder configuration file:~
To create a local configuration file for a specific workspace folder, use
|:CocLocalConfig| to create and open `.vim/coc-settings.json` in current
workspace folder.
Folder configuration would overwrite user configuration.
Note: the configuration file won't work when the parent folder is not resolved
as workspace folder, it's best practice to start vim inside workspace folder,
see |coc-workspace-folders|.
*coc-configuration-expand*
Variables expands:~
Variables would be expanded in string values of configuration, supported
variables:
• `${userHome}` the path of the user's home folder
• `${cwd}` current working directory of vim.
You can also reference environment variables through the `${env:name}` syntax
(for example, `${env:USERNAME}`), no expand happens when env not exists.
Configurations that requires file paths (ex:
|coc-config-workspace-ignoredFolders|) support expand `~` at the beginning of
the filepath to user's home and some additional variables:
• `${workspaceFolder}` the current opened file's workspace folder.
• `${workspaceFolderBasename}` the name of the workspace folder opened in
coc.nvim without any slashes (/).
• `${file}` the current opened file.
• `${fileDirname}` the current opened file's dirname.
• `${fileExtname}` the current opened file's extension.
• `${fileBasename}` the current opened file's basename
• `${fileBasenameNoExtension}` the current opened file's basename with no file extension.
*coc-configuration-scope*
Configuration scope:~
A configuration could be one of three different configuration scopes:
• `"application"` the configuration could only be used in user configuration
file.
• `"resource"` the configuration could be used in user and workspace folder
configuration file.
• `"language-overridable"` the configuration could be used in user and
workspace folder configuration file, and can be use used in language scoped
configuration section like `[typescript][json]`. For example: >
// disable inlay hint for some languages
"[rust][lua][c]": {
"inlayHint.enable": false
}
<
==============================================================================
FLOATING WINDOWS *coc-floating*
Floating windows/popups are created by |api-floatwin| on neovim or |popupwin|
on vim.
*coc-floating-scroll*
Scroll floating windows:~
See |coc#float#has_scroll()| for example.
Note: use |coc#pum#scroll()| for scroll popup menu.
*coc-floating-close*
Close floating windows:~
To close all floating windows/popups use |coc#float#close_all()| or
|popup_clear()| on vim. Or you can use <CTRL-w>o on neovim which close all
split windows as well. Or use |popup_clear()| on vim.
To close single floating window/popup, use |coc#float#close()|.
*coc-floating-focus*
Focus floating windows:~
On neovim, use <CTRL-w>w (or |<Plug>(coc-float-jump)|) could focus a floating
window just created (if it's focusable). It's not allowed to focus popups on
vim, unless it's using a terminal buffer.
*coc-floating-config*
Configure floating windows:~
To set custom window options on floating window create, use autocmd
|CocOpenFloat| or |CocOpenFloatPrompt|.
Related variables:
• |g:coc_last_float_win|
• |g:coc_borderchars|
• |g:coc_border_joinchars|
• |g:coc_markdown_disabled_languages|
Related highlight groups:
• |CocFloating| For floating window background.
• |CocFloatDividingLine| For dividing lines.
• |CocFloatActive| For active parts.
• |CocMenuSel| For selected line.
To customize floating windows used by popup menu, use:
• |coc-config-suggest-floatConfig|
• |coc-config-suggest-pumFloatConfig|
For floating windows created around cursor, like diagnostics, hover and
signature use |coc-config-floatFactory-floatConfig| for common float
configurations. For further customization, use:
• |coc-config-diagnostic-floatConfig|
• |coc-config-signature-floatConfig|
• |coc-config-hover-floatConfig|
For customize dialog windows, use |coc-config-dialog|.
For customize notification windows, use |coc-config-notification|.
Configure |coc-preferences-enableMessageDialog| to show messages as
notifications (except for the messages of unexpected errors which are always
echoed).
==============================================================================
LSP FEATURES *coc-lsp*
Most features of LSP 3.17 are supported, checkout the specification at
https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/
Features not supported:
• Telemetry.
• Inline values for debugger.
• Notebook document.
LSP features only works with attached documents, see |coc-document-attached|.
To check exists providers of current buffer, use command
`:CocCommand document.checkBuffer` or API |CocHasProvider()|.
For historic reason, some features automatically works by default, but some
are not.
Features automatically work by default:~
• Trigger completion |coc-completion|.
• Diagnostics refresh |coc-diagnostics|.
• Pull diagnostics |coc-pullDiagnostics|.
• Trigger signature help |coc-signature|.
• Inlay hints |coc-inlayHint|
Most features could be toggled by |coc-configuration| and some vim variables.
Features require enabled by configuration:~
• Semantic highlights |coc-semantic-highlights|.
• Document color highlights |coc-document-colors|.
• Code lens, |coc-code-lens|
• Linked editing, |coc-linked-editing|.
• Format on type, enabled by |coc-preferences-formatOnType|
• Format on save, enabled by |coc-preferences-formatOnSave|.
Features requested by user:~
• Locations related (including definitions, references etc.) |coc-locations|
• Invoke code action |coc-code-actions|.
• Show call hierarchy tree |coc-callHierarchy|.
• Show type hierarchy tree |coc-typeHierarchy|
• Format, range format and on type format |coc-format|.
• Highlight same symbol ranges |coc-document-highlights|.
• Outline of document symbols |coc-outline| and |coc-list-symbols|.
• Show hover information |coc-hover|.
• Rename symbol under cursor |coc-rename|.
• Open link under cursor |coc-document-links|.
• Selection range |coc-selection-range|
• Create folding ranges |coc-fold|.
For convenient, some actions have associated |coc-key-mappings| provided.
Prefer |CocAction()| for more options.
Features triggered by languageserver:~
• Show message notification (use |coc-notification|).
• Show message request (use |coc-dialog-menu|).
• Log message notification (use `:CocCommand workspace.showOutput` to show
output).
• Show document request (opened by vim or your browser for url).
• Work done progress (use |coc-notification|).
To make coc.nvim provide LSP features for your languages, checkout
https://github.com/neoclide/coc.nvim/wiki/Language-servers
To debug issues with languageserver, checkout
https://github.com/neoclide/coc.nvim/wiki/Debug-language-server
------------------------------------------------------------------------------
DOCUMENT *coc-document*
An associated document is created on buffer create, and disposed on buffer
unload.
Attached document:~
*coc-document-attached*
An attached document means coc.nvim synchronize the lines of vim's buffer with
associated document automatically.
Only attached documents are synchronized with language servers and therefore
LSP features could be provided for the attached buffer.
The buffer may not be attached by following reasons:
• The 'buftype' is neither <empty> nor 'acwrite', (could be bypassed by
|b:coc_force_attach|).
• Buffer variable |b:coc_enabled| is `0`.
• Byte length of buffer exceed |coc-preferences-maxFileSize|.
• Buffer is used for command line window.
Use |CocAction('ensureDocument')| or `:CocCommand document.checkBuffer` to
check attached state of current buffer.
Filetype map:~
*coc-document-filetype*
Some filetypes are mapped to others to match the languageId used by VSCode,
including:
• javascript.jsx -> javascriptreact
• typescript.jsx -> typescriptreact
• typescript.tsx -> typescriptreact
• tex -> latex
Use |g:coc_filetype_map| to create additional filetype maps.
Use `:CocCommand document.echoFiletype` to echo mapped filetype of current
document.
Note make sure use mapped filetypes for configurations that expect filetypes.
------------------------------------------------------------------------------
HOVER *coc-hover*
Hover feature provide information at a given text document position, normally
include type information and documentation of current symbol.
Hover functions:~
• |CocAction('doHover')| Show hover information at cursor position.
• |CocAction('definitionHover')||| Show hover information with definition
context at cursor position.
• |CocAction('getHover')| Get hover documentations at cursor position.
*coc-hover-example*
Hover key-mapping example:~
>
nnoremap <silent> K :call ShowDocumentation()<CR>
" Show hover when provider exists, fallback to vim's builtin behavior.
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('definitionHover')
else
call feedkeys('K', 'in')
endif
endfunction
<
------------------------------------------------------------------------------
COMPLETION *coc-completion*
Vim's builtin completion is no longer used. The default completion
now works like in VSCode:
• Completion is automatically triggered by default.
• Selection is enabled by default, use |coc-config-suggest-noselect| to
disable default selection.
• When selection is enabled and no preselect item exists, the first complete
item will be selected (depends on |coc-config-suggest-selection|).
• Snippet expand and additional edits only work after confirm completion.
• 'completeopt' is not used and APIs of builtin popupmenu not work.
*coc-completion-default*
Default Key-mappings:~
To make the new completion work like the builtin completion, without any
additional configuration, the following key-mappings are used when
the {lhs} is not mapped:
Use <C-n>, <C-p>, <up> and <down> to navigate completion list: >
inoremap <silent><expr> <C-n> coc#pum#visible() ? coc#pum#next(1) : "\<C-n>"
inoremap <silent><expr> <C-p> coc#pum#visible() ? coc#pum#prev(1) : "\<C-p>"
inoremap <silent><expr> <down> coc#pum#visible() ? coc#pum#next(0) : "\<down>"
inoremap <silent><expr> <up> coc#pum#visible() ? coc#pum#prev(0) : "\<up>"
<
Use <PageDown> and <PageUp> to scroll: >
inoremap <silent><expr> <PageDown> coc#pum#visible() ? coc#pum#scroll(1) : "\<PageDown>"
inoremap <silent><expr> <PageUp> coc#pum#visible() ? coc#pum#scroll(0) : "\<PageUp>"
<
Use <C-e> and <C-y> to cancel and confirm completion: >
inoremap <silent><expr> <C-e> coc#pum#visible() ? coc#pum#cancel() : "\<C-e>"
inoremap <silent><expr> <C-y> coc#pum#visible() ? coc#pum#confirm() : "\<C-y>"
Note: <CR> and <Tab> are not remapped by coc.nvim.
*coc-completion-variables*
Related variables:~
• Disable completion for buffer: |b:coc_suggest_disable|
• Disable specific sources for buffer: |b:coc_disabled_sources|
• Disable words for completion: |b:coc_suggest_blacklist|
• Add additional keyword characters: |b:coc_additional_keywords|
*coc-completion-functions*
Related functions:~
• Trigger completion with options: |coc#start()|.
• Trigger completion refresh: |coc#refresh()|.
• Select and confirm completion: |coc#_select_confirm()|.
• Check if the custom popupmenu is visible: |coc#pum#visible()|.
• Select the next completion item: |coc#pum#next()|.
• Select the previous completion item: |coc#pum#prev()|.
• Cancel completion and reset trigger text: |coc#pum#cancel()|.
• Confirm completion: |coc#pum#confirm()|.
• Close the popupmenu only: |coc#pum#stop()|.
• Get information about the popupmenu: |coc#pum#info()|.
• Select specific completion item: |coc#pum#select()|.
• Insert word of selected item and finish completion: |coc#pum#insert()|.
• Insert one more character from current complete item: |coc#pum#one_more()|.
• Scroll popupmenu: |coc#pum#scroll()|.
*coc-completion-customize*
Customize completion:~
Use |coc-config-suggest| to change the completion behavior.
Use 'pumwidth' for configure the minimal width of the popupmenu and 'pumheight'
for its maximum height.
Related Highlight groups:
|CocPum| for highlight groups of customized pum.
|CocSymbol| for kind icons.
|CocMenuSel| for background highlight of selected item.
Note: background, border and winblend are configured by
|coc-config-suggest-floatConfig|.
Example user key-mappings:~
*coc-completion-example*
Note: use command `:verbose imap` to check current insert
key-mappings when your key-mappings not work.
Use <tab> and <S-tab> to navigate completion list: >
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
" Insert <tab> when previous text is space, refresh completion if not.
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1):
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
Use <c-space> to trigger completion: >
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
<
Use <CR> to confirm completion, use: >
inoremap <expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<CR>"
<
To make <CR> to confirm selection of selected complete item or notify coc.nvim
to format on enter, use: >
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
Map <tab> for trigger completion, completion confirm, snippet expand and jump
like VSCode: >
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ?
\ "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ CheckBackspace() ? "\<TAB>" :
\ coc#refresh()
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = '<tab>'
<
Note: the `coc-snippets` extension is required for this to work.
------------------------------------------------------------------------------
DIAGNOSTICS SUPPORT *coc-diagnostics*
Diagnostics of coc.nvim are automatically refreshed to UI by default, checkout
|coc-config-diagnostic| for available configurations.
Note most language servers only send diagnostics for opened buffers for
performance reason, some lint tools could provide diagnostics for all files in
workspace.
Note pull diagnostics feature is added in LSP 3.17, which is not available
yet.
*coc-diagnostics-refresh*
Changes on diagnostics refresh~
• Add highlights for diagnostic ranges and virtual text (when enabled on
neovim or vim >= 9.0.0067), see |coc-highlights-diagnostics|.
• Add diagnostic signs to 'signcolumn', use `set signcolumn=yes` to avoid
unnecessary UI refresh.
• Update variable |b:coc_diagnostic_info|.
• Refresh related |location-list| which was opened by |:CocDiagnostics|.
Diagnostics are not refreshed when buffer is hidden, and refresh on insert
mode is disabled by default.
Diagnostics highlights:~
See |coc-highlights-diagnostics|.
*coc-diagnostics-toggle*
Enable and disable diagnostics~
Use |coc-config-diagnostic-enable| to toggle diagnostics feature.
Use |CocAction('diagnosticToggle')| for enable/disable diagnostics feature.
Use |CocAction('diagnosticToggleBuffer')| for enable/disable diagnostics of
current buffer.
Show diagnostic messages~
Diagnostic messages would be automatically shown/hide when the diagnostics
under cursor position changed (use float window/popup when possible) by
default.
To manually refresh diagnostics messages, use |<Plug>(coc-diagnostic-info)|
and |CocAction('diagnosticPreview')|.
*coc-diagnostics-jump*
Jump between diagnostics~
Use key-mappings:
|<Plug>(coc-diagnostic-next)| jump to diagnostic after cursor position.
|<Plug>(coc-diagnostic-prev)| jump to diagnostic before cursor position.
|<Plug>(coc-diagnostic-next-error)| jump to next error.
|<Plug>(coc-diagnostic-prev-error)| jump to previous error.
Check all diagnostics~
Use |coc-list-diagnostics| to open |coc-list| with all available diagnostics.
Use API |CocAction('diagnosticList')| to get list of all diagnostics.
------------------------------------------------------------------------------
PULL DIAGNOSTICS SUPPORT *coc-pullDiagnostics*
Diagnostics are pulled for visible documents when supported by languageserver.
Pull for workspace diagnostics is also enabled by default.
Document diagnostics are pulled on change by default, and can be
configured to be pulled on save.
Checkout |coc-config-pullDiagnostic| for related configurations.
------------------------------------------------------------------------------
LOCATIONS SUPPORT *coc-locations*
There're different kinds of locations, including "definitions", "declarations",
"implementations", "typeDefinitions" and "references".
Key-mappings for invoke locations request~
• |<Plug>(coc-definition)|
• |<Plug>(coc-declaration)|
• |<Plug>(coc-implementation)|
• |<Plug>(coc-type-definition)|
• |<Plug>(coc-references)|
• |<Plug>(coc-references-used)|
Error will be shown when the buffer not attached |coc-document-attached|.
Message will be shown when no result found.
Location jump behavior~
When there's only one location returned, the location is opened by command
specified by |coc-preferences-jumpCommand| ("edit" by default), context mark
is added by |m'|, so you can jump back previous location by <C-o>.
When multiple locations returned, |coc-list-location| is opened for preview
and other further actions.
To use |coc-list-location| for single location as well, use
|coc-locations-api| (instead key-mappings provided by coc.nvim).
To change default options of |coc-list-location| or use other plugin for
list of locations, see |g:coc_enable_locationlist|.
To use vim's quickfix for locations, use configuration
|coc-preferences-useQuickfixForLocations|.
To use vim's tag list for definitions, use |CocTagFunc()|.
*coc-locations-api*
Related APIs~
• |CocAction('jumpDefinition')| Jump to definition locations.
• |CocAction('jumpDeclaration')| Jump to declaration locations.
• |CocAction('jumpImplementation')| Jump to implementation locations.
• |CocAction('jumpTypeDefinition')| Jump to type definition locations.
• |CocAction('jumpReferences')|| Jump to references.
• |CocAction('jumpUsed')| Jump to references without declarations.
• |CocAction('definitions')| Get definition list.
• |CocAction('declarations')| Get declaration list.
• |CocAction('implementations')| Get implementation list.
• |CocAction('typeDefinitions')| Get type definition list.
• |CocAction('references')| Get reference list.
Send custom locations request to languageserver:
• |CocLocations()|
• |CocLocationsAsync()|
------------------------------------------------------------------------------
RENAME *coc-rename*
Rename provides workspace-wide rename of a symbol. Workspace edit
|coc-workspace-edit| is requested and applied to related buffers when
confirmed.
Check if current buffer has rename provider with
`:echo CocAction('hasProvider', 'rename')`
Rename key-mappings:~
• |<Plug>(coc-rename)|
Rename functions:~
• |CocAction('rename')| Rename the symbol under the cursor.
• |CocAction('refactor')| Open refactor buffer for all references (including
definitions), recommended for function signature refactor.
Rename local variable:~
Use command `:CocCommand document.renameCurrentWord` which uses |coc-cursors|
to edit multiple locations at the same time and defaults to word extraction
when rename provider doesn't exist.
Rename configuration:~
Use |coc-preferences-renameFillCurrent| to enable/disable populating prompt
window with current variable name.
------------------------------------------------------------------------------
SIGNATURE HELP *coc-signature*
Signature help for functions is shown automatically when user
types trigger characters defined by the provider, which will use floating
window/popup to show relevant documentation.
Use |CocAction('showSignatureHelp')| to trigger signature help manually.
Note error will not be thrown when provider does not exist or nothing is returned
by languageserver, use `echo CocAction('hasProvider', 'signature')` to check
if a signature help provider exists.
Use |coc-config-signature| to change default signature help behavior.
|CocFloatActive| is used to highlight activated parameter part.
------------------------------------------------------------------------------
INLAY HINT *coc-inlayHint*
Inlay hint is enabled for all filetypes by default. Inlay hint uses virtual
text which requires neovim >= 0.5.0 or vim >= 9.0.0067.
Note: you may need configure extension or languageserver to make inlay hint
works.
To temporarily toggle inlay hint of current buffer, use command
`:CocCommand document.toggleInlayHint`
Change highlight group:~
• |CocInlayHint|
• |CocInlayHintType|
• |CocInlayHintParameter|
Configure inlay hint support:~
|coc-config-inlayHint|
------------------------------------------------------------------------------
FORMAT *coc-format*
Some tools may reload buffer from disk file during format, coc.nvim only
apply `TextEdit[]` to the document.
Don't be confused with vim's indent feature, configure/fix the 'indentexpr' of
your buffer if the indent is wrong after character insert. (use
|coc-format-ontype| might helps with the indent)
*coc-format-options*
Format options:~
Buffer options that affect document format: 'eol', 'shiftwidth' and
'expandtab'.
• |b:coc_trim_trailing_whitespace| Trim trailing whitespace on a line.
• |b:coc_trim_final_newlines| Trim all newlines after the final newline at
the end of the file.
Those options are converted to `DocumentFormattingOptions` and transferred to
languageservers before format. Note: the languageservers may only support
some of those options.
*coc-format-document*
Format full document:~
Use |CocAction('format')|, you can create a command like: >
command! -nargs=0 Format :call CocActionAsync('format')
<
to format current buffer.
*coc-format-ontype*
Format on type:~
Format on type could be enabled by |coc-preferences-formatOnType|.
Use `:CocCommand document.checkBuffer` to check if `formatOnType` provider
exists for current buffer.
To format on <CR>, create key-mapping of <CR> that uses |coc#on_enter()|.
If you don't like the behavior on type bracket characters, configure
|coc-preferences-bracketEnterImprove||.
*coc-format-selected*
Format selected code:~
Use 'formatexpr' for specific filetypes: >
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
So that |gq| could works for format range of lines.
>
Setup visual mode and operator key-mappings: >
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
<
*coc-format-onsave*
Format on save:~
To enable format on save, use configuration |coc-preferences-formatOnSave|.
Or create |BufWritePre| autocmd like: >
autocmd BufWritePre * call CocAction('format')
<
Note the operation have to synchronized, avoid use |CocActionAsync()|.
Note to skip the autocmd, use `:noa w` to save the buffer.
The operation on save will block your vim, to not block too long time, the
operation will be canceled after 0.5s, configured by
|coc-preferences-willSaveHandlerTimeout|
------------------------------------------------------------------------------
CODE ACTION *coc-code-actions*
Code actions are used for ask languageserver to provide specific kind code
changes.
Possible code action kinds:
• `quickfix` used for fix diagnostic(s).
• `refactor` used for code refactor.
• `source` code actions apply to the entire file.
• `organizeImport` organize import statements of current document.
Key-mappings for code actions:~
• |<Plug>(coc-fix-current)| Invoke quickfix action at current line if any.
• |<Plug>(coc-codeaction-cursor)| Choose code actions at cursor position.
• |<Plug>(coc-codeaction-line)| Choose code actions at current line.
• |<Plug>(coc-codeaction)| Choose code actions of current file.
• |<Plug>(coc-codeaction-source)| Choose source code action of current file.
• |<Plug>(coc-codeaction-selected)| Choose code actions from selected range.
• |<Plug>(coc-codeaction-refactor)| Choose refactor code action at cursor
position.
• |<Plug>(coc-codeaction-refactor-selected)| Choose refactor code action with
selected code.
Except for |<Plug>(coc-fix-current)| which invoke code action directly,
|coc-dialog-menu| would be shown for pick specific code action.
To invoke organize import action, use command like:
>
command! -nargs=0 OR :call CocAction('organizeImport')
See |CocAction('organizeImport')| for details.
Related APIs~
• |CocAction('codeActions')|
• |CocAction('organizeImport')|
• |CocAction('fixAll')|
• |CocAction('quickfixes')|
• |CocAction('doCodeAction')|
• |CocAction('doQuickfix')|
• |CocAction('codeActionRange')|
------------------------------------------------------------------------------
DOCUMENT HIGHLIGHTS *coc-document-highlights*
Document highlights is used for highlight same symbols of current document
under cursor.
To enable highlight on CursorHold, create an autocmd like this: >
autocmd CursorHold * call CocActionAsync('highlight')
<
Checkout |coc-highlights-document| for related highlight groups.
Note error will not be thrown when provider not exists or nothing returned
from languageserver with |CocAction('highlight')|
Install `coc-highlight` extension if you want to highlight same words under
cursor without languageserver support.
To jump between previous/next symbol position, use
`:CocCommand document.jumpToPrevSymbol` and
`:CocCommand document.jumpToNextSymbol`
------------------------------------------------------------------------------
DOCUMENT COLORS *coc-document-colors*
Document colors added color highlights to vim buffers. To enable document
color highlights, use |coc-config-colors-enable|.
The feature requires vim >= 8.1.1719 or neovim >= 0.5.0.