0

To make changes in several files I use the following script:

echo search('publications.html"') | normal o<li><a href="./book_series.html">Книжные серии</a></li>
echo search('collections.html"') | d
echo search('photo.html"') | d
wq

Then I do for file in *.html do; vim -e $file < script; done

As a result a string "^Z=86=K5 A5@88" is inserted instead of "Книжные серии". All html files as well as the script itself are utf-8 encoded, and no other problems with Cyrillic revealed. What's going on?

Thanks in advance for any comment!

  • Is *Vim* in utf-8 encoding? Check what ":set encoding?" tells you. – Ben Jun 03 '14 at 17:10
  • Are you sure encoding is utf-8 when launching Vim with the `-e` flag? The help states that when Vim starts in ex mode, *and the -s flag is given*, that Vim skips reading the .vimrc and other things. Perhaps for some reason Vim is skipping that in your case also? You can try using "-S script" instead of "-e ... < script" to start Vim normally. – Ben Jun 04 '14 at 18:46
  • FWIW I tested the first line of your script in my Vim, and it seems to work as intended, not as you report. – Ben Jun 04 '14 at 18:46
  • Thanks, Ben, the -S option really helps! My locale is en_US, and the default encoding in vim is latin1 (e.g. it encodes such a normal mode script written by the -W option), so may be this messes the cyrillic when in Ex mode... – Stas Malavin Jun 05 '14 at 06:50

2 Answers2

0

You probably need to tell Vim to interpret your script as utf-8, even if all the encodings are correct.

Try inserting this line at the top of your script:

 scriptencoding utf-8
Ben
  • 8,725
  • 1
  • 30
  • 48
0

According to the vim_use mailing list response to this same question, multibyte characters are not handled in Vim's ex mode.

Thus, the solution is to not use ex mode at all.

Instead of using:

vim -e $file < script

Use the -S flag to run the script outside of ex mode:

vim -S script $file
Ben
  • 8,725
  • 1
  • 30
  • 48