Text converting operator via the OpenAI-compatible API (Chat Completions streaming).
Uses OpenAI's official endpoint by default. Set base_url to use any
OpenAI-compatible provider such as OpenRouter.
vim.fn["dein#add"]("vim-denops/denops.vim") -- required
vim.fn["dein#add"]("gw31415/denops-aioperator.nvim")
-- Configuration
vim.api.nvim_set_var('aioperator_opts', {
-- ↓These args configure the OpenAI-compatible request.
openai = {
api_key = "sk-********-****-****-****-************",
-- If `api_key` is not specified explicitly, the environment variable
-- `OPENAI_API_KEY` is used.
model = "gpt-4o-mini",
-- base_url = "https://api.openai.com/v1", -- default
},
-- scroll = false, -- Automatically scroll the window to the bottom. Default: true
})
-- Key mapping
vim.keymap.set({ "n", "x" }, "gG", function(arg)
return require 'aioperator'.opfunc(arg)
end, { expr = true })This plugin provides only the operator function require 'aioperator'.opfunc.
See :help operator for more information on how to use the operator.
- Press the operator key you set and select the textobj you want to convert.
- or, you can use the visual mode to select the text before pressing the operator key.
- Input the instruction about the conversion you want to make.
- Press Enter then the conversion result will be inserted.
To use OpenRouter, set base_url to the OpenRouter
endpoint and provide your OpenRouter API key:
vim.api.nvim_set_var('aioperator_opts', {
openai = {
api_key = "sk-or-v1-********************************", -- OpenRouter key
model = "openai/gpt-4o-mini", -- OpenRouter provider/model format
base_url = "https://openrouter.ai/api/v1",
},
})You can also set the key via environment variable:
export OPENAI_API_KEY="sk-or-v1-..."api_key— API key string. Falls back toOPENAI_API_KEYenv var.model— Model name. Defaults togpt-4o-mini. For OpenRouter, useprovider/modelformat (e.g.openai/gpt-4o-mini,anthropic/claude-3.5-sonnet).base_url— API endpoint base URL. Defaults tohttps://api.openai.com/v1. Set tohttps://openrouter.ai/api/v1for OpenRouter.seed— Optional integer seed for deterministic output.
- This plugin now uses Chat Completions streaming (SSE) instead of the OpenAI Realtime WebSocket API.
- The default model is
gpt-4o-mini(WebSocket-only models likegpt-realtime-miniare no longer used). g:aioperator_opts.openaisupports:api_keymodelbase_url(optional — enables OpenRouter or other compatible providers)seed(optional, integer)
- Removed WebSocket-specific options. Legacy keys (
apiKey,baseURL,organization,project,temperature) are not supported.
