On 2026-04-14, rendcrx (Vim Github Repository) wrote:
> Hi
> 
> I’ve been trying to find a good way to compile/build code from
> inside Vim.

This is what the :make command is intended to do.

> The methods I currently know of are as follows:
> 
>  1. Use tmux or Ctrl-z to suspend Vim and perform compilation or building
>  2. Use the :! command
>  3. Use the :make command
>  4. Use the :term command
>  5. Use external plugins such as vim-dispatch or asyncrun
> 
> However, I believe all these approaches have drawbacks:

> Method 3: :make command
> 
> make output is not syntax-highlighted.

True.

> You have to manually set the compiler beforehand.
> 
> If I just want to compile the current file with gcc, it is
> cumbersome — I have to manually change makeprg.

Neither is necessarily true.  The default :make command is make, and
make has internal rules to make a specified target from a source
file in various languages.  For example, if you edit foo.c to add
a C main(), then save it, you can build foo by executing

    :make foo

Even without a Makefile, the make program knows how to compile foo
from foo.c using cc, which on my system is a link to gcc.

> When using other build commands, :make is not very intuitive,
> since it is not actually running the make utility.

By default, it is using make.  It is also "intuitive" if you've been
using Unix for a while.  If you want :make to run something else,
you can specify it in a filetype plugin, or use a project Makefile
that specifies how to build a given program.  There are all sorts of
ways to expand on those ideas to have a :make command that "just
works".

> I'm curious if others have found better workflows, or if there are
> existing solutions I've missed. Looking forward to hearing your
> thoughts!

I have mainly used one of two workflows.

1.  Use a Makefile or a 'makeprg' that is smart enough to figure out
    what to build from the argument targets I specify.  I have
    a plugin that configures Vim according to the project Vim starts
    in or the file Vim first edits, so selecting a build system for
    each project is pretty easy and the build command is always the
    same:  :make.

2.  Run make or a similar command externally using a simple wrapper
    script that tees stdour and stderr to a file.  This lets me see
    the full color output of the build command.  If the output
    contains an error, I run another wrapper script around Vim that
    uses that build output file as an argument to Vim's -q option to
    put the errors into the quickfix list.

    This method has the feature of allowing the use of less on the
    build output to get scrolling and coloring.

Regards,
Gary

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/20260415044914.GH10946%40phoenix.

Raspunde prin e-mail lui