Skip to content
Logo

Editor Setup

Configure your editor for Solidity syntax highlighting, formatting, and Foundry integration.

VS Code

ExtensionPurpose
Solidity by Nomic FoundationSyntax highlighting, diagnostics, code completion
Even Better TOMLfoundry.toml syntax highlighting

Configure format on save

Add to your VS Code settings (.vscode/settings.json):

.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:

.vscode/settings.json
{
  "solidity.formatter": "forge"
}

Generate remappings for IDE support

Create a remappings.txt file so your editor can resolve imports:

$ forge remappings > remappings.txt

The Solidity extension reads this file to resolve import paths.

Create .vscode/settings.json in your project:

.vscode/settings.json
{
  "[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:

  1. Go to Settings → Tools → External Tools

  2. Add a new tool:

    • Name: Forge Build
    • Program: forge
    • Arguments: build
    • Working directory: $ProjectFileDir$
  3. Repeat for other commands (forge test, forge fmt)

Format on save

Use the File Watchers plugin to run forge fmt on save:

  1. Install the File Watchers plugin
  2. Go to Settings → Tools → File Watchers
  3. 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.