Skip to content

Neovim plugin written in Lua for running a main or script in several languages

License

Notifications You must be signed in to change notification settings

javiorfo/nvim-fuel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

nvim-fuel

Fuel for your programs

nvim-fuel is a Neovim plugin for running a main or script in several languages. This is meant to be useful for practicing and maybe teaching.

Caveats

  • To use this plugin in a particular language, the compiler or language itself needs to be installed.
  • Supported languages are: Assembly, C, C++, Clojure, Go, Haskell, Java, Kotlin, Lua, Python, Rust, Scala, Scheme and Zig
  • Posibility to add custom language implementations
  • This plugin has been developed on and for Linux following open source philosophies.

Overview

Feature nvim-fuel NOTE
Command to show results in Fuel Console ✔️ Set by Fuel
Command to close Fuel Console ✔️ Set by FuelStop
Execution in Normal Mode ✔️ Set by Fuel
Execution in Insert Mode ✔️ Set by Fuel
Console size configurable ✔️ By setup
Autosave configurable ✔️ By setup
Supports different languages in same window (different buffers) ✔️
Supports custom language implementations ✔️
Main arguments
Stdin ✔️
Popup console ✔️ By setup

Installation

Packer

use {
    'javiorfo/nvim-fuel',
    requires = 'javiorfo/nvim-popcorn'
}

Lazy

{
    'javiorfo/nvim-fuel',
    lazy = true,
    dependencies = { 'javiorfo/nvim-popcorn' },
    -- ft could contain only the languages nvim-fuel will be used for
    ft = { "asm", "c", "cpp", "clojure", "go", "haskell", "java", "kotlin", "lua", "python", "rust", "scala", "scheme", "zig" },
    opts = {
         -- Not necessary. Only if you want to change the setup
         view = {
             -- Default console size (this applies to popup size too)
             console_size = 10,

             -- Default autosave before pressing the Fuel shortcut
             autosave = true,

             -- Default false. If you want to show the console in a popup instead of a buffer
             popup = false
         }
    },
    keys = {
        { "<leader>fu", "<Plug>Fuel" },
        { "<leader>fs", "<Plug>FuelStop" }
    }
}

Configuration (Packer)

  • Set mappings in init.vim or init.lua
local opts = { noremap = true, silent = true }

-- Normal mode 
vim.api.nvim_set_keymap('n', '<leader>fu', '<Plug>Fuel', opts)
vim.api.nvim_set_keymap('n', '<leader>fs', '<Plug>FuelStop<CR>', opts)
  • Only the installation step is required to use this plugin, but you can modify this options if you like:
require'fuel'.setup{
    view = {
        -- Default console size (this applies to popup size too)
        console_size = 10,

        -- Default autosave before pressing the Fuel shortcut
        autosave = true,

        -- Default false. If you want to show the console in a popup instead of a buffer
        popup = false
    },
    -- Override language implementations or implement a missing language
    language_implementations = {
        -- C example
        c = {
            -- Required build function
            -- file_with_extension is this case will be 'file_name.c'
            -- file is this case will be 'file_name'
            build = function (file_with_extension, file)
                vim.cmd("autocmd BufDelete c_fuel_main_console silent !rm -f " .. file)
                return string.format("gcc -Wall %s -o /tmp/%s && /tmp/%s && rm -f /tmp/%s 2> /dev/null", file_with_extension, file, file, file)
            end,

            -- Required statusline function
            -- This will print on cmd statusline after build is executed
            get_statusline = function(file)
                return util.statusline_style(" C", file)
            end,

            -- Required get_footer function
            -- This will print on footer popup after build is executed
            get_footer = function(file)
                return util.footer(" C", file)
            end
        }

    }
}

Usage

  • Executing the map corresponding to Fuel in a main or scripting file, it will compile and execute the aforementioned file opening a console ouput.
  • Execute the map corresponding to FuelStop to close all open Fuel console. In case you are using popup = true just press
  • To see the execution string use the command :FuelInfo which will open a popup with info

Screenshots

Java:

java

C:

c

Haskell and Rust in the same window:

haskell

Kotlin:

With popup console

popup

NOTE: The colorscheme nebula from nvim-nyctophilia is used in this image.


Donate

  • Bitcoin (QR) 1GqdJ63RDPE4eJKujHi166FAyigvHu5R7v