In Neovim, the Quickfix List and Location List serve as powerful mechanisms for storing references to code locations (:h quickfix
). These lists can be populated through traditional commands (:make
, :vim
, :grep
), modern LSP functionality, or via plugin pickers like Telescope, fzf-lua, snacks.picker and others.
These code references—enhanced with additional diagnostic information when coming from LSP diagnostics—represent valuable context that can significantly improve interactions with Large Language Models.
ctx.nvim bridges this gap by converting Quickfix and Location List items into well-formatted Markdown, creating digestible context for LLMs. The plugin focuses solely on this conversion functionality, allowing it to complement any LLM integration workflow without introducing unnecessary dependencies.
- Neovim ≥ 0.10
You can install ctx.nvim using your preferred plugin manager. Here's an example configuration for lazy.nvim:
-- Using lazy.nvim
{
"S1M0N38/ctx.nvim",
version = "*",
opts = {},
keys = {
-- Add visual selection to Quickfix List
{
"<leader>q",
function()
local item = require("ctx.items").selection()
require("ctx.utils").highlight(item)
vim.fn.setqflist({ item }, "a")
end,
desc = "Add to Quickfix List",
mode = { "v" },
},
-- Add visual selection to Location List
{
"<leader>l",
function()
local win = vim.api.nvim_get_current_win()
local item = require("ctx.items").selection()
require("ctx.utils").highlight(item)
vim.fn.setloclist(win, { item }, "a")
end,
desc = "Add to Location List",
mode = { "v" },
},
-- There are other ways to send items to Quickfix / Location list.
-- For example, many pickers (telescope, fzf-lua, snacks.picker) can
-- send items to Quickfix / Location list.
-- Yank Quickfix List to clipboard register
{
"yq",
function()
local md = require("ctx").qflist_to_md()
vim.fn.setreg("+", md)
vim.notify("Yanked qflist")
end,
desc = "Yank Quickfix List",
},
-- Yank Location List to clipboard register
{
"yl",
function()
local nr = vim.api.nvim_get_current_win()
local md = require("ctx").loclist_to_md(nr)
vim.fn.setreg("+", md)
vim.notify("Yanked loclist")
end,
desc = "Yank Quickfix List",
},
-- Suggestions for Quickfix List navigation
{ "[q", vim.cmd.cprev, desc = "Previous Quickfix item" },
{ "]q", vim.cmd.cnext, desc = "Next Quickfix item" },
{ "[Q", vim.cmd.colder, desc = "Older Quickfix list" },
{ "]Q", vim.cmd.cnewer, desc = "Newer Quickfix list" },
-- Suggestions for Location List navigation
{ "[l", vim.cmd.lprev, desc = "Previous Location item" },
{ "]l", vim.cmd.lnext, desc = "Next Location item" },
{ "[L", vim.cmd.lolder, desc = "Older Location list" },
{ "]L", vim.cmd.lnewer, desc = "Newer Location list" },
}
}
To get started with ctx.nvim, read the documentation with :help ctx
. This will provide you with a comprehensive overview of the plugin's features and usage.
Note
Learning Vim/Neovim Documentation: Vim/Neovim plugins are usually shipped with :help documentation. Learning how to navigate it is a valuable skill. If you are not familiar with it, start with :help
and read the first 20 lines.
- tjdevries/vlog.nvim for logging.
- S1M0N38/base.nvim for template.