On Jul 4, 2:03 am, Jeri Raye <[email protected]> wrote:
>
> I want to let vim execute this myscript.vim only when the first line
> of the memfile.psm file contains more then one word.
> Otherwise it should do nothing, because it has already done this time
> the last ime.
> How do I do that?
>

vim -c "if getline(1)=~'\v^\W*\w+%(\W+\w+)+\W*$' | source myscript.vim
| endif" memfile.psm

This will set up Vim to, right after launching and finishing all it's
startup stuff, check the first line in the file to see if it matches a
regular expression crafted to match:

^ - beginning of line
\W* - zero or more non-word characters
\w+ - one or more word characters (first word)
%(\W+\w+) - one or more non-word characters followed by one or more
word characters (second word)
+ - repeat last match one or more times (to allow matches on lines
containing more than 2 words)
\W* - zero or more non-word characters
$ - end of the line

If the line matches, it sources your script.

The regex can probably be simplified, but will work as-is. Note the
use of \v (:help /\v) to eliminate the need for escaping some of the
special regex characters.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to