Hi
I’ve been trying to find a good way to compile/build code from inside Vim.
:! command:make command:term commandHowever, I believe all these approaches have drawbacks:
Cannot make use of quickfix.
:! commandAlso cannot use quickfix, and produces extra output that clutters the terminal screen. If I run it multiple times, it becomes difficult to locate the output.
I have set these three autocommands to work around this:
set t_te= autocmd VimLeavePre * set t_te& autocmd VimSuspend * set t_te& autocmd VimResume * set t_te=
However, with large amounts of output I can no longer scroll up to review it, nor can I revisit the output later. make and grep suffer from the same issue.
:make commandmake output is not syntax-highlighted.
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.
When using other build commands, :make is not very intuitive, since it is not actually running the make utility.
Additionally, I have set 'autochdir' for convenience when switching files with :e, which causes :make to run in the current directory. However, many projects have their Makefile in the top-level directory.
(If I avoid 'autochdir' and use :find instead of :e, the completion for :find includes header file directories as well.)
:term commandFeels like a very good solution so far, with highlighted output. Although it does not integrate with quickfix natively, I can use :cgetbuf later to make use of quickfix.
In my opinion, plugins are meant to improve or add new features, not completely change the existing workflow. They require learning new uppercase commands.
Moreover, many core features of these plugins rely on integration with external tools like tmux or external terminals.I believe compilation and building should be handled more effectively by Vim itself.
Could we add an option to :!, :make, and :grep to run them via term_start? This would allow asynchronous execution, let us navigate the output using Vim's built-in movement commands, and also provide syntax highlighting. If we automatically run cgetbuf at the end, we could also make use of the quickfix feature.
Add a compile command that executes the following build command through term_start(we can use :compile gcc -g % to compile our file). We could then use cgetbuf to capture the compilation results. This would be very convenient when frequently switching compilers or build commands, as we would no longer need to manually set makeprg. We could also automatically detect the command being run (similar to vim-dispatch) and switch the errorformat accordingly.
In the output window, we could use the g command to repeat the last executed command. The advantage is that the window preserves the previous execution directory and environment. This way, even if we navigate deep into the project directory, pressing g would still run the build from the project root. This idea is inspired by Emacs.
This might also be a good solution for #5411, because we use a separate window to display the original text.And we also don't need 'autochroot' to build project #16070.
Additionally, could term_start support a "non-scrolling" mode? I've noticed that Emacs's compile command does not scroll automatically. I'm not sure if this would be a good idea to adopt in Vim. Perhaps it would be better to avoid auto-scrolling during compilation, but jump straight to the error output if the build fails? But there might be people like me who often run commands like :term go doc strings. This would behave similarly to running go doc strings | less or gcc --help | less in bash. It would be much better if :term could support non-scrolling output.
This is my current idea, and I’m not sure if there’s a better solution.
I'm curious if others have found better workflows, or if there are existing solutions I've missed. Looking forward to hearing your thoughts!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
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 %
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.
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.
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.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Another ideas
:termdef TermClick() if &buftype == 'terminal' const line = getline('.') if line =~ '.+:\d+:\d+: error: \d+' # TODO: show the error message using popup or text properties # open the file at the error line ed file cursor(lnum, col) endif enddef nnoremap <LeftMouse> <scriptcmd>TermClick()<CR> nnoremap <S-CR> <scriptcmd>TermClick()<CR>
ch_listen to open a port in vim, create a wrapper program that run the compiler and then notify vim that the compile has finished, process the compile error to quickfix, run the wrapper in :term—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
Relate: #18188
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.![]()
This is an enhancement of using terminal. https://github.com/habamax/.vim/blob/master/autoload/terminal.vim
—
Reply to this email directly, view it on GitHub.
You are receiving this because you commented.![]()
Thanks for sharing! It’s great to see related work and enhancements around the terminal usage.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.![]()