Home

Awesome

Compiler.nvim

Neovim compiler for building and running your code without having to configure anything.

screenshot_2023-06-19_13-59-07_947251291

<div align="center"> <a href="https://discord.gg/ymcMaSnq7d" rel="nofollow"> <img src="https://img.shields.io/discord/1121138836525813760?color=azure&labelColor=6DC2A4&logo=discord&logoColor=black&label=Join the discord server&style=for-the-badge" data-canonical-src="https://img.shields.io/discord/1121138836525813760"> </a> </div>

Table of contents

Why

Those familiar with Visual Studio IDE will remember how convenient it was to just press a button and having your program compiled and running. I wanted to bring that same user experience to Neovim.

Supported languages

LanguageMore info
asm x86-64
c
c++
c#+info
dart+info
elixir+info
fortran
f#+info
gleam+info
flutter+info
go
java+info
javascript+info
kotlin+info
lua
make
perl
python+info
r
ruby
rust
shell+info
swift
typescript+info
visual basic dotnet+info
zig+info

Required system dependencies

Some languages require you manually install their compilers in your machine, so compiler.nvim is able to call them. Please check here, as the packages will be different depending your operative system.

How to install

lazy.nvim package manager

{ -- This plugin
  "Zeioth/compiler.nvim",
  cmd = {"CompilerOpen", "CompilerToggleResults", "CompilerRedo"},
  dependencies = { "stevearc/overseer.nvim", "nvim-telescope/telescope.nvim" },
  opts = {},
},
{ -- The task runner we use
  "stevearc/overseer.nvim",
  commit = "6271cab7ccc4ca840faa93f54440ffae3a3918bd",
  cmd = { "CompilerOpen", "CompilerToggleResults", "CompilerRedo" },
  opts = {
    task_list = {
      direction = "bottom",
      min_height = 25,
      max_height = 25,
      default_detail = 1
    },
  },
},

Recommended mappings

-- Open compiler
vim.api.nvim_set_keymap('n', '<F6>', "<cmd>CompilerOpen<cr>", { noremap = true, silent = true })

-- Redo last selected option
vim.api.nvim_set_keymap('n', '<S-F6>',
     "<cmd>CompilerStop<cr>" -- (Optional, to dispose all tasks before redo)
  .. "<cmd>CompilerRedo<cr>",
 { noremap = true, silent = true })

-- Toggle compiler results
vim.api.nvim_set_keymap('n', '<S-F7>', "<cmd>CompilerToggleResults<cr>", { noremap = true, silent = true })

Commands

CommandDescription
:CompilerOpenShows the adecuated compiler for your buffer's filetype.
:CompilerToggleResultsOpen or close the compiler results.
:CompilerRedoRedo the last selected option.
:CompilerStopDispose all tasks.

How to use (Basic usage)

This is what happen when you select build & run, build, or run in the compiler:

compiler.nvim will look for the conventional entry point file for the current language you are using. To achieve this, it searches in your current working directory for the next files

LanguageDefault entry pointDefault output
asm x86-64./main.asm./bin/program
c./main.c./bin/program
c++./main.cpp./bin/program
c#./Program.cs./bin/Program.exe
dart./lib/main.dart./bin/main
elixir./mix.exs./_build/
fortran./fpm./build/
f#see here./bin/
gleam./build.toml./build
flutter./pubspec.yaml./build/
go./main.go./bin/program
java./Main.java./bin/Main.class
javascript./src/index.js
kotlin./Main.kt./bin/MainKt.class
lua./main.lua
make./Makefile
perl./main.pl
python./main.py./bin/program
r./main.r
ruby./main.rb
rust./main.rs./bin/program
shell./main.sh
swift./main.swift./bin/program
typescript./src/index.ts
visual basic .netsee here./bin/
zig./build.zig./zig-out/bin/build

This is how the compilation results look after selecting Build & run program in c screenshot_2023-06-19_13-59-37_766847673 For more info see wiki - when to use every option

Creating a solution (optional)

If you want to have more control, you can create a .solution.toml file in your working directory by using this template where every [entry] represents a program to compile

[HelloWorld]
entry_point = "/path/to/my/entry_point_file/main.c"
output = "/path/where/the/program/will/be/written/hello_world"
arguments = ""

[SOLUTION]
executable = "/program/to/execute/after/the/solution/has/compiled/my_program"

For more examples see wiki.

Build automation utilities (optional)

If any of these files exist in your current working directory, they will be automatically detected and displayed on Compiler.nvim:

Build automation utilityFileMore info
Make./Makefile+info
CMake./CMakeLists.txt+info
Gradle./build.gradle+info
Maven./pom.xml+info
NodeJS NPM./package.json+info
Meson./meson.build+info

Quick start

Create ~/c-example/main.c and paste this code. Then do :cd ~/c-example/ to change the working directory to the project.

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

Open the compiler and select Build and run. You will see the compilation results.

screenshot_2023-07-25_23-56-57_069109256

FAQ

How can I compile videogames?

The workflow of game development is essentially very different from just compiling and running a program. It involve loading editing and running scenes. While there is no way for us to support it directly, here I offer you some tricks:

Godot engine

To Build and run a godot scene, use the command godot /my/scene.tscn on the terminal. This works really well: It's fast and simple.

Unity

The recommended way is to have 2 monitors, one with nvim and your code, and another one with your unity scenes to run the game. Unity has some terminal commands, but working with them is quite a painful experience.

🌟 Support the project

If you want to help me, please star this repository to increase the visibility of the project.

Stargazers over time

Thanks to all contributors

<a href="https://github.com/zeioth/compiler.nvim/graphs/contributors"> <img src="https://contrib.rocks/image?repo=zeioth/compiler.nvim" /> </a>

Roadmap