-
Notifications
You must be signed in to change notification settings - Fork 4
/
nvim-gpt.lua
42 lines (36 loc) · 1.54 KB
/
nvim-gpt.lua
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
local M = {}
local function add_default_keymaps()
vim.cmd [[
nnoremap <silent> <CR> <Cmd>GPT<CR>
vnoremap <silent> <CR> :GPTCode<CR>
nnoremap <silent> g<CR> <Cmd>GPTWrite<CR>
nnoremap <silent> @<CR> <Cmd>Telescope nvim-gpt gpt_template initial_mode=insert<CR>
nnoremap <silent> g@<CR> <Cmd>Telescope nvim-gpt gpt_history<CR>
vnoremap <silent> @<CR> :GPTCode<CR><Cmd>Telescope nvim-gpt gpt_template initial_mode=insert<CR>
vnoremap <silent> g@<CR> :GPTCode<CR><Cmd>Telescope nvim-gpt gpt_history<CR>
nnoremap <silent> gs<CR> <Cmd>exec ":GPT " . getline('.')<CR>
nnoremap <silent> gy<CR> <Cmd>exec ":GPT " . expand('<cword>')<CR>
nnoremap <silent> gu<CR> <Cmd>%GPTCode<CR>
nnoremap <silent> gsm<CR> <Cmd>Telescope nvim-gpt gpt_model<CR>
" to prevent this mapping interfere with quickfix selection:
" autocmd CmdwinEnter * nnoremap <CR> <CR>
" autocmd BufReadPost quickfix nnoremap <CR> <CR>
]]
end
function M.setup(opts)
if not opts.no_default_keymaps then
add_default_keymaps()
vim.cmd [[ autocmd VimLeave * GPTClose ]]
end
M._setup_options = opts
end
function M.get_model_list()
return vim.api.nvim_call_function('GPTModelList', {}) or vim.api.nvim_call_function('GPTModelList', {}) or {'none', {'none'}}
end
function M.get_prompt_history()
return vim.api.nvim_call_function('GPTPromptHistory', {}) or vim.api.nvim_call_function('GPTPromptHistory', {}) or {}
end
function M.get_template_list()
return vim.api.nvim_call_function('GPTTemplateList', {}) or vim.api.nvim_call_function('GPTTemplateList', {}) or {}
end
return M