1

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)

amaz1ng
  • 13
  • 5

2 Answers2

2

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/
Sato Katsura
  • 3,066
  • 15
  • 21
0

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.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • Thanks for successfully explaining the macro-function. I have tryed it out and it works fine. But isn't there a way to make it automaticly like the "Last modified: "-function? – amaz1ng Feb 08 '17 at 06:03
  • @amaz1ng, you can make the two modifications in one macro. – Kent Feb 08 '17 at 08:45