Editor Setup
Configure your editor for Solidity syntax highlighting, formatting, and Foundry integration.
VS Code
Recommended extensions
| Extension | Purpose |
|---|---|
| Solidity by Nomic Foundation | Syntax highlighting, diagnostics, code completion |
| Even Better TOML | foundry.toml syntax highlighting |
Configure format on save
Add to your VS Code settings (.vscode/settings.json):
{
"[solidity]": {
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity",
"editor.formatOnSave": true
}
}To use forge fmt instead, configure the Solidity extension to use Foundry's formatter:
{
"solidity.formatter": "forge"
}Generate remappings for IDE support
Create a remappings.txt file so your editor can resolve imports:
$ forge remappings > remappings.txtThe Solidity extension reads this file to resolve import paths.
Recommended workspace settings
Create .vscode/settings.json in your project:
{
"[solidity]": {
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity",
"editor.formatOnSave": true
},
"solidity.formatter": "forge",
"solidity.packageDefaultDependenciesContractsDirectory": "src",
"solidity.packageDefaultDependenciesDirectory": "lib"
}Vim / Neovim
Syntax highlighting
Use vim-solidity for syntax highlighting:
Plug 'tomlion/vim-solidity'LSP support with Neovim
For Neovim with nvim-lspconfig, configure the Solidity language server:
require('lspconfig').solidity_ls.setup({
root_dir = require('lspconfig.util').root_pattern('foundry.toml', '.git'),
})Format with forge fmt
Create a command to format the current file:
command! ForgeFmt !forge fmt %Or set up autoformatting on save:
autocmd BufWritePost *.sol silent! !forge fmt %JetBrains IDEs
IntelliJ IDEA / WebStorm
Install the Solidity plugin for syntax highlighting and basic support.
Configure external tools for Foundry commands:
-
Go to Settings → Tools → External Tools
-
Add a new tool:
- Name: Forge Build
- Program:
forge - Arguments:
build - Working directory:
$ProjectFileDir$
-
Repeat for other commands (
forge test,forge fmt)
Format on save
Use the File Watchers plugin to run forge fmt on save:
- Install the File Watchers plugin
- Go to Settings → Tools → File Watchers
- Add a new watcher:
- File type: Solidity
- Program:
forge - Arguments:
fmt $FilePath$ - Output paths to refresh:
$FilePath$
Emacs
Use solidity-mode:
(use-package solidity-mode
:ensure t
:mode "\\.sol\\'")Configure forge fmt as the formatter:
(defun forge-fmt ()
"Format current buffer with forge fmt."
(interactive)
(shell-command (format "forge fmt %s" (buffer-file-name)))
(revert-buffer t t t))
(add-hook 'solidity-mode-hook
(lambda ()
(add-hook 'before-save-hook #'forge-fmt nil t)))Shell completions
Generate shell completions for Foundry commands:
# Add to ~/.bashrc
$ eval "$(forge completions bash)"
$ eval "$(cast completions bash)"
$ eval "$(anvil completions bash)"After adding completions, restart your shell or source your config file.
Was this helpful?
