On 2026-04-14, rendcrx (Vim Github Repository) wrote: > Thank you for mentioning Makefile and the default build workflow. > > I do like Makefile, but it has some drawbacks as I mentioned earlier. > > When I’m working on small, standalone files, I often need to switch between > different commands. For example: > > gcc -S to inspect assembly > gcc -O2 / gcc -O0 to compare compiler output > go test -race for testing, go run to execute a Go program > > Writing a dedicated Makefile for every such case feels cumbersome.And > constantly changing makeprg for these one-off commands is also very tedious.It > would be much more convenient if I could run a command directly like this, > without leaving Vim, and still capture errors :compile gcc -S -O2 %
You could write your own command, e.g. :Compile, that would take as arguments the compiler command line. Your command could assign the that command line to 'makeprg' and run :make. It might have to configure 'efm' as appropriate for each compiler, but something would have to do that no matter what solution you chose. If you don't like the idea of using commands that begin with an upper-case letter, there are solutions for that, too, using command abbreviations. > Using Makefile requires running make in the right directory, otherwise I have > to specify the path manually.If I’m working in a deeply nested directory with > autochdir enabled, make becomes inconvenient. You could have your custom build command search for the project root directory, i.e., the directory in which you would normally execute your build command. The project root directory is often identifiable as containing the project's build configuration file (e.g. Makefile) or revision control system directory (e.g. .git). Your build command could cd to that directory before executing the actual build command, using :cd or :lcd within Vim, or using cd in the shell command that launches the build. > It would be better to have a dedicated compilation window that remembers the > environment and the last command.Then I could press a shortcut (like g in > Emacs) to re-run the build.That way I could browse files anywhere and just > switch to the compilation window to rerun the last build command. You could do that, too. You would presumably execute some command of your own to set up that window, and that command could use :lcd to set that window's working directory. Unfortunately, as far as I can tell, Vim does not have window-local or buffer-local history. To retrieve the last build command, you might have to search for it, but that's pretty easy. Just type the start of the command and the <Up> key. See the paragraph immediately preceding the ":help :history" entry. Alternatively, you could have your build command cache the last compile command and use it if you didn't give your command any arguments, for example. > I’m happy to use Makefile for my own C projects.But for other > people’s projects or non-C projects, the default make doesn’t feel > very convenient. I've been working on these issues for years and have found solutions that work well for me. The problems I've run into have usually been due to my not fully understanding the problem or the behavior I wanted rather than to any limitation of Vim. 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/20260415072453.GI10946%40phoenix.
