Skip to content

[idea] Filetype-aware makeprg defaults for the Compile command #292

Description

@stanfish06

What

Set sensible per-filetype makeprg defaults via a FileType autocmd so that :Compile works out-of-the-box without requiring manual vim.opt.makeprg = "..." per session.

Where

lua/config/options.lua:74 — where vim.opt.makeprg = "" is set
lua/config/options.lua:158–169 — the Compile command definition

Why it matters

init.lua:74 sets makeprg to an empty string globally, which means :Compile (options.lua:158) always calls make — a no-op unless the user has manually set makeprg first. Given 7 LSPs are configured for Go, Rust, C/C++, Python, and TypeScript, there is a clear mapping from filetype to build command that could be automated.

The existing workflow already uses marks + terminals (tabe | te) for running code. Per-filetype makeprg fills the gap for the quickfix-based compile loop (:Compile, <leader>co, <leader>cc).

Recommended implementation

Add after the Compile command definition:

vim.api.nvim_create_autocmd("FileType", {
    group = vim.api.nvim_create_augroup("FiletypeMakeprg", { clear = true }),
    callback = function()
        local defaults = {
            go         = "go build ./...",
            rust       = "cargo build",
            c          = "make",
            cpp        = "make",
            python     = "python3 %",
            typescript = "npx tsc --noEmit",
            javascript = "node %",
            lua        = "luac -p %",
            swift      = "swift build",
        }
        local ft = vim.bo.filetype
        if defaults[ft] then
            vim.bo.makeprg = defaults[ft]
        end
    end,
})

Notes

  • vim.bo.makeprg sets the option buffer-locally, so project-level overrides (:set makeprg=cmake --build build) still take effect and don't leak across buffers.
  • The existing lcd (local working directory) feature in the config pairs well: go build ./... runs from whatever directory the current window is rooted in.
  • % in the makeprg value is expanded to the current filename by :make, so python3 % and node % work as script runners for single files.
  • For projects using custom build systems, a .nvim.lua per-project file (or similar) can override makeprg per project without touching this default.
  • Consider adding :Compile check alias variants (e.g. go vet ./..., cargo check) as optional secondary patterns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions