Neovim OpenAI Codex, GitHub Copilot, and

Use OpenAI Codex in Neovim, and compare the suggestions with GitHub Copilot and

4 min readNov 27, 2021


Photo by Pankaj Patel on Unsplash

In a previous article, we walked through AI-assisted completion using Tabnine, GitHub Copilot, and OpenAI Codex.

In this article, let’s develop a Neovim plugin to try out OpenAI Codex, and compare the suggestions with GitHub Copilot and

OpenAI Codex

OpenAI Codex is an artificial intelligence model developed by OpenAI that can parse natural language and generate code in response.

A Lua Module for Codex

Instead of using a plugin like nvim-magic, let’s write a simple Lua module for Neovim.

Here is a full listing of the Lua module.

  • To use OpenAI Codex, you need to have the API key. API_KEY_FILE specifies the location of the file containing the API key.
  • There are 2 models available. The Davinci Codex is the most capable Codex model. It is particularly good at translating natural language to code. The Cushman Codex is almost as capable as Davinci Codex but slightly faster. This speed advantage may make it preferable for real-time applications. I configure the Davinci Codex using the OPENAI_URL variable.
  • MAX_TOKENS indicates the maximum number of tokens to return. Tokens can be words or just chunks of characters.
  • There are a number of parameters that can be configured like top_p, temperature, best_of, logprobs, etc. I am not going through each one of them but you can read the documentation and experiment with them.

Neovim Code Completion using Codex

Let’s try out code completion using Codex. To make it simple, I use the following key mappings.

vnoremap gz <Cmd>lua require("utils.codex").complete()<CR>




Software engineer, Data Science and ML practitioner.