[英]Vim - compiling a C program and displaying the output in a tab
我正在嘗試編譯一個 C 程序並將其輸出顯示在 Vim 的選項卡中。
我的設置如下所示:
hellomain.c
#include<stdio.h>
#include<stdbool.h>
int main()
{
int i = 100;
bool b =0;
printf("hello world :)");
return 0;
}
生成文件
program: hellomain.c
gcc -o hello hellomain.c
當我運行:make | copen
:make | copen
, :make | copen
這篇文章,我看到了一個這樣的窗口:
gcc -o hello hellomain.c
Press ENTER or type command to continue
按回車后,程序編譯,我看到一個新的水平拆分選項卡,其中包含gcc
命令,但不是程序的輸出:
這里有什么問題?
:make && ./hello
你試過這個嗎?
或者,嘗試以下
:make && ./hello | copen
首先,對於由單個源文件組成的程序,您不需要編寫 Makefile(除非您的 gnumake 版本不正確(mingw),或者如果您使用的是非 gnu 系統(macosx?))。
然后,在另一篇文章中,我提出了一種編譯和執行的方法(如果編譯成功)並且允許注入可選輸入。 該解決方案需要編寫一些腳本。
手動非自動版本是
" Change compilation options -- required once per vim session
" in C++, it would be $CXXFLAGS...
" See the other post for more on the topic
let $CFLAGS = '-Wall -Wextra -O3'
" Compile
:make %<
:copen
" Execute
:!./%<
" or
:term ./%<
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.