Sometimes, when faulty outputs from compilations of C++ files/projects are to long, I like to redirect that output to a file, so that I can inspect it side-by-side with each of the offending files in turn.

The weak point of this, is that I lose the useful text format (colors, bold, ...) of errors and warnings, which really helps me spot the errors when quickly scrolling through the log file.

Thefore my questions are:

  • Is there a filetype I can set on those log files so that they are shown with those coloring?
  • Or maybe I should redirect the output in another way that preserves some raw control sequences that the terminal uses to color text? (I know this is offtopic, but I'm asking here because I'd prefer the first approach, which is on topic.)

I know I can open :term and run g++ there, so I have all Vim movement commodities in that terminal by pressing Ctrl-WN, but I'm interested anyway.


It is not quite answering the question, but you can run :make to compile from vim, and will allow you to jump to the location of the first error. Then, you can run :cwindow to display the quickfix window, to have the list of errors in a split.

The quickfix will have some color highlight:

enter image description here

Bringing your cursor on an error line and pressing return will make you jump to the erroring line.

I have an alias which does that for me (compiling + displaying the result):

nnoremap <leader>m :make<CR><C-o>:cwindow<CR>

For more info:

:help :make

:help quickfix-window

:help quickfix

The quickfix window content is a buffer like any other, so would you need, you can for exemple save its content (the compilation output) is some file too.

  • 2
    You can even open the error file with -q; you may have to retroactively set errorformat to get the right quickfix list though – D. Ben Knoble Nov 25 '20 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.