VIM - passing a list of colon commands through the command line

Good afternoon,

I am writing a simple script in my BASHRC file to post something that I could not solve in the previous question:

Vim svn-diff side view for entire directory

I basically generate a list of all files with the status of “Modified” SVN. For each of these files, I want to create a side-by-side visual diff, convert it to HTML, and then add it to the HTML executable.

eg:

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 

I can run vimdiff quite easily by creating a clean copy of the file and getting a copy of the modified file.

vimdiff has the problem first, namely:

 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 

So, I'm trying to get past this, so I don't need to hit ENTER for every file in my list.

Then I need vimdiff call the ToHTML command, and then issue the command to add the HTML buffer to the working file:

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

In short, like me:

  • Skip this issue with listchars when vimdiff is vimdiff . This problem does not occur when I start vim , so I do not know why this happens when I start vimdiff .
  • Pass the list of colon commands in VIM to run them in startup without requiring a change to my .vimrc file.
+4
source share
1 answer

In the end, I created a separate VIMRC file that is passed to the vim command at runtime, via:

 `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}" } 

The following has been added to the VIMRC file:

 " Convert the diff to HTML autocmd VimEnter * silent TOhtml " Write output to temporary buffer autocmd VimEnter * w! ./temp.html " Quit VIM autocmd VimEnter * qa! 
+1
source

Source: https://habr.com/ru/post/1482270/


All Articles