This is a plugin for neovim that helps you contextual code used for AI prompts.
context-nvim allows you to manage two types of contexts:
- Manual Contexts: These are contexts that you manually define and manage. You can add, remove, and edit these contexts with
context-nvimsubcommands. - History Contexts: These are contexts that are automatically generated by
context-nvimbased on buffers you have opened recently.
- Telescope picker for viewing / deleting manual contexts
- Telescope picker for viewing / deleting history contexts
- subcommands for managing manual contexts
nvim-cmpsource for referencing history-based and manual contexts in your AI prompts
Using lazy.nvim:
{
"napisani/context-nvim",
config = function()
require("context_nvim").setup({ })
end,
},
require("context_nvim").setup({
enable_history = true, -- whether to enable history context by tracking opened files/buffers
history_length = 10, -- how many history items to track
history_for_files_only = true, -- only use history for files, any non-file buffers will be ignored
history_pattern = "*", -- history pattern to match files/buffers that will be tracked
root_dir = ".", -- root directory of the project, used for finding files and constructing paths
cmp = {
enable = true, -- whether to enable the nvim-cmp source for referencing contexts
manual_context_keyword = "@manual_context", -- keyword to use for manual context
history_keyword = "@history_context", -- keyword to use for history context
},
telescope = {
enable = true, -- whether to enable the telescope picker
},
logger = {
level = "error", -- log level for the plenary logger
},
lsp = {
ignore_sources = {}, -- lsp sources to ignore when adding line diagnostics to the manual context
},
})Adds the current file to the manual context.
:ContextNvim add_current_file
Adds the current visual selection or buffer to the manual context.
:ContextNvim add_current
Adds all items from the quickfix list to the manual context.
:ContextNvim add_qflist
Clears the history context.
:ContextNvim clear_history
Clears the manual context.
:ContextNvim clear_manual
Opens a Telescope picker to select and add a directory to the manual context.
:ContextNvim add_dir
Opens a Telescope picker to select and add a file to the manual context.
:ContextNvim add_file
Opens a Telescope picker to view and manage the history context.
:ContextNvim find_context_history
Opens a Telescope picker to view and manage the manual context.
:ContextNvim find_context_manual
Adds context for LSP line diagnostics to the manual context.
:ContextNvim add_line_lsp_daig
- Open a file in neovim
- Perform one or many of the following actions:
- Add the current file to the manual context
- Add the current visual selection to the manual context
- Add the current buffer to the manual context
- Add the quickfix list to the manual context
- Add a directory to the manual context
- Add a file to the manual context
- Add line diagnostics to the manual context
- Open
gp.nvimor another AI prompt plugin that supports chatting with an AI model - start to type
@manual_context(or@history_context) - Accept the cmp suggestion to insert the manual context into the chat
- finish writing your prompt and send it to the AI model
- Profit?
