Skip to content

trimclain/builder.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚒️ builder.nvim

Simple building plugin for neovim inspired by the Build Tool from Sublime Text.

Default
bot
Vertical Floating
vert float

Demo

demo.mp4

Requirements

Installation

Using lazy.nvim (recommended)

{
    "trimclain/builder.nvim",
    cmd = "Build",
    -- stylua: ignore
    keys = {
        { "<C-b>", function() require("builder").build() end, desc = "Build" }
    },
    opts = {
        commands = {
            -- add your commands
        },
    },
}

Using packer.nvim

use {
    "trimclain/builder.nvim",
    config = function()
        require('builder').setup({
            commands = {
                -- add your commands
            },
        })
        vim.keymap.set("n", "<C-b>", "<cmd>Build<cr>", { silent = true, desc = "Build" })
    end
}

Configuration

Builder comes with the following defaults:

{
    -- location of Builder buffer; opts: "bot", "top", "vert" or float
    type = "bot",
    -- percentage of width/height for type = "vert"/"bot" between 0 and 1
    size = 0.25,
    -- size of the floating window for type = "float"
    float_size = {
        height = 0.8,
        width = 0.8,
    },
    -- which border to use for the floating window (see `:help nvim_open_win`)
    float_border = "none",
    -- number or table { above, right, below, left }, similar to CSS padding
    padding = 0,
     -- show/hide line numbers in the Builder buffer
    line_number = false,
    -- automatically save before building
    autosave = true,
    -- keymaps to close the Builder buffer, same format as for vim.keymap.set
    close_keymaps = { "q", "<Esc>" },
     -- measure the time it took to build
    measure_time = true,
    -- empty lines between the measured time message and the output data
    time_to_data_padding = 0,
    -- support colorful output by using to `:terminal` instead of a normal nvim buffer;
    -- for `color = true` the `type = "float"` isn't allowed
    color = false,
    -- commands for building each filetype, can be a string or a table { cmd = "cmd", alt = "cmd" }; see below
    -- for lua and vim filetypes `:source %` will be used by default
    commands = {},
}

When creating a command, there are following available variables

  • % — path to the current file from the current working directory
  • $file — current file name with extension
  • $basename — basename of the file
  • $ext — current file extension
  • $path — full path to the file
  • $dir — current working directory

This is an example of what commands could look like

    commands = {
        c = "gcc % -o $basename.out && ./$basename.out",
        cpp = "g++ % -o $basename.out && ./$basename.out",
        go = {
            cmd = "go run %",
            alt = "go build % && ./$basename",
        },
        java = {
            cmd = "java %",
            alt = "javac % && java $basename",
        }
        javascript = "node %",
        -- lua = "lua %", -- this will override the default `:source %` for lua files
        markdown = "glow %",
        python = "python %",
        rust = "cargo run",
        sh = "sh %",
        typescript = "ts-node %",
        zsh = "zsh %",
    },

Usage

Run :Build to build/run current file/project using the command for current filetype from commands table. You can also pass different size and type arguments:

:Build size=0.4 type=vert

or

:lua require("builder").build({ type = "float" })

To build with the alternative command use:

:Build alt=true

To enable colored output use:

:Build color=true

Feedback

If you have any questions or would like to see any new features, feel free to open a new Issue.

Credit

About

Simple building plugin for neovim written 100% in lua

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published