6

再会,

我正在我的 BASHRC 文件中编写一个简单的脚本,以适应我在上一个问题中无法完全解决的问题:

Vim 中整个目录的 svn-diff 并排视图

我基本上会生成所有具有“已修改”SVN 状态的文件的列表。对于这些文件中的每一个,我想创建一个并排的视觉差异,将其转换为 HTML,然后将其附加到正在运行的 HTML 文件中。

例如:

MODIFIED_FILES="$(svn status | grep "^M" | cut -c9-)"
for i in ${MODIFIED_FILES}; do
  # Generate a side-by-side diff in vim via VIMDIFF
  # Convert via ToHTML
  # Append the HTML file to a file called "overall_diff.html"
done

通过创建文件的干净副本并拥有修改后文件的副本,我可以很容易地完成 vimdiff。

vimdiff起初有一个问题,即:

2 files to edit
Error detected while processing /Users/Owner/.vimrc:
line   45:
E474: Invalid argument: listchars=tab:>-,trail:.,extends:>,precedes:«
Press ENTER or type command to continue

所以,我正在努力克服这个问题,这样我就不必ENTER为列表中的每个文件都点击了。

接下来,我需要vimdiff调用ToHTML命令,然后发出命令将 HTML 缓冲区附加到正在运行的文件中:

:'<,'>w! >>overall_diff.html

简而言之,我该如何:

  1. listchars通过何时vimdiff调用来解决这个问题。运行的时候没有出现这个问题vim,所以不知道为什么运行的时候会出现这个问题vimdiff
  2. 将一个冒号命令列表传递给 VIM,让它在startup不需要更改我的.vimrc文件的情况下运行它们。
4

1 回答 1

1

最后,我创建了一个单独的 VIMRC 文件,该文件vim在运行时通过以下方式传递给命令:

`vim -d file1 fil2 -u my_special_vimrc_file`

function createVimDiff()
{
   # Create some buffers
   TEMP_FILE="./tmp_file"
   VIM_TEMP="./temp.html"
   REVISION=""
   BUFFER_FILE="./overall_diff.html"
   # Get a list of the files that have changed
   MODIFIED_FILES="$(svn status | grep '^M' | cut -c9-)"
   # Remove buffers
   rm "${BUFFER_FILE}"
   for i in ${MODIFIED_FILES}; do
      # Remove intermediate buffers
      rm "${TEMP_FILE}"
      rm "${VIM_TEMP}"
      # Get the current SVN rev number for the current file
      REVISION="$(svn info ${i} | grep Revision)"
      # Echo the name of the file to the report
      echo "FILE: ${i}" >> "${BUFFER_FILE}"
      # Same with the revision number
      echo "${REVISION}" >> "${BUFFER_FILE}"
      echo "<br>" >> "${BUFFER_FILE}"
      # First print a copy of the unmodified file in a temporary buffer
      svn cat "${i}" > "${TEMP_FILE}"
      # Now print the unmodified file on the left column, and the
      # modified file in the right column, so they appear side-by-side
      vim -d "${TEMP_FILE}" "${i}" -u ~/.vimdiff_rc
      # Write the side-by-side diff to a file
      cat "${VIM_TEMP}" >> "${BUFFER_FILE}"
      echo "<br>" >> "${BUFFER_FILE}"
   done
   # Cleanup temporary buffers
   rm "${TEMP_FILE}"
   rm "${VIM_TEMP}"
}

并将以下内容放入我的 VIMRC 文件中:

" Convert the diff to HTML
autocmd VimEnter * silent TOhtml

" Write output to temporary buffer
autocmd VimEnter * w! ./temp.html

" Quit VIM
autocmd VimEnter * qa!
于 2013-05-22T23:17:32.987 回答