1

I am creating a script that grabs all links from a web page's source code. I would like to call Vim from a bash script and the easiest way for me to do that is to use a vim script.

I have a file called 'script.vim':

:g!/https:\/\//d
:%norm!/https^Mdi"Vp
:wq!

I am deleting every line without https and the norm command is being used to remove all text that is not inside double quotes & containing https.

Everything works except the ^M and I'm not sure how to go about replacing that in the script file.

For extra info, I'm calling the script file like so: vim websitecode.txt -s script.vim

Simply put, I need a replacement for ^M so the norm command will work in a script.

1 Answer 1

1

As a replacement of:

:%norm!/https^Mdi"Vp

I would propose you:

:exe '%norm!/https' . "\<CR>" . 'di"Vp'

The "" converts escpaped sequence \<CR> into ^M.

3
  • 1
    It's working, but oddly enough it seems to only be removing one line at a time. Any idea how to fix that?
    – ex7lted
    Commented Aug 30, 2022 at 15:25
  • My mistake :-| I forgot % to range over all the lines ;-) Commented Aug 30, 2022 at 15:26
  • 1
    Haha I totally wasn't thinking about it either. Thank you so much
    – ex7lted
    Commented Aug 30, 2022 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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