1

I'm trying to use errorformat to shorten the code-compile-code loop. My setup is such:

  1. MacOS where my editor (vim) sits. Along with git, etc. Everything except the compiler (VCS).
  2. A Ubuntu VM that runs on the same computer.
  3. A folder that's shared between the two. It mounts as ~/projects/my_proj on MacOS and /media/psf/projects/my_proj on the VM.

My workflow:

  1. Edit code on MacOS.
  2. Send SSH command to VM to compile the code and dump the results in /media/psf/projects/my_proj/results:
ssh remote_user@remote_host cd /media/psf/projects/my_proj/results; vcs <options_string> -f filelist.f
  1. Examine results of log and edit errors.

In step #3 of the workflow above, I would like to use quickfix to scan the log file. I've found that :cfile works to load the file.

However, the compiler on the VM writes out file paths using the absolute path:

/media/psf/projects/my_proj

When I try to read this into vim on MacOS, /media/psf/projects doesn't exist. And vim cannot display the errors.

What would be the best way (vimscript? macro?) that I can preprocess the log file (replace all folder paths), spit out an intermediate logfile and run :cfile on that?

4

1 回答 1

3

您问题的信噪比很低。以下是我对您的问题的理解:

  • 你有一个带有共享目录的虚拟机,
  • 您项目的代码位于该目录中,
  • 目录/media/psf/在虚拟机和~/projects/foobar/主机中,
  • 当编译器输出错误时,路径以/media/psf/,
  • 当您在主机上的 Vim 中提取这些错误时,这些错误/media/psf/不存在,因此 Vim 无法跳转到错误,
  • 在将错误列表输入 Vim 之前或期间,您/media/psf/需要一种翻译方法。~/projects/foobar/

以下解决方案假定从 VM 检索到的错误列表保存到名为errorfile共享目录根目录的文件中:

:cexpr readfile('~/projects/foobar/errorfile')->join("\n")->substitute('/media/psf/', '~/projects/foobar/', 'g')

参考:

:help :cexpr
:help readfile()
:help join()
:help substitute()

FWIW,告诉您的编译器将错误列表写入上述文件将允许您从工作流程中删除 SSH 步骤。

于 2020-07-30T07:26:53.593 回答