Open a new .sh file in vim, to begin syntax highlighting. Type some text, and insert the following text: url="http://bugs.gentoo.org" output="'This'odd\"filename.txt" outputFile="--output-document=`echo "${output:9}" | sed "s/['\\"]//g"`" wget --output-document="$outputFile" "$url" The text after the outputFile line will be colored as a string literal, closing the literal with the quotation after the =. To recover the correct highlighting, the outputFile line will need to appear three times. You can reduce this to twice if you put a backslash before the single quote in the sed script. You may think this is odd syntax.. and I agree, it is, requiring the double backslash to escape the quotation mark. Nevertheless, bash requires this to run, and therefore I consider the error in vim's syntax highlighting. I'm using data from webpages to determine filenames of files that will be downloaded, so I need to handle a few permitted characters that don't work on the filesystem. Reproducible: Always Steps to Reproduce: 1. open vim 2. insert text: url="http://bugs.gentoo.org" output="'This'odd\"filename.txt" outputFile="--output-document=`echo "${output:9}" | sed "s/['\\"]//g"`" wget --output-document="$outputFile" "$url" 3.examine wget --output-document line. Repeat the outputFile line to resolve the error, in some fashion
Well, changing to this line makes highlighting work properly, and works almost exactly the same as your code (only that statement is now run in a subshell): outputFile="--output-document=$(echo "${output:9}" | sed "s/['\\"]//g")" Also, for that simple of a sed, why not just use the string manipulation powers of bash? output=${output:9} # get all but the first 9 chars of the name output=${output//\'/} # remove all single quotes output=${output//\"/} # remove all double quotes I'm sure there're a few other ways bash would let you do this as well. Also, your current code would call: wget --output-document=--output-document=cleanfilename.txt Which probably doesn't make wget happy. That'll avoid the ugly echo|sed stuff altogether (and make running this faster, since you aren't forking any other processes). But bash scripting issues aside, this is the sorta bug that would be better reported to vim upstream, since it's a bug in the sh.vim script they distribute. Here's their instructions for submitting a bug report (taken from their FAQ): 2.6. Where can I report bugs? First collect the required information using the following command: :source $VIMRUNTIME/bugreport.vim Now send the resulting text from the above command to the bugs@vim.org e-mail address. The Vim Development mailing list (see above) is a good place to discuss general bugs. If the bug you find is with syntax highlighting or some other "added feature" (i.e. not directly programmed into vim), attempt to inform the maintainer of that feature. For more information, read :help bug-reports I'm going to close this as UPSTREAM for now. When a patch is made to fix this, I'll make a new gentoo release of vim.