Skip to content

thesis/vim-solidity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vim-solidity

Version License Test

The actively maintained Solidity plugin for Vim.

Comprehensive syntax highlighting, indentation, and code folding for Solidity, the smart contract programming language for Ethereum. Supports Solidity 0.8.x with all modern language features.

Features

  • Modern Solidity 0.8.x support: All keywords through Solidity 0.8.24
    • transient storage (0.8.24+)
    • unchecked blocks (0.8.0+)
    • Custom error declarations (0.8.4+)
    • User-defined value types (type Foo is uint256, 0.8.18+)
    • using ... global syntax (0.8.19+)
    • fallback() and receive() functions
  • Smart indentation: Context-aware indentation for functions, contracts, and blocks
  • Code folding: Fold contracts, functions, and assembly blocks
  • NatSpec support: Syntax highlighting for @param, @return, @notice, etc.
  • Yul/Assembly: Full Yul opcode highlighting with proper scoping
  • Foundry integration: Automatic detection of .t.sol and .s.sol files
  • Pure Vim: No external dependencies, works in Vim 8.0+ and Neovim

Installation

vim-plug

Add to your ~/.vimrc or ~/.config/nvim/init.vim:

Plug 'thesis/vim-solidity', { 'branch': 'main' }

Then run :PlugInstall

Vundle

Add to your ~/.vimrc:

Plugin 'thesis/vim-solidity'

Then run :PluginInstall

Pathogen

git clone https://github.com/thesis/vim-solidity.git ~/.vim/bundle/vim-solidity

Native Vim Packages (Vim 8+)

mkdir -p ~/.vim/pack/plugins/start
git clone https://github.com/thesis/vim-solidity.git ~/.vim/pack/plugins/start/vim-solidity

Neovim with lazy.nvim

{
  'thesis/vim-solidity',
  branch = 'main',
  ft = 'solidity',
}

Configuration

Enable Code Folding

Add to your ~/.vimrc:

augroup solidity_folding
    au!
    au FileType solidity setlocal foldmethod=syntax
augroup END

Usage:

  • zc - Close fold under cursor
  • zo - Open fold under cursor
  • zM - Close all folds
  • zR - Open all folds

Comment Toggling

vim-solidity works with vim-commentary:

Plug 'tpope/vim-commentary'

Usage:

  • gcc - Toggle comment on current line
  • gc in visual mode - Toggle comment on selection

Matchit Support

Enable % jumping between Solidity constructs:

" In your .vimrc
runtime macros/matchit.vim

Supported matches:

  • contract}
  • function}
  • ifelse
  • trycatch
  • assembly}

Advanced Features

Foundry Workflow

vim-solidity detects Foundry projects automatically:

  • .t.sol files → Test files
  • .s.sol files → Script files
  • Regular .sol files → Contract files

A buffer-local variable b:solidity_file_type is set to 'test', 'script', or 'contract'.

Syntax Highlighting

All modern Solidity features are highlighted:

// Custom errors (0.8.4+)
error InsufficientBalance(uint256 available, uint256 required);

// User-defined value types (0.8.18+)
type UFixed256x18 is uint256;

// Using global (0.8.19+)
using SafeMath for uint256 global;

// Transient storage (0.8.24+)
contract Example {
    transient uint256 temporaryValue;

    // Unchecked arithmetic (0.8.0+)
    function increment(uint256 x) public pure returns (uint256) {
        unchecked {
            return x + 1;
        }
    }
}

NatSpec Comments

Full support for Solidity's documentation format:

/// @title A title
/// @author The author name
/// @notice Explain to end users what this does
/// @dev Explain to developers the extra details
/// @param x Description of parameter x
/// @return Description of return value
function example(uint256 x) public returns (uint256) {
    return x * 2;
}

Yul/Assembly

Assembly blocks have proper syntax highlighting with scoped opcodes:

function getCodeSize(address addr) public view returns (uint256 size) {
    assembly {
        size := extcodesize(addr)
    }
}

Compatibility

  • Vim: 8.0 or later
  • Neovim: Fully compatible
  • Solidity: 0.8.0 through 0.8.24+ (backward compatible with 0.7.x)

Known Limitations

This is a pure Vim plugin focused on syntax, indentation, and folding. It does not provide:

  • Language Server Protocol (LSP) features (go-to-definition, hover, rename)
  • Linting (use ALE or Syntastic)
  • Code completion (use LSP or YouCompleteMe)
  • Compiler integration (planned for future release)

For full IDE features, you can set up an LSP client (coc.nvim, vim-lsp, or native Neovim LSP) with a Solidity language server like nomicfoundation/solidity-language-server.

Comparison with Other Plugins

Feature vim-solidity (this) tomlion/vim-solidity
Actively maintained ✅ Yes ❌ Abandoned (5+ years)
Vim support ✅ Yes ✅ Yes
Neovim support ✅ Yes ✅ Yes
Solidity 0.8.x ✅ Yes ❌ Partial
Pure Vim ✅ Yes ✅ Yes

Use vim-solidity if:

  • You want actively maintained Solidity syntax support
  • You need modern Solidity 0.8.x features
  • You prefer a simple, dependency-free plugin
  • You work on remote servers via SSH
  • You want syntax highlighting and code folding that "just works"

For LSP features:

If you need go-to-definition, hover, rename, and other IDE features:

Troubleshooting

Colors look wrong

Your colorscheme may not define Solidity-specific groups. Try a different colorscheme or customize:

" In your .vimrc
hi link solKeyword Statement
hi link solBuiltinType Type
hi link solConstant Constant

Indentation is incorrect

The indentation logic is based on JavaScript. For complex cases, you may need to manually adjust with >> and <<.

Please report persistent indentation issues with a minimal example.

Folding doesn't work

Make sure you've set foldmethod:

:set foldmethod=syntax

If folding is slow, try:

:set foldmethod=indent

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

Development Setup

# Clone vader.vim for testing
git clone https://github.com/junegunn/vader.vim.git test/vader.vim

# Run tests
vim -Nu test/vimrc -c 'Vader! test/vader/*.vader'

Reporting Issues

Before opening an issue:

  1. Check existing issues for duplicates
  2. Test with a minimal .vimrc
  3. Provide a minimal Solidity example
  4. Include your Vim version and OS

Use our issue templates.

Related Projects

History

This plugin is a maintained fork of 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.

License

MIT License - see LICENSE for details.

Maintainers


⭐ If you find vim-solidity useful, please star the repository!

Built with ❤️ for the Solidity and Vim communities.

About

Syntax highlighting for Solidity in Vim

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 13