Skip to content

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

Notifications You must be signed in to change notification settings

neysanfoo/compiler.nvim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Supported languages

Planned & coming soon:

  • scala
  • R
  • elixir
  • visual basic
  • F
  • 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"},
  dependencies = { "stevearc/overseer.nvim" },
  config = function(_, opts) require("compiler").setup(opts) end,
},
{ -- The framework we use to run tasks
  "stevearc/overseer.nvim",
  commit = "3047ede61cc1308069ad1184c0d447ebee92d749", -- Recommended to to avoid breaking changes
  cmd = {"CompilerOpen", "CompilerToggleResults"},
  opts = {
    -- Tasks are disposed 5 minutes after running to free resources.
    -- If you need to close a task inmediatelly:
    -- press ENTER in the menu you see after compiling on the task you want to close.
    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 })

Available 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 lenguage 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

How to create a solution (Advanced)

If you want to have more control, you can create a .solution file in your working directory by using this template:

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

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

Where every [entry] represents a program to compile

option Description
[entry] Anything inside the brackets will be ignored. Write anything you want inside. You can use it to easily identify your program.
entry_point Path of the file containing the entry point of the program.
output Path where the compiled program will be written.
parameters Are optional parameters to pass to the compiler. If you don't need them you can delete this option or leave it as empty string if you want.

[SOLUTION] represents the executable to run after all programs in the solution have compiled. This section is optional and can be deleted safely.

Option Description
[SOLUTION] Anything inside the brackets will be ignored. But keeping the the default name [SOLUTION] is recommended.
executable Path to a program to execute after the compilation finishes.

Please, respect the syntax of the .solution file, as we intentionally do not parse errors in order to keep the compiler code simple. For more examples see wiki.

Make (Advanced)

This option will look for a Makefile in the working directory and execute it with make Makefile. If your Makefile is not in the working directory, you can either change your current working directory, or create a symbolic link to the Makefile (and if you do, add it to .gitignore).

For building systems not directly supported by Compiler.nvim: Create a Makefile and use it to call cmake, maven, or any other build system you want to use from there. For more examples see wiki.

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 parameters, we recommend you to use the terminal instead, because creating a .solution file just to be able to pass parameters to your simple shell script is probably a overkill, and not the right tool.

  • I'm a windows user, do I need to do something special? In theory no. Check the dependencies section of this README.md and make sure you have them. If for some wild reason a required dependency don't exist on windows, or you don't know how to get it, the easy way is to enable the Windows Linux Subsystem and run neovim from there. Then you can just sudo apt install some_package for anything you may need.

  • 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.

🌟 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

  • Research the viability of supporting building system for languages which have an standard (c, cpp, rust, java) directly without a Makefile.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 88.3%
  • Assembly 3.2%
  • C 1.4%
  • Perl 1.2%
  • Go 1.1%
  • C# 1.1%
  • Other 3.7%