4

I'm trying to vimify a task of editing bulk file move commands.

I'm using Fossil-SCM to manage a bunch of files and have some changes in directory structure. To get SCM to grasp the move, I have to supply the command fossil mv oldname newname for each file.

Since it is some hundrets of files and different directories that changed, I have saved the output of fossil into a file showing on each line:

MISSING    /path/to/missing/file

And I want to change that to

fossil mv "/path/to/missing/file" "/path/to/missing/file"

From there on theres nothing left than walk manually through the lines and change directory names as needed.

However, this conversion could safe much time.

I tried using RegEx, but somehow seems VIM to not accept the grouping... I tried:

:1;$s/^MISSING (.*)$/^fossil mv \"\1\" \"\1\"$

But as soon as i try to use parentheses in the search definition, vim states the pattern could not be found. So what would be the most vimic way to solve this?

9

Usually, vim uses something akin to Basic Regular Expressions (BRE). You need to use \( and \) instead:

:%s/^MISSING *\(.*\)$/fossil mv "\1" "\1"/

Or prefix the pattern with \v. From :he regexp (more specifically, :he /magic):

after:    \v       \m       \M       \V         matches
                'magic' 'nomagic'    
          $        $        $        \$         matches end-of-line
          .        .        \.       \.         matches any character
          *        *        \*       \*         any number of the previous atom
          ()       \(\)     \(\)     \(\)       grouping into an atom
          |        \|       \|       \|         separating alternatives  
...

So the magical expression would look like:

:%s/\v^MISSING *(.*)$/fossil mv "\1" "\1"/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.