Install Cody for Neovim

Learn how to use Cody and its features with the Neovim editor.

Cody for Neovim is currently in the experimental stage and is no longer actively maintained, so support will be limited.

The Cody extension for Neovim by Sourcegraph enhances your coding experience in your IDE by providing intelligent code suggestions, context-aware completions, and advanced code analysis.

This guide will walk you through installing and setting up the Cody within your Neovim environment.

Cody for Neovim

Neovim Extension (Experimental)

Install Cody's free extension for Neovim.

Prerequisites

Installation

sg.nvim is a plugin that uses Sourcegraph's code intelligence features directly within the Neovim text editor. You can install the plugin using different Neovim plugin managers like:

lazy.nvim

LUA
return { { "sourcegraph/sg.nvim", dependencies = { "nvim-lua/plenary.nvim" }, -- If you have a recent version of lazy.nvim, you don't need to add this! build = "nvim -l build/init.lua", }, }

packer.nvim

LUA
-- Packer.nvim, also make sure to install nvim-lua/plenary.nvim use { 'sourcegraph/sg.nvim', run = 'nvim -l build/init.lua' }

vim-plug

LUA
-- Using vim-plug Plug 'sourcegraph/sg.nvim', { 'do': 'nvim -l build/init.lua' }

Once you have installed the plugin, run :checkhealth sg to verify a successful installation. Next, you are prompted to log in as a free user by connecting to your Sourcegraph.com account or using the enterprise instance.

Setting up with Sourcegraph instance

To connect sg.nvim with Sourcegraph, you need to follow these steps:

  • Log in on your Sourcegraph instance
  • Go to Settings > Access tokens from the top right corner
  • Create your access token, and then run :SourcegraphLogin in your neovim editor after installation
  • Type in the link to your Sourcegraph instance (for example, https://sourcegraph.com)
  • Next, paste your generated access token

An alternative way to this is to use the environment variables specified for src-cli.

At any point, you can run :checkhealth sg to ensure you're logged in and connected to your Sourcegraph instance.

Features

The sg.nvim plugin supports a wide range of features that helps you integrate and use Cody and Sourcegraph Search directly within your Neovim environment.

Cody

The sg.nvim extension supports the following features for Cody:

FeatureDescription
ChatChat interface and associated commands
AutocompletionsSupport both prompted and suggested autocompletions

The sg.nvim extension supports the following features for Sourcegraph Search:

FeatureDescription
Read filesDirectly from sourcegraph links: :edit <sourcegraph url>
Automatically adds protocols for https://sourcegraph.com/* links
Directly from buffer names :edit sg://github.com/tjdevries/sam.py/-/src/sam.py
Read non-filesRepository roots, folders (both expanded and non-expanded), open file from folder
Built-in LSP clientConnects to Sourcegraph via Goto Definition and Goto References (less than 20 references)
Basic searchKeyword and regexp support, type:symbol support, and repo support
Advanced search featuresAutocompletions and memory of last searches

Commands

The sg.nvim extension also supports pre-built reusable prompts for Cody called "Commands" that help you quickly get started with common programming tasks like:

  • :CodyAsk: Ask a question about the current selection
  • :CodyChat {title}: Starts a new Cody chat, with an optional {title}
  • :CodyRestart: Restarts Cody and Sourcegraph
  • :CodyTask {task_description}: Instructs Cody to perform a task on a selected text
  • :CodyTaskAccept: Accepts the current CodyTask
  • :CodyTaskNext: Cycles to the next CodyTask
  • :CodyTaskPrev: Cycles to the previous CodyTask
  • :CodyTaskView: Opens the last active CodyTask
  • :CodyToggle: Toggle to the current Cody Chat window