英文:
Problems with Quickfix list
问题
我正在尝试配置makeprg
,以便在我输入:make
时编译我的C程序,如果有问题,将它们放入Quickfix列表中,如果没有问题,运行程序并将输出放入Quickfix列表。
我正在使用:
- vim 9.0
- zsh
- 在M1 Mac上使用g++编译器
- 在Alacrity模拟器中
这个配置可以工作,但它不执行代码:
set makeprg=g++\ -w\ -g\ %\ -o\ %:r
当我尝试这个配置时:
CompilerSet makeprg=rm\ -fr\ %:r;g++\ -w\ -g\ %\ -o\ %:r&&./%:r
它的运行方式如下:
(我的代码中有错误)它会显示错误,然后我按回车键,会出现一个空屏幕和:
E40: 无法打开错误文件 /var/folders/hc/y4sccdy52y34th77l1lc0j_c0000gn/T/vTqwygm/3
(最后三个文件夹在每次运行时都会更改)
然后我再按一次回车返回到vim,并且Quickfix列表的内容没有改变。
当我删除错误时:
./%:r
的输出显示没有问题。
我添加了:
rm\ -fr\ %:r
因为我认为如果没有可执行文件供./%:r
运行,它就不会显示在Quickfix中。
没有这个配置,它总是显示以下输出:
rm\ -fr\ %:r
非常感谢任何帮助。
英文:
I am trying to make makeprg
so that when I write :make
it will compile my c program and if there are problems put them in Quickfix list and if there are non run the program and put output to Quick fix list
I am using
- vim 9.0
- zsh
- g++ compiler on m1 mac
- in alacrity emulator
this works but it doesn't execute the code:
set makeprg=g++\ -w\ -g\ %\ -o\ %:r
when I try this one:
CompilerSet makeprg=rm\ -fr\ %:r;g++\ -w\ -g\ %\ -o\ %:r&&./%:r
it goes like this:
(I have errors in my code) it shows me the errors then I hit enter I get blank screen with :
E40: Can't open error file /var/folders/hc/y4sccdy52y34th77l1lc0j_c0000gn/T/vTqwygm/3
(last three folders change every run)
then I hit another enter return to vim and contents of Quickfix list is unchanged.
when I remove the error:
output of ./%:r
is shown with no problems.
I added :
rm\ -fr\ %:r
because I thought that if there will be no executable to run for ./%:r
it will not show in Quick fix
without that it always shows output of
rm\ -fr\ %:r
any help is much appreciated
答案1
得分: 0
Vim正在将makeprg
的输出重定向到一个文件,因此出现错误:./%:r
没有输出。
当你想要运行多个命令时,输出将来自最后一个命令。相反,你需要创建一个子shell来运行两个命令,以便两者的输出被合并在一起:
set makeprg=(g++\ -w\ -g\ %\ -o\ %:r\ &&\ ./%:r)
英文:
Vim is redirecting the output from makeprg
to a file, hence the error: there is no output from ./%:r
.
When you want run multiple commands, the output will be taken from the last one. Instead you need to create a subshell to run both commands, so the output of both is combined together:
set makeprg=(g++\ -w\ -g\ %\ -o\ %:r\ &&\ ./%:r)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论