VIM Convert Text to URL with Search/Replace -


i have document contains long filenames, followed hyphen, followed description of contents of file. files pdfs. converting document page on our website, has filename, should link file, followed description of file contents.

i'm versed in basics of vim, advanced search/replace i'm lacking in. i'd convert each filename link filename. example:

webadapt_prod_int_10.1_install.iis7.2008r2.pdf - step step instructions installing arcsde 10.1 oracle on ‘test’ environment, including configuration notes. 

should convert to:

<a href="documents/webadapt_prod_int_10.1_install.iis7.2008r2.pdf">webadapt_prod_int_10.1_install.iis7.2008r2.pdf</a> - step step instructions installing arcsde 10.1 oracle on ‘test’ environment, including configuration notes. 

there 30 of these documents, going line-by-line time consuming (though time response i'll have done it). i'd know how next time i'm given big text file needs formatting.

thanks in advance!

try this:

:%s!\v^\s+\.pdf!<a href="&">&</a>! 

please note above doesn't try html entities though. see vim tips wiki possible solution if that's concern.

edit: way works:

  • :% - filter entire file
  • s!...!...! - substitute
  • \v - set "very magic" syntax regexps
  • ^\s+\.pdf - match 1 or more non-spaces @ begging of line, followed .pdf
  • <a href="&">&</a> - replace link: & matched string (that is, filename).

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -