Saturday, April 30, 2011

determine if a certain line occurs in a file

i'm trying to write a small vim function which will modify a copyright
year each time i'm opening a file. here is what i came up with

function UpdateCopyrightYear()
let l:cmd = 's/\(\d\+\)/\1-'.strftime("%Y").'/'
g/Copyright 2010, Company E/exec l:cmd
endfunction

the problem that i'm facing right now is if the pattern is not in the
file, i get an error message, E486: Pattern not found Copyright 2010,
Company E. is there a way to tell vim not to execute the command if
pattern is not found, say something like:

function UpdateCopyrightYear()
let l:cmd = 's/\(\d\+\)/\1-'.strftime("%Y").'/'
if g/Copyright 2010, Company E/
g/Copyright 2010, Company E/exec l:cmd
endif
endfunction

thanks, any help is appreciated.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment