amaz1ng
amaz1ng

Reputation: 13

How can I add or/and modify a version-number in Vimrc autocmd

I love to work with Vim. I use the autocmd in ~.vimrc like:

  :fun LastMod()
  :  if line("$") > 20
  :    let l = 20
  :  else
  :    let l = line("$")
  :  endif
  :  exe "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " .
  :  \ strftime("%Y %b %d")
  :endfun

The Question is: How can I add or/and modify a version-number like:

from Version: v1.345 to Version: v1.346

In action when I write a shell-Script, I like to automaticly modify some Lines:

#!/bin/bash
# Last modified: <date time>
# Version: v1.23-<n>
#

(maybe thats a little more clear)

Upvotes: 1

Views: 149

Answers (2)

Sato Katsura
Sato Katsura

Reputation: 3086

Edit to match the sample you posted:

:%s/\m\%<21l^# Last modified: \zs.*/\=strftime('%Y %b %d')/
:%s/\m\%<21l^# Version: v\d\+\.\d\+-\zs\d\+/\=submatch(0)+1/

Upvotes: 2

Kent
Kent

Reputation: 195209

what I mean is: in a script like: #!/bin/bash # Last modified: # Version: v1.23<#>

I think you want to change the version in your shell script(s). Assume that you have:

#!/bin/bash
#Last modified: whatever
#Version: v1.234
#other stuff
...

You can have this line in your .vimrc:

let @v="gg/Version:/\<cr>2E\<c-a>"

Then everytime you open your shellscript, pressing @v will make the version number be incremented by 1. Well the 1 means for example, from v1.1099 to v1.1100

In fact it created a macro.

Upvotes: 0

Related Questions