-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathcodeium.vim
More file actions
131 lines (106 loc) · 4.33 KB
/
codeium.vim
File metadata and controls
131 lines (106 loc) · 4.33 KB
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
if exists('g:loaded_codeium')
finish
endif
let g:loaded_codeium = 1
command! -nargs=? -complete=customlist,codeium#command#Complete Codeium exe codeium#command#Command(<q-args>)
if !codeium#util#HasSupportedVersion()
finish
endif
function! s:SetStyle() abort
if &t_Co == 256
hi def CodeiumSuggestion guifg=#808080 ctermfg=244
hi def CodeiumFlash ctermbg=153 guibg=#ADD8E6 gui=bold cterm=bold
else
hi def CodeiumSuggestion guifg=#808080 ctermfg=8
hi def CodeiumFlash ctermbg=7 guibg=LightBlue gui=bold cterm=bold
endif
hi def link CodeiumAnnotation Normal
" Register the property types for Vim
if !has('nvim')
if empty(prop_type_get('CodeiumFlash'))
call prop_type_add('CodeiumFlash', {'highlight': 'CodeiumFlash'})
endif
endif
endfunction
function! s:MapTab() abort
if !get(g:, 'codeium_no_map_tab', v:false) && !get(g:, 'codeium_disable_bindings')
imap <script><silent><nowait><expr> <Tab> codeium#Accept()
endif
endfunction
augroup codeium
autocmd!
autocmd InsertEnter,CursorMovedI,CompleteChanged * call codeium#DebouncedComplete()
autocmd BufEnter * if codeium#Enabled()|call codeium#command#StartLanguageServer()|endif
autocmd BufEnter * if mode() =~# '^[iR]'|call codeium#DebouncedComplete()|endif
autocmd InsertLeave * call codeium#Clear()
autocmd BufLeave * if mode() =~# '^[iR]'|call codeium#Clear()|endif
autocmd ColorScheme,VimEnter * call s:SetStyle()
" Map tab using vim enter so it occurs after all other sourcing.
autocmd VimEnter * call s:MapTab()
autocmd VimLeave * call codeium#ServerLeave()
augroup END
imap <Plug>(codeium-dismiss) <Cmd>call codeium#Clear()<CR>
imap <Plug>(codeium-next) <Cmd>call codeium#CycleCompletions(1)<CR>
imap <Plug>(codeium-next-or-complete) <Cmd>call codeium#CycleOrComplete()<CR>
imap <Plug>(codeium-previous) <Cmd>call codeium#CycleCompletions(-1)<CR>
imap <Plug>(codeium-complete) <Cmd>call codeium#Complete()<CR>
if !get(g:, 'codeium_disable_bindings')
if empty(mapcheck('<C-]>', 'i'))
imap <silent><script><nowait><expr> <C-]> codeium#Clear() . "\<C-]>"
endif
if empty(mapcheck('<M-]>', 'i'))
imap <M-]> <Plug>(codeium-next-or-complete)
endif
if empty(mapcheck('<M-[>', 'i'))
imap <M-[> <Plug>(codeium-previous)
endif
if empty(mapcheck('<M-Bslash>', 'i'))
imap <M-Bslash> <Plug>(codeium-complete)
endif
if empty(mapcheck('<C-k>', 'i'))
imap <script><silent><nowait><expr> <C-k> codeium#AcceptNextWord()
endif
if empty(mapcheck('<C-l>', 'i'))
imap <script><silent><nowait><expr> <C-l> codeium#AcceptNextLine()
endif
endif
call s:SetStyle()
let s:dir = expand('<sfile>:h:h')
if getftime(s:dir . '/doc/codeium.txt') > getftime(s:dir . '/doc/tags')
silent! execute 'helptags' fnameescape(s:dir . '/doc')
endif
function! CodeiumEnable() " Enable Codeium if it is disabled
let g:codeium_enabled = v:true
call codeium#command#StartLanguageServer()
endfun
command! CodeiumEnable :silent! call CodeiumEnable()
function! CodeiumDisable() " Disable Codeium altogether
let g:codeium_enabled = v:false
endfun
command! CodeiumDisable :silent! call CodeiumDisable()
function! CodeiumToggle()
if exists('g:codeium_enabled') && g:codeium_enabled == v:false
call CodeiumEnable()
else
call CodeiumDisable()
endif
endfunction
command! CodeiumToggle :silent! call CodeiumToggle()
function! CodeiumManual() " Disable the automatic triggering of completions
let g:codeium_manual = v:true
endfun
command! CodeiumManual :silent! call CodeiumManual()
function! CodeiumAuto() " Enable the automatic triggering of completions
let g:codeium_manual = v:false
endfun
command! CodeiumAuto :silent! call CodeiumAuto()
function! CodeiumChat()
call codeium#Chat()
endfun
command! CodeiumChat :silent! call CodeiumChat()
:amenu Plugin.Codeium.Enable\ \Codeium\ \(\:CodeiumEnable\) :call CodeiumEnable() <Esc>
:amenu Plugin.Codeium.Disable\ \Codeium\ \(\:CodeiumDisable\) :call CodeiumDisable() <Esc>
:amenu Plugin.Codeium.Manual\ \Codeium\ \AI\ \Autocompletion\ \(\:CodeiumManual\) :call CodeiumManual() <Esc>
:amenu Plugin.Codeium.Automatic\ \Codeium\ \AI\ \Completion\ \(\:CodeiumAuto\) :call CodeiumAuto() <Esc>
:amenu Plugin.Codeium.Toggle\ \Codeium\ \(\:CodeiumToggle\) :call CodeiumToggle() <Esc>
:amenu Plugin.Codeium.Chat\ \Codeium\ \(\:CodeiumChat\) :call CodeiumChat() <Esc>