|
1 | 1 | # vim-solidity |
2 | 2 |
|
3 | | -Maintained syntax files for [Solidity](https://github.com/ethereum/solidity), |
4 | | -the smart contract programming language for Ethereum. |
| 3 | +[](https://github.com/thesis/vim-solidity/tags) |
| 4 | +[](LICENSE) |
| 5 | +[](https://github.com/thesis/vim-solidity/actions/workflows/test.yml) |
| 6 | + |
| 7 | +**The actively maintained Solidity plugin for Vim.** |
| 8 | + |
| 9 | +Comprehensive syntax highlighting, indentation, and code folding for [Solidity](https://soliditylang.org/), the smart contract programming language for Ethereum. Supports Solidity 0.8.x with all modern language features. |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- ✅ **Modern Solidity 0.8.x support**: All keywords through Solidity 0.8.24 |
| 14 | + - `transient` storage (0.8.24+) |
| 15 | + - `unchecked` blocks (0.8.0+) |
| 16 | + - Custom `error` declarations (0.8.4+) |
| 17 | + - User-defined value types (`type Foo is uint256`, 0.8.18+) |
| 18 | + - `using ... global` syntax (0.8.19+) |
| 19 | + - `fallback()` and `receive()` functions |
| 20 | +- ✅ **Smart indentation**: Context-aware indentation for functions, contracts, and blocks |
| 21 | +- ✅ **Code folding**: Fold contracts, functions, and assembly blocks |
| 22 | +- ✅ **NatSpec support**: Syntax highlighting for `@param`, `@return`, `@notice`, etc. |
| 23 | +- ✅ **Yul/Assembly**: Full Yul opcode highlighting with proper scoping |
| 24 | +- ✅ **Foundry integration**: Automatic detection of `.t.sol` and `.s.sol` files |
| 25 | +- ✅ **Pure Vim**: No external dependencies, works in Vim 8.0+ and Neovim |
5 | 26 |
|
6 | 27 | ## Installation |
7 | 28 |
|
8 | | -### Pathogen |
9 | | -Run the following command: |
| 29 | +### vim-plug |
10 | 30 |
|
11 | | -```bash |
12 | | -git clone https://github.com/thesis/vim-solidity.git ~/.vim/bundle/vim-solidity |
| 31 | +Add to your `~/.vimrc` or `~/.config/nvim/init.vim`: |
| 32 | + |
| 33 | +```vim |
| 34 | +Plug 'thesis/vim-solidity', { 'branch': 'main' } |
13 | 35 | ``` |
14 | 36 |
|
| 37 | +Then run `:PlugInstall` |
| 38 | + |
15 | 39 | ### Vundle |
16 | | -Add the following line to your `~/.vimrc`: |
| 40 | + |
| 41 | +Add to your `~/.vimrc`: |
17 | 42 |
|
18 | 43 | ```vim |
19 | 44 | Plugin 'thesis/vim-solidity' |
20 | 45 | ``` |
21 | 46 |
|
22 | | -### Plug |
23 | | -Add the following line to your `~/.vimrc`: |
| 47 | +Then run `:PluginInstall` |
24 | 48 |
|
25 | | -```vim |
26 | | -Plug 'thesis/vim-solidity', {'branch': 'main' } |
| 49 | +### Pathogen |
| 50 | + |
| 51 | +```bash |
| 52 | +git clone https://github.com/thesis/vim-solidity.git ~/.vim/bundle/vim-solidity |
27 | 53 | ``` |
28 | 54 |
|
29 | | -### No Plugin Manager |
| 55 | +### Native Vim Packages (Vim 8+) |
30 | 56 |
|
31 | | -Copy all of the files manually into your `~/.vim`. |
| 57 | +```bash |
| 58 | +mkdir -p ~/.vim/pack/plugins/start |
| 59 | +git clone https://github.com/thesis/vim-solidity.git ~/.vim/pack/plugins/start/vim-solidity |
| 60 | +``` |
| 61 | + |
| 62 | +### Neovim with lazy.nvim |
| 63 | + |
| 64 | +```lua |
| 65 | +{ |
| 66 | + 'thesis/vim-solidity', |
| 67 | + branch = 'main', |
| 68 | + ft = 'solidity', |
| 69 | +} |
| 70 | +``` |
32 | 71 |
|
33 | 72 | ## Configuration |
34 | 73 |
|
| 74 | +### Enable Code Folding |
| 75 | + |
| 76 | +Add to your `~/.vimrc`: |
| 77 | + |
35 | 78 | ```vim |
36 | 79 | augroup solidity_folding |
37 | 80 | au! |
38 | 81 | au FileType solidity setlocal foldmethod=syntax |
39 | 82 | augroup END |
40 | 83 | ``` |
41 | 84 |
|
42 | | -Will enable Solidity code-folding based on the included syntax file. This might |
43 | | -have an impact on editing performance. |
| 85 | +**Usage:** |
| 86 | +- `zc` - Close fold under cursor |
| 87 | +- `zo` - Open fold under cursor |
| 88 | +- `zM` - Close all folds |
| 89 | +- `zR` - Open all folds |
| 90 | + |
| 91 | +### Comment Toggling |
| 92 | + |
| 93 | +vim-solidity works with [vim-commentary](https://github.com/tpope/vim-commentary): |
| 94 | + |
| 95 | +```vim |
| 96 | +Plug 'tpope/vim-commentary' |
| 97 | +``` |
| 98 | + |
| 99 | +**Usage:** |
| 100 | +- `gcc` - Toggle comment on current line |
| 101 | +- `gc` in visual mode - Toggle comment on selection |
| 102 | + |
| 103 | +### Matchit Support |
| 104 | + |
| 105 | +Enable `%` jumping between Solidity constructs: |
| 106 | + |
| 107 | +```vim |
| 108 | +" In your .vimrc |
| 109 | +runtime macros/matchit.vim |
| 110 | +``` |
| 111 | + |
| 112 | +**Supported matches:** |
| 113 | +- `contract` ↔ `}` |
| 114 | +- `function` ↔ `}` |
| 115 | +- `if` ↔ `else` |
| 116 | +- `try` ↔ `catch` |
| 117 | +- `assembly` ↔ `}` |
| 118 | + |
| 119 | +## Advanced Features |
| 120 | + |
| 121 | +### Foundry Workflow |
| 122 | + |
| 123 | +vim-solidity detects Foundry projects automatically: |
| 124 | + |
| 125 | +- `.t.sol` files → Test files |
| 126 | +- `.s.sol` files → Script files |
| 127 | +- Regular `.sol` files → Contract files |
| 128 | + |
| 129 | +A buffer-local variable `b:solidity_file_type` is set to `'test'`, `'script'`, or `'contract'`. |
| 130 | + |
| 131 | +### Syntax Highlighting |
| 132 | + |
| 133 | +All modern Solidity features are highlighted: |
| 134 | + |
| 135 | +```solidity |
| 136 | +// Custom errors (0.8.4+) |
| 137 | +error InsufficientBalance(uint256 available, uint256 required); |
| 138 | +
|
| 139 | +// User-defined value types (0.8.18+) |
| 140 | +type UFixed256x18 is uint256; |
| 141 | +
|
| 142 | +// Using global (0.8.19+) |
| 143 | +using SafeMath for uint256 global; |
| 144 | +
|
| 145 | +// Transient storage (0.8.24+) |
| 146 | +contract Example { |
| 147 | + transient uint256 temporaryValue; |
| 148 | +
|
| 149 | + // Unchecked arithmetic (0.8.0+) |
| 150 | + function increment(uint256 x) public pure returns (uint256) { |
| 151 | + unchecked { |
| 152 | + return x + 1; |
| 153 | + } |
| 154 | + } |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +### NatSpec Comments |
| 159 | + |
| 160 | +Full support for Solidity's documentation format: |
| 161 | + |
| 162 | +```solidity |
| 163 | +/// @title A title |
| 164 | +/// @author The author name |
| 165 | +/// @notice Explain to end users what this does |
| 166 | +/// @dev Explain to developers the extra details |
| 167 | +/// @param x Description of parameter x |
| 168 | +/// @return Description of return value |
| 169 | +function example(uint256 x) public returns (uint256) { |
| 170 | + return x * 2; |
| 171 | +} |
| 172 | +``` |
| 173 | + |
| 174 | +### Yul/Assembly |
| 175 | + |
| 176 | +Assembly blocks have proper syntax highlighting with scoped opcodes: |
| 177 | + |
| 178 | +```solidity |
| 179 | +function getCodeSize(address addr) public view returns (uint256 size) { |
| 180 | + assembly { |
| 181 | + size := extcodesize(addr) |
| 182 | + } |
| 183 | +} |
| 184 | +``` |
| 185 | + |
| 186 | +## Compatibility |
| 187 | + |
| 188 | +- **Vim**: 8.0 or later |
| 189 | +- **Neovim**: Fully compatible |
| 190 | +- **Solidity**: 0.8.0 through 0.8.24+ (backward compatible with 0.7.x) |
| 191 | + |
| 192 | +## Known Limitations |
| 193 | + |
| 194 | +This is a **pure Vim plugin** focused on syntax, indentation, and folding. It does not provide: |
| 195 | + |
| 196 | +- **Language Server Protocol (LSP)** features (go-to-definition, hover, rename) |
| 197 | +- **Linting** (use [ALE](https://github.com/dense-analysis/ale) or [Syntastic](https://github.com/vim-syntastic/syntastic)) |
| 198 | +- **Code completion** (use LSP or [YouCompleteMe](https://github.com/ycm-core/YouCompleteMe)) |
| 199 | +- **Compiler integration** (planned for future release) |
| 200 | + |
| 201 | +For full IDE features, you can set up an LSP client ([coc.nvim](https://github.com/neoclide/coc.nvim), [vim-lsp](https://github.com/prabirshrestha/vim-lsp), or native Neovim LSP) with a Solidity language server like [nomicfoundation/solidity-language-server](https://github.com/NomicFoundation/hardhat-vscode/tree/development/server). |
| 202 | + |
| 203 | +## Comparison with Other Plugins |
| 204 | + |
| 205 | +| Feature | vim-solidity (this) | tomlion/vim-solidity | |
| 206 | +|---------|---------------------|----------------------| |
| 207 | +| Actively maintained | ✅ Yes | ❌ Abandoned (5+ years) | |
| 208 | +| Vim support | ✅ Yes | ✅ Yes | |
| 209 | +| Neovim support | ✅ Yes | ✅ Yes | |
| 210 | +| Solidity 0.8.x | ✅ Yes | ❌ Partial | |
| 211 | +| Pure Vim | ✅ Yes | ✅ Yes | |
| 212 | + |
| 213 | +**Use vim-solidity if:** |
| 214 | +- You want actively maintained Solidity syntax support |
| 215 | +- You need modern Solidity 0.8.x features |
| 216 | +- You prefer a simple, dependency-free plugin |
| 217 | +- You work on remote servers via SSH |
| 218 | +- You want syntax highlighting and code folding that "just works" |
| 219 | + |
| 220 | +**For LSP features:** |
| 221 | + |
| 222 | +If you need go-to-definition, hover, rename, and other IDE features: |
| 223 | +- Set up an LSP client ([coc.nvim](https://github.com/neoclide/coc.nvim), [vim-lsp](https://github.com/prabirshrestha/vim-lsp), or native Neovim LSP) |
| 224 | +- Use a Solidity language server like [nomicfoundation/solidity-language-server](https://github.com/NomicFoundation/hardhat-vscode/tree/development/server) |
| 225 | +- vim-solidity works alongside LSP for syntax highlighting |
| 226 | + |
| 227 | +## Troubleshooting |
| 228 | + |
| 229 | +### Colors look wrong |
| 230 | + |
| 231 | +Your colorscheme may not define Solidity-specific groups. Try a different colorscheme or customize: |
| 232 | + |
| 233 | +```vim |
| 234 | +" In your .vimrc |
| 235 | +hi link solKeyword Statement |
| 236 | +hi link solBuiltinType Type |
| 237 | +hi link solConstant Constant |
| 238 | +``` |
| 239 | + |
| 240 | +### Indentation is incorrect |
| 241 | + |
| 242 | +The indentation logic is based on JavaScript. For complex cases, you may need to manually adjust with `>>` and `<<`. |
| 243 | + |
| 244 | +Please report persistent indentation issues with a minimal example. |
| 245 | + |
| 246 | +### Folding doesn't work |
| 247 | + |
| 248 | +Make sure you've set `foldmethod`: |
| 249 | + |
| 250 | +```vim |
| 251 | +:set foldmethod=syntax |
| 252 | +``` |
| 253 | + |
| 254 | +If folding is slow, try: |
| 255 | + |
| 256 | +```vim |
| 257 | +:set foldmethod=indent |
| 258 | +``` |
| 259 | + |
| 260 | +## Contributing |
| 261 | + |
| 262 | +Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
| 263 | + |
| 264 | +### Development Setup |
| 265 | + |
| 266 | +```bash |
| 267 | +# Clone vader.vim for testing |
| 268 | +git clone https://github.com/junegunn/vader.vim.git test/vader.vim |
| 269 | + |
| 270 | +# Run tests |
| 271 | +vim -Nu test/vimrc -c 'Vader! test/vader/*.vader' |
| 272 | +``` |
| 273 | + |
| 274 | +### Reporting Issues |
| 275 | + |
| 276 | +Before opening an issue: |
| 277 | +1. Check existing issues for duplicates |
| 278 | +2. Test with a minimal `.vimrc` |
| 279 | +3. Provide a minimal Solidity example |
| 280 | +4. Include your Vim version and OS |
| 281 | + |
| 282 | +Use our [issue templates](https://github.com/thesis/vim-solidity/issues/new/choose). |
| 283 | + |
| 284 | +## Related Projects |
| 285 | + |
| 286 | +- [Foundry](https://github.com/foundry-rs/foundry) - Ethereum development toolkit |
| 287 | +- [solc](https://github.com/ethereum/solidity) - The Solidity compiler |
| 288 | +- [Hardhat VSCode](https://github.com/NomicFoundation/hardhat-vscode) - Official Solidity LSP implementation |
| 289 | +- [coc.nvim](https://github.com/neoclide/coc.nvim) - LSP client for Vim/Neovim |
| 290 | +- [vim-lsp](https://github.com/prabirshrestha/vim-lsp) - Async LSP client for Vim |
| 291 | + |
| 292 | +## History |
| 293 | + |
| 294 | +This plugin is a maintained fork of [tomlion/vim-solidity](https://github.com/tomlion/vim-solidity), which has been inactive since 2018. It incorporates improvements from the Ethereum Foundation's fork and adds modern Solidity 0.8.x support. |
| 295 | + |
| 296 | +## License |
| 297 | + |
| 298 | +MIT License - see [LICENSE](LICENSE) for details. |
| 299 | + |
| 300 | +## Maintainers |
| 301 | + |
| 302 | +- [Thesis](https://github.com/thesis) |
| 303 | + |
| 304 | +--- |
| 305 | + |
| 306 | +**⭐ If you find vim-solidity useful, please star the repository!** |
| 307 | + |
| 308 | +Built with ❤️ for the Solidity and Vim communities. |
0 commit comments