• Stars
    star
    348
  • Rank 118,068 (Top 3 %)
  • Language
    Lua
  • License
    GNU General Publi...
  • Created 11 months ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Compiler.nvim

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

screenshot_2023-06-19_13-59-07_947251291

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. I wanted to bring that same user experience to Neovim.

Supported languages

Planned & coming soon:

Pull requests are welcome. See FAQ.

  • dart
  • kotlin
  • swift
  • javascript
  • typescript
  • visual basic
  • F
  • R
  • objetive C
  • scala
  • elixir
  • delphy
  • pascal
  • cobol

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" },
  opts = {},
},
{ -- The task runner we use
  "stevearc/overseer.nvim",
  commit = "3047ede61cc1308069ad1184c0d447ebee92d749",
  cmd = { "CompilerOpen", "CompilerToggleResults", "CompilerRedo" },
  opts = {
    task_list = {
      direction = "bottom",
      min_height = 25,
      max_height = 25,
      default_detail = 1,
      bindings = { ["q"] = function() vim.cmd("OverseerClose") end },
    },
  },
},

Recommended mappings

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

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

Commands

Command Description
:CompilerOpen Shows the adecuated compiler for your buffer's filetype.
:CompilerToggleResults Open or close the compiler results.
:CompilerRedo Redo the last selected option.

How to use (Basic usage)

This is what hapen 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

Language Default entry point Default output
c ./main.c ./bin/program
c++ ./main.cpp ./bin/program
c# ./Program.cs ./bin/Program.exe
java ./Main.java ./bin/Main.class
rust ./main.rs ./bin/program
go ./main.go ./bin/program
asm x86-64 ./main.asm ./bin/program
python ./main.py ./bin/program
ruby ./main.rb
lua ./main.lua
perl ./main.pl
shell ./main.sh
make ./Makefile

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.

Make (optional)

This option will look for a Makefile in the working directory and execute it with make Makefile. For more examples see wiki.

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

  • I don't have time to read: If you prefer you can try NormalNvim which comes with the compiler pre-installed. Just open some code and hit F6!

  • How can I add a language that is not supported yet? Fork the project, and go to the directory /compiler/languages. Copy c.lua and rename it to any language you would like to add, for example ruby.lua. Now modify the file the way you want. It is important you name the file as the filetype of the language you are implementing. Then please, submit a PR to this repo so everyone can benefit from it.

  • How can I change the way the compiler works? Same as the previous one.

  • Is this plugin just a compiler, or can I run scripts too? Yes you can. But if your script receive arguments, we recommend you to use the terminal instead, because creating a .solution.toml file just to be able to pass arguments to your simple shell script is probably a overkill, and not the right tool.

  • Is this plugin also a building system manager? No, it is not. For convenience, we provide the option Run Makefile, which should cover some cases of use. But if your workflow relies heavily on building systems, please consider installing an specific neovim plugin for this purpose. See wiki.

  • I'm a windows user, do I need to do something special? You have to enable WLS, and run nvim inside. Otherwise it would be impossible for you to install the required dependencies.

  • Where are the global options? There are not. Creating a .solution file of your project is the way to configure stuff. This way we can keep the code extra simple.

  • How can I disable notifications when compiling? Check here.

  • I'm coding a web, how do I run it? Please don't try to compile/run web languages. I recommend you this strategy instead:

    • A way to transpile: toggleterm + tmux.
    • A way run the project: Just keep the website opened in your browser.
  • How can I auto :cd my projects? Use this fork of the plugin project.nvim.

🌟 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

Roadmap

  • Better windows compatibility when not using WLS: The commands rm -rf and mkdir -p only exist on unix. To support Windows without WLS we should run the equivalent powershell command when Windows is detected.

More Repositories

1

garbage-day.nvim

Garbage collector that stops inactive LSP clients to free RAM
Lua
137
star
2

markmap.nvim

Visualize your Markdown as mindmaps with markmap
Lua
121
star
3

rofi-shortcuts

The ultimate shortcuts cheatsheet
Shell
51
star
4

rofi-zeal

Use rofi to search documentation on Zeal and Man
Shell
46
star
5

heirline-components.nvim

Distro agnostic components for your Neovim heirline config
Lua
33
star
6

termux-docker

Just a script that setups everything for you
Shell
33
star
7

dooku.nvim

Code documentation generator for Neovim
Lua
28
star
8

XFCE-Wacom-Settings

Wacom settings for XFCE
Shell
24
star
9

django-dual-authentication

Allows authentication with either a username or an email address.
Python
18
star
10

django-email-blacklist

Python class to detect Disposable Emails.
Python
17
star
11

wofi-calc

A simple calculator for wofi, inspired in rofi-calc
Shell
17
star
12

zeioth-hyprland-config

My personal config - Feel free to get ideas from here
Roff
14
star
13

atom-visual-studio-code-ui

The experience of Visual Studio Code, now in Atom.
Less
11
star
14

zeioth-lutris

My contributions to Lutris
10
star
15

makeit.nvim

Neovim Makefile plugin
Lua
10
star
16

atom-visual-studio-code-light-ui

The real experience of Visual Studio Code, now in Atom.
Less
7
star
17

latencyflex2-installer

LatencyFlex2 installer easy to hack
Shell
6
star
18

fzf-kill

Kill -9 with zfz
Shell
3
star
19

zeioth-zmk

My wireless keyboard drivers
C
3
star
20

hyprshotgun

Screenshots the way you like: Local, or online
Shell
3
star
21

vim-doxygen

Doxygen integration for vim
Vim Script
3
star
22

distroupdate.nvim

Neovim plugin to update your current distro from its github remote
Lua
3
star
23

zeioth-qmk

My wired keyboard drivers
C
2
star
24

vim-dooku

(Highly customizable) Documentation generator(s) for VIM
2
star
25

mason-extra-cmds

Provides the command :MasonUpdateAll
Lua
2
star
26

vim-typedoc

Autogenerate and open your typedoc documentation from vim
Vim Script
2
star
27

vim-zeioth-config

One of the best vimconfigs you are gonna find out there. Most likely.
Python
2
star
28

norecaptcha-python3

Python 3 client for Google No CAPTCHA reCAPTCHA services.
Python
2
star
29

new-project.nvim

A neovim plugin to create a new project
2
star
30

none-ls-external-sources

All external sources not natively supported by none-ls.
Lua
2
star
31

idoven-technical-challenge

Challenger: Adrian Lopez
Python
1
star
32

linux-security-notifications

Systemd service that displays important security information as friendly desktop notifications.
1
star
33

IDE.nvim

The bastard son of Neovim, Visual Studio and IntelliJ
1
star
34

package-manager.nvim

A package manager to rule them all.
1
star
35

BrrrOS

The OS that goes like brrr
Python
1
star
36

paco

Aliases to make the most common pacman commands more intuitive.
Shell
1
star
37

basic-programming-principles

Examples for people initiating in coding
Python
1
star