๐คSimpleGPT is a Vim plugin designed to provide a simple yet flexible way to:
Though we have a lot of ChatGPT plugins to leverage the power of ChatGPT in Vim, I still find it hard to locate a handy one that completely fits my workflow.
After thinking about it, I found that the main reason is that the most important part of my workflow is missing in existing plugins: Fast editing of questions based on my current status!!
So, quickly editing the question template and building the question is the most important part of my workflow. Existing plugins are not convenient enough for this and focus more on the Chat UI.
This repository is designed to offer a highly customizable and extensible QA interaction with ChatGPT in the simplest way possible.
โ ๏ธPlease follow the installation guide of ChatGPT.nvim to make sure your ChatGPT works.
-- Lazy.nvim
{
"you-n-g/simplegpt.nvim",
dependencies = {
{
"jackMort/ChatGPT.nvim", -- You should configure your ChatGPT make sure it works.
event = "VeryLazy",
config = true,
dependencies = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
"folke/trouble.nvim",
"nvim-telescope/telescope.nvim",
},
},
},
config = true,
},
-- or packer.nvim
use({
"you-n-g/simplegpt.nvim",
config = function()
require("simplegpt").setup()
end,
requires = {
{
"jackMort/ChatGPT.nvim", -- You should configure your ChatGPT make sure it works.
event = "VimEnter",
config = function()
require("chatgpt").setup()
end,
requires = {
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
"folke/trouble.nvim",
"nvim-telescope/telescope.nvim",
},
},
},
})
If you want to customize you <LocalLeader>
, please use following code:
vim.g.maplocalleader = "\\" -- change the localleader key to \
More detailed configuration are listed here. You can find my latest and preferred configuration here as an example.
I have attempted to summarize the key concepts and manual in one image.
The question is constructed by rendering a template. The 't' register serves as the template, encompassing:
{{content}}
, {{filetype}}
, and {{visual}}
.{{a}}
, {{b}}
, and {{c}}
.The primary concepts that govern the functionality of this plugin are:
Register-based, template-driven question construction: This approach allows for the dynamic creation of questions by leveraging the power of Vim registers. The registers serve as placeholders within the template, which are then replaced with the appropriate content during the question construction process.
Dumping and loading of registers: This feature enables the preservation of register content across different sessions. It's important to note that temporary registers, denoted by {{p-}}
, are exempt from this process and their content is not saved to disk.
Response display targets: This refers to the destination where the response from ChatGPT is displayed. The plugin offers flexibility in choosing the target, allowing for a more tailored user experience.
To illustrate the core template rendering mechanism of SimpleGPT, consider the following example. We have a template in the 't' register:
"I am currently working on a {{filetype}} file. The content of the file is: {{content}}. I have selected the following lines: {{visual}}. My question is: {{q}}."
The register values are:
{{filetype}}
is 'markdown'{{content}}
is 'This is a sample markdown file.'{{visual}}
is 'This is a selected.'{{q}}
is 'How can I improve this line?'The constructed question becomes:
"I am currently working on a markdown file. The content of the file is: This is a sample markdown file. I have selected the following lines: This is a selected line. My question is: How can I improve this line?"
Registers are of two types:
{{content}}
, {{filetype}}
, {{visual}}
, and {{q}}
. They store special values used in the template process. The {{q}}
register allows for an editable question when rendering the whole content.Register | meaning |
---|---|
t | The register for the template. |
others | the variables to render the template |
key | meaning |
---|---|
content | the whole file content |
filetype | the filetype of the file |
visual | the selected lines |
context | the nearby context of the selected line(10 lines up & down) |
Dialog shortcuts:
{"q", "<C-c>", "<esc>"}
: exit the dialog;{"C-k"}
Copy code in triple backquotes of current buffer;ChatDialog
(The dialog that are able to get response){"C-a"}
: Append the response to current meeting.{"C-y"}
: Copy the full response to the clipboard.{"C-r"}
: Replace the selected visual text or current line.Normal shortcuts start with <LocalLeader>g
<LocalLeader>gl
: load registers<LocalLeader>gD
: dump registers<LocalLeader>ge
: edit registers<LocalLeader>gs
: send question to clipboard<LocalLeader>gc
: send question to ChatGPT<LocalLeader>gr
: send to get direct response<LocalLeader>gd
: send to get response with diff<LocalLeader>gR
: resume last popup<LocalLeader>gp
: load current file to reg<LocalLeader>gP
: append current file to regShortcuts for combined actions: Loading template + send to target
<LocalLeader>s
.<LocalLeader>sr
: (R)ewrite Text<LocalLeader>sc
: (C)omplete Code<LocalLeader>sg
: Fix (g)rammar<LocalLeader>sd
: Con(d)ense<LocalLeader>st
: Con(t)inueFlag explanation:
๐: high priority
TODOs
b:vimtex_main
in my config solve this problem.?
to see the help menu for shortcuts.---- Example focused part ----
def plus(a, b):
# TODO: plus them and return
---- Example output part ----
def plus(a, b):
return a + b
Bugs
<c-r>
in popup target.More features that may be added in the long future
Welcome to contribute to this project.
You can test the plugin with minimal config with
vim -u tests/init_configs/lazy.lua -U NONE -N -i NONE
for lazy.nvimvim -u tests/init_configs/packer.lua -U NONE -N -i NONE
ChatCompletion
API (which is the most powerful and frequently used in the future trend).