2015-07-12 89 views
0

我想管stderrgcctee errors.err,但我沒有運氣嘗試這兩塊我提出了:如何在vim中makeprg gcc pipe tee errors.err?

setlocal makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>\ >(tee\ errors.err) 

的文件是存在的,但它的空白。起初我以爲:make正在刪除它,但即使使用set makeef=makeerrors.errerrors.err文件仍然是空白。

其他(實際上是我以前的)解決方案是:

setlocal makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>&1\ |\ tee\ errors.err 

但我得到這個錯誤我從來沒有想出如何消除:E10: \ should be followed by /, ? or &


編輯1:我試過以便使用其他文件名,如teerrors.err,以防萬一。同樣的問題。

編輯2:我也嘗試:

set shellredir=2>errorsredir.err 
!gcc % -o %<.x 

無濟於事。但是,無論如何,這不會是一個解決方案,因爲我不能將makeprg設置爲過濾器。

編輯3:這一個(額外\在管)

setlocal makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>&1\ \|\ tee\ teeerrors.err 

給出VIM錯誤:E492: Not an editor command: tee teeerrors.err

我剛用完的想法。

+0

您可以放心地忘記'makeprg'。它被設計打破了,它永遠不會做你想要的。如果你使用'system()'和'cgetexpr',你可能會有更多的機會,只要你閱讀源代碼並找出正確的詮釋'shell','shellcmdflag','shellpipe','shellquote','shellredir ''''shellslash','shelltemp','shellxquote'和'shellxescape'。是的,這很糟糕。 – lcd047

+0

謝謝。你的評論雖然沒有解決這個問題,但卻是一個不錯的靈感。我開始玩'makeprg = bash -c ...',只是爲了實現,由於錯誤消息,'makeprg'本身使用'bash -c ...'。所以我簡化了一些東西(見下面的答案)。 –

回答

0

我想我找到了一個解決方案。比我想象的更簡單。

:set makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>errors.err;\ cat\ errors.err 

底線:你不能管。 (至少我找不到管道解決方案)。

+0

添加到我的'c.vim'插件。 ;) –

1

有點晚,但是......你可以用管道,只需要添加額外的雙反斜線:

setlocal makeprg=gcc\ -Wall\ -Wextra\ -g\ -O0\ -ansi\ -pedantic-errors\ %\ -o\ %<.x\ 2>&1\ \\\|\ tee\ teeerrors.err 
+0

謝謝!我會仔細看看。 –