This question might be very abstract, so apologize in advance.
I have a log file that contains lines that obey to a certain pattern (filename,line,function, trace statement). For example
file1.cpp, 12, function1, "we are in function 1"
file2.cpp, 104, add, "add function"
another_file.cpp, 300, function2, "This is a trace"
What I would like to have is the vim editor to split in two windows. One window has the log file and everytime I move my cursor to a trace line, the other window will open the real file in the correct line of code.
For example in the top window my cursor is at line
file2.cpp, 104, add, "add function"
and the second (vim is split in two windows) window opens file2.cpp in line 104 (at the center of the second window).
Is there any chance to use a structured file (a log file) as a “navigator” for the source code?
If yes, how can we do it in vim? If not, let’s make it! (but I would not like to reinvent the wheel 🙂 )
What you describe is called a quickfix window in Vim. You may be familiar with it from the results of the
:makecommand. You can open a quickfix window using:cfile. The format is determined by theerrorformatvariable. Look up Vim help on these for more details.For your example (filename, line, function, trace statement) you could do:
The gratuitous triple backslashes are there to get around escape sequences in the
:setcommand. The format translates to%f\,\ %l\,\ %m.Alternatively, you could output your log in the gcc format. In that case, the default
errorformatwould be able to parse it, and all you would have to do is open it with the:cfilecommand.After loading, you can view the log using the
:clistor:copen.