0

I am using the ex mode of vim in a script to perform vim regular expression and substitution on text files.

ex $NAME <<EOEX
    :%s/<.\{-}>//g
    :%s/\[.\{-}\]//g
    :%s/&#160;/ /g
    :%s/^Contents$
    :%s/^\d.*$
    :%s/ (.\{1,4\})//g
    :g/^$\n^$/d
    :x
EOEX

I was having issues with the regex :%s/ ([^)]\{-}[^\d0-\d1000].\{-})//g (not shown). I am using it to filter out sets of parentheses and their contents when a character with a value greater than 1000 is found within. This expression would delete all sets of parentheses and content when put into the ex commands above, so I had to call it the following way:

vim $NAME -c ':%s/ ([^)]\{-}[^\d0-\d1000].\{-})//g' -c ':wq'

which works fine. Does anyone have insight into why it works when given to vim with the -c option but not as a command in ex mode?

(Side question: what does the syntax of <<'EOEX ... EOEX' do? I can't find any documentation for it. EDIT: As I understand it now, the use of <<'EOEX ... EOEX' is a Here document and EOEX wraps the string literal that is passed to the ex $NAME command. As far as it seems to me the name of the wrapping identified (in my case EOEX) is arbitrary)

L Lansing
  • 63
  • 5
  • Side answer: `< – Peter Rincker Jun 04 '18 at 21:47
  • 1
    The regular expressions on your ex-command look very different from the second regex the you provided. If you're asking why only the second regex "works" my answer is: because they are completely different. – builder-7000 Jun 05 '18 at 02:44
  • I failed to make it clear but I tried the exact expression within the ex commands and it failed to work the intended way. – L Lansing Jun 05 '18 at 04:59
  • 1
    Side answer: why do you use that notation if you don't know what it does? – romainl Jun 05 '18 at 05:45
  • I'm not sure if your question is rhetorical but I used the notation based on an example of using vim's ex mode from within a bash script, and this is for a learning project rather than professional – L Lansing Jun 05 '18 at 14:13
  • I could be due to your magicnes. Prepend the regex with \m to enforce default magicnes. See `help \m` – XPlatformer Dec 13 '18 at 10:27

0 Answers0