This guide provides step-by-step instructions to set up Neovim as a Solidity development environment using the VSCode-Solidity Language Server.
Download and install Neovim from:
sudo apt install neovim # Ubuntu/Debian
brew install neovim # macOS
Verify installation:
nvim --version
Ensure you have Node.js installed:
node -v
If not installed, get it from:
For Linux/macOS:
curl -fsSL https://fnm.vercel.app/install | bash
fnm install 18
Run the following command in PowerShell or Command Prompt:
git clone --depth 1 https://github.com/wbthomason/packer.nvim ^
%LOCALAPPDATA%\nvim-data\site\pack\packer\start\packer.nvim
Create the Neovim configuration directory if it doesn't exist:
mkdir %USERPROFILE%\AppData\Local\nvim\lua
Create and open init.lua
:
nvim %USERPROFILE%\AppData\Local\nvim\init.lua
Paste the following setup:
-- Ensure packer is installed
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
vim.cmd('!git clone --depth 1 https://github.com/wbthomason/packer.nvim '..install_path)
vim.cmd('packadd packer.nvim')
return true
end
return false
end
ensure_packer()
-- Install plugins
require('packer').startup(function(use)
use 'wbthomason/packer.nvim' -- Plugin manager
use 'neovim/nvim-lspconfig' -- LSP support
use 'hrsh7th/nvim-cmp' -- Autocompletion
use 'hrsh7th/cmp-nvim-lsp' -- LSP completion source
use 'williamboman/mason.nvim' -- LSP manager
end)
-- Setup Solidity LSP
local lspconfig = require('lspconfig')
local lspconfig = require('lspconfig')
lspconfig.solidity_ls.setup{
cmd = { "vscode-solidity-server", "--stdio" },
filetypes = { "solidity" },
root_dir = lspconfig.util.root_pattern("hardhat.config.js", "foundry.toml", ".git"),
settings = {
solidity = {
compileUsingRemoteVersion = 'latest',
defaultCompiler = 'remote',
enabledAsYouTypeCompilationErrorCheck = true,
},
}
}
Or Local debug etc
lspconfig.solidity_ls.setup{
cmd = {
"node",
"--inspect-brk=9229",
"(%PATH%)vscode-solidity/out/src/server.js",
"--stdio"
},
filetypes = {"solidity"},
root_dir = lspconfig.util.root_pattern("foundry.toml", "hardhat.config.js", ".git"),
settings = {
solidity = {
compileUsingRemoteVersion = 'latest',
defaultCompiler = 'remote',
enabledAsYouTypeCompilationErrorCheck = true,
},
}
}
Save the file and exit Neovim.
Open Neovim and run:
:PackerSync
nvim test.sol
:LspInfo
You should see solidity_ls
running.
Start typing a Solidity function or keyword and press:
<C-Space>
:LspRestart
Command | Action |
---|---|
gd |
Go to definition |
gr |
Find references |
K |
Show documentation |
<C-Space> |
Trigger autocomplete |
:LspInfo |
Show LSP status |
:LspRestart |
Restart LSP |
If LSP is not working, check logs:
:lua print(vim.inspect(vim.lsp.get_active_clients()))
Or manually start the Solidity LSP:
node --inspect-brk=9229 (PATH)vscode-solidity/out/src/server.js --stdio