Vim long file paths break/split over multiple lines in quickfix window

534 Views Asked by At

A long file paths is broken up over multiple lines in the Vim quickfix window which then for example does not allow to jump to the error location displayed in the qf.

The file (and the lines around) are diplayed in the quickfix window as (the example is the output from neomakes pdflatex)

|| Enter file name:
|| /long/path/to/file/.../loca
tionOfTexFiles/myTexFile.tex|144 error| Emergency stop.
|| read

to be able to follow to the file line by lnext/cnext I should have

/long/path/to/file/.../locationOfTexFiles/myTexFile.tex|144 error| Emergency stop.

For quickfix files I have the following relevant (in my view) settings which are set to:

setlocal nolinebreak
setlocal nowrap
setlocal textwidth=9999

So I am wondering how I can display the file path in one line within the quickfix window?

2

There are 2 best solutions below

3
On

On :make, Vim invokes 'makeprg', captures the output, and then parses it according to 'errorformat'. The latter does support multi-line error messages (cp. :help errorformat-multi-line), but that is mostly for what I would call intentional linebreaks, as specified by the compiler. What you suffer from is unintentional linebreaks because of line wrapping (due to overly long paths).

Now, I don't know about "neomakes pdflatex", but it looks like that tool creates the linebreaks, whereas it shouldn't, as Vim is capturing the output, and there's no receiving terminal (or user). Investigating in that direction (or opening an issue at the project's tracker) might be helpful.

The mentioned Vim options ('linebreak', 'wrap', etc.) have nothing to do with it. They apply to normal buffers; the quickfix buffer as such is not modifiable.

Workarounds

A possible workaround might be to :cd first to a directory that is "closer" to the processed files (or even :set autochdir); this might avoid the long paths in the output.

Alternatively, you may "unmangle" the output by adding a sed stage after the compiler:

let &makeprg .= "| sed -e 's/.../...'"
0
On

If I'm not mistaken, the issue is on pdflatex side. The || mark is a good indication: you'll have one per output line -- in case filename and/or lines numbers are recognized, they'll be fed in between the bars.

So. This means you'll need a way to fix the path names. It'll be better to do it outside vim. I'm not saying this is trivial. I'm just saying that if you can have a program able to fix pdflatex outputs, you'll just be one pipe away from the solution (plus a correct forwarding of error codes...).

If you prefer to implement it in vim script, this is possible. But you'll experience side-effects. In my BuildToolsWrapper plugin I'm able to post-process compilation output in vim side, but the result is far from being perfect. I'm working on getqflist() result, and parse each line. When I found a line where I want to fix the filename, it's not simply about fixing the filename but also about assigning a valid buffer number to it. See this function where I can replace a filename with another one. The magic happens where lh#buffer#get_nr() is used. Still you'd need to implement a vim script able to merge split filenames.

IOW: my understanding is that vim is not involved. It could be used to fix the issue, but IMO this is not the easier path to undertake.