美好的一天,
我正在BASHRC文件中编写一个简单的脚本,以容纳我在上一个问题中无法解决的问题:
Side-by-side view in Vim of svn-diff for entire directory
我基本上生成了一个具有“已修改”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
简而言之,我该怎么做:
listchars
时,使用vimdiff
解决此问题。运行vim
时不会发生此问题,所以当我运行vimdiff
时,我不知道为什么会这样。startup
运行,而无需更改我的.vimrc
文件。答案 0 :(得分: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!