-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
162 lines (133 loc) · 5.18 KB
/
init.vim
File metadata and controls
162 lines (133 loc) · 5.18 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
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
" Add these to your .vimrc or init.vim
" Set path to the AI assistant script
let g:ai_assistant_path = expand('~/bin/vim-ai-assistant.py')
" Define available personas
let g:ai_personas = ['general', 'hemingway', 'formal', 'academic', 'creative']
let g:ai_current_persona = 'general'
" Function to get AI suggestions with persona
function! GetAISuggestions(mode, ...) abort
let l:filename = expand('%:p')
if empty(l:filename)
echo "Save the file first"
return
endif
" Get persona (optional argument or use current)
let l:persona = a:0 > 0 ? a:1 : g:ai_current_persona
" Save current file
silent write
" Call external script
let l:cmd = g:ai_assistant_path . ' "' . l:filename . '" --mode=' . a:mode . ' --persona=' . l:persona
let l:output = system(l:cmd)
if a:mode == 'inline'
" Load suggestions into quickfix list
let l:qf_entries = json_decode(l:output)
call setqflist(l:qf_entries)
copen
echo "Showing " . l:persona . " style suggestions"
else
" Open suggestions in a split
" Trim any whitespace from the output to get the clean filename
let l:file_path = substitute(l:output, '^\s*\(.\{-}\)\s*$', '\1', '')
if filereadable(l:file_path)
execute 'split ' . fnameescape(l:file_path)
setlocal readonly
else
echo "Error: Could not read suggestions file"
echo "Output was: " . l:output
endif
endif
endfunction
" Function to change current persona
function! ChangeAIPersona(persona) abort
if index(g:ai_personas, a:persona) >= 0
let g:ai_current_persona = a:persona
echo "AI persona changed to: " . a:persona
else
echo "Invalid persona. Available: " . join(g:ai_personas, ", ")
endif
endfunction
" Commands
command! -nargs=? AISuggest call GetAISuggestions('comments', <f-args>)
command! -nargs=? AIInline call GetAISuggestions('inline', <f-args>)
command! -nargs=? AISummary call GetAISuggestions('summary', <f-args>)
command! -nargs=1 -complete=customlist,AIPersonaComplete AIPersona call ChangeAIPersona(<q-args>)
" Command completion for personas
function! AIPersonaComplete(ArgLead, CmdLine, CursorPos)
return filter(copy(g:ai_personas), 'v:val =~ "^" . a:ArgLead')
endfunction
" Create commands for each persona
for persona in g:ai_personas
let capitalized_persona = toupper(persona[0]) . persona[1:]
execute 'command! ' . capitalized_persona . 'Suggest call GetAISuggestions("comments", "' . persona . '")'
execute 'command! ' . capitalized_persona . 'Inline call GetAISuggestions("inline", "' . persona . '")'
endfor
" Key mappings for default persona
nnoremap <Leader>as :AISuggest<CR>
nnoremap <Leader>ai :AIInline<CR>
nnoremap <Leader>au :AISummary<CR>
" Optional: Quick persona selection menu
function! AIPersonaMenu()
let l:choices = {}
let l:i = 1
for persona in g:ai_personas
let l:choices[l:i] = persona
let l:i += 1
endfor
echo "Select AI Persona:"
for [key, val] in items(l:choices)
echo key . ": " . val
endfor
let l:choice = input("Persona (1-" . len(l:choices) . "): ")
if has_key(l:choices, l:choice)
call ChangeAIPersona(l:choices[l:choice])
endif
endfunction
nnoremap <Leader>ap :call AIPersonaMenu()<CR>
" Optional: Add syntax highlighting for different personas in quickfix list
augroup AIPersonaSyntax
autocmd!
autocmd BufEnter quickfix call s:HighlightAIPersonas()
augroup END
" Function to get AI suggestions from all personas and combine them
function! GetAllPersonaSuggestions() abort
let l:filename = expand('%:p')
if empty(l:filename)
echo "Save the file first"
return
endif
" Save current file
silent write
" Initialize empty quickfix list
call setqflist([])
" Show progress
echo "Getting suggestions from all personas (this may take a while)..."
" Process each persona
for persona in g:ai_personas
echo "Processing " . persona . " suggestions..."
" Call external script with proper argument format
let l:cmd = g:ai_assistant_path . ' "' . l:filename . '" --mode inline --persona ' . persona
let l:output = system(l:cmd)
" Parse output and add to quickfix list
let l:qf_entries = json_decode(l:output)
call setqflist(l:qf_entries, 'a') " Append to the quickfix list
endfor
" Open the quickfix window
copen
echo "Showing combined suggestions from all personas"
endfunction
" Command for getting suggestions from all personas
command! AIAll call GetAllPersonaSuggestions()
function! s:HighlightAIPersonas()
syntax match qfPersonaHemingway /\[HEMINGWAY\].*/ contained
syntax match qfPersonaFormal /\[FORMAL\].*/ contained
syntax match qfPersonaAcademic /\[ACADEMIC\].*/ contained
syntax match qfPersonaCreative /\[CREATIVE\].*/ contained
syntax match qfPersonaGeneral /\[GENERAL\].*/ contained
highlight qfPersonaHemingway ctermfg=red guifg=#FF5555
highlight qfPersonaFormal ctermfg=yellow guifg=#FFAA55
highlight qfPersonaAcademic ctermfg=blue guifg=#5599FF
highlight qfPersonaCreative ctermfg=green guifg=#55DD55
highlight qfPersonaGeneral ctermfg=white guifg=#DDDDDD
syntax cluster qfPersonas contains=qfPersonaHemingway,qfPersonaFormal,qfPersonaAcademic,qfPersonaCreative,qfPersonaGeneral
syntax match qfLine /^.*/ contains=@qfPersonas
endfunction