Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Neovim Setup

This note covers setting up Compact language support in Neovim using compact.vim, a community-driven plugin.

Docs: Neovim Setup


Intuition First

The compact.vim plugin provides language features for Compact source files in Neovim. It’s not an official Midnight plugin, but it’s the recommended way to edit .compact files with proper syntax highlighting and indentation.

The plugin matches the language features found in the VS Code extension, but for Neovim.


Features

FeatureWhat it does
Syntax highlightingKeywords, types, circuits colored
Smart indentationProper indent for blocks
Code foldingFold circuit definitions
Text objectsSelect circuit bodies
Import navigationgf jumps to imports
Compiler integration:make runs the compiler

Installation

Using lazy.nvim

Add to your plugins in init.lua:

return require("lazy").setup({
  { "1NickPappas/compact.vim" },
})

Using packer

use("1NickPappas/compact.vim")

Using vim-plug

Plug '1NickPappas/compact.vim'

Configuration

File Detection

The plugin automatically detects .compact files. No configuration needed.

Syntax Highlighting

Syntax highlighting works automatically.

Compiler Integration

Run the compiler from Neovim:

:compiler compactc
:make %:p

Usage

Opening a Compact File

nvim contracts/contract.compact

The plugin activates automatically based on the .compact extension.

Folding

Fold circuits and blocks:

za         " toggle fold
zR         " open all folds
zM         " close all folds

Jump to imports with gf:

gf         " go to file under cursor

Tree-Sitter Integration

The plugin supports tree-sitter for better parsing:

require("nvim-treesitter.configs").setup({
  ensure_installed = { "compact" },
})

The tree-sitter parser provides accurate syntax highlighting and better performance.


Quick Recap

  • Install via your plugin manager.
  • Syntax highlighting and indentation work automatically.
  • Use :make to compile from Neovim.
  • Review troubleshooting for issues.