Vim script: how to easily transfer data to cwindow

I am using a user-defined function (currently located in .vimrc) and not: make or another direct command line tool to compile / check my currently edited file for errors. Like this:

function! CompileMyCode(...) set errorformat=Error:\ %m\\,\ in\ line\ %l let l:output = "Error: bad code!, in line 9" return l:output endfunction command! -nargs=* CompileMyCode :call CompileMyCode(<f-args>) 

when using a new command in command mode, an error window does not appear.

 :CompileMyCode | cwindow 

What am I doing wrong?

Edit: Now I tried the following, which also does not open any cwindow.

 function! CompileMyCode(...) set errorformat=Error:\ %m\\,\ in\ line\ %l let l:output = "Error: bad code!, in line 9" " I tried both of the following lines separately cexpr l:output call setqflist([l:output]) endfunction 

The suggested cexpr and setqflist() do not correctly open the cwindow window in my example. Can anyone suggest a complete solution?

Edit 2:

The main problem is resolved. Here is my current code:

  let l:result = expand("%").'|8| errortext' cexpr [ l:result, l:result ] caddexpr '' cwindow 

This example looks at the default error format that vim seems to support. When cexpr outputs the actual error and uses errorformat , cwindow seems to ignore this.

However, I wanted to stick to the default error format anyway on the output, not relying on a custom errorformat

Thanks for your answers!

+4
source share
2 answers

I did something similar using cexpr l:output instead of returning a string and putting the compilation output into the quickfix window. You can see my vim function here: http://www.zenskg.net/wordpress/?p=199

Update

Adding an empty line to the quick delete list seems to allow cwindow to appear. For instance:

 function! MyCompile() let l:output = "Error: line 1" cexpr l:output caddexpr "" cwindow endfunction 
+3
source

If you already have access to the error information as structured data in Vim (or you can easily get it), you can use setqflist() .

+2
source

All Articles