decvers.vim

3 views
Skip to first unread message

markem

unread,
Jan 1, 2026, 2:35:15 PM (16 hours ago) Jan 1
to vim_use
First, sorry for top posting. I was just replying to my email. Live and learn as they say. Now I know to not do that. I'll try to always go to the list and post there from now on. Again - very sorry.

I decided to post my decvers.vim script here in case anyone out there would like to use it. Why is it called decvers.vim? The "dec" part comes from the Digital Equipment Corporation or DEC name. The "vers" is for the word "version". Thus decvers.vim.

What it does is to make a copy of your source code automatically. It does this by adding a semicolon (;) to the end of the file name and then adding a five digit number to the end of the file name also. (So like "00000" or "00001" and so on.) Each time you edit the file, it adds one new number onto the end of the save (I have it set to do this three times). When you reach the maximum number of saves the earliest version is removed. Thus, you don't over run your system with backup copies. The interesting thing about this is that this shows you how you could do an automated version number in the program but I'm just interested in just having a backup I can return to if somehow I manage to muck up the current version. Anyway, here is the code. It is not perfect but it works. :-)

decvers.vim
" Note that tab stops should be at 4 spaces. Also I left all of my ECHO commands
" in - in case anyone wants to play around with the script. This is free software and
" can be used anywhere for anything. It is basically public domain. MEM.

Beginning of script

" -*- vim -*-
" @(#) $Id: decvers.vim,v 0.1 Mark Manning
"
" Notes: Please note that I am using five zeros as the size of the
" backup file names. So we have 00000 and then 00001, 00002, etc...
"
let path_name=expand("%:p")
let file_name=expand("%:t")
"
" Now see about getting all of the iterations of the current file
"
let cmd ='dir /b/on "' . path_name . ';*"'
let x=systemlist(cmd)
" let x=split(x[0],"\n")
let ary_len=len(x)

" echo "CMD = " . cmd
" echo "X = "
" echo x
"
" Now get the highest number of the iterations
"
let l=0
let high_num=0
if( ary_len > 0 )
while( l < ary_len )
let a=split(x[l],";")
" echo "A = "
" echo a
let a_len = len(a) - 1
let a_last = a[a_len]
" echo "a_last = " . a_last
if( a_last >= high_num )
"
" For unknown reasons a_last is never higher than high_num
"
" echo "a_last = " . a_last
let high_num = str2nr( a_last, 10 )
" echo "High_num = " . high_num
else
" echo "a_last = " . a_last
let high_num = str2nr( a_last, 10 )
" echo "High_num = " . high_num
endif

" echo "L = " . l
let l += 1
endwhile
endif
"
" Make a new filename (ie: full file name PLUS .(high_num+1)
" In other words - make a new filename with the backup number one
" higher than the highest backup number. Example A.BOB;00001
"
" echo "High_num = " . high_num
let high_num = high_num + 1
" echo "High_num = " . high_num
let ext = printf("%05d", high_num )
" echo "High_num = " . high_num
" echo "ext = " . ext
let new_path = expand("%:p") . ";" . ext
"
" Now save the file to the new file name we just made.
"
" echo "new_path = " . new_path

let cmd = 'copy "' . path_name . '" "' . new_path . '"'

let output = systemlist( cmd )

" echo "CMD = " . cmd
" echo "Output = "
" echo output
"
" Now get rid of any extra backup files we might have. MAX_BACKUPS is set here.
"
let max_backups = 3
"
" Now do the above again to get all of the backup files
"
let cmd ='dir /b/on "' . path_name . ';*"'
let x=systemlist(cmd)
" let x=split(x[0],"\n")
let ary_len = len(x)

" echo "CMD = " . cmd
" echo "X = "
" echo x
"
" If the ary_len is greater than max_backups - get rid of
" the lowest numbers because those are the oldest.
"
if( ary_len > max_backups )
let l=0
let ary_len = ary_len - max_backups
if( ary_len > 0 )
while( l < ary_len )
let a=split(x[l],";")
" echo "A = "
" echo a
let a_len = len(a) - 1
let ext = a[a_len]
let file_name = expand("%:p") . ";" . ext
let cmd = 'del "' . file_name . '"'
let output = systemlist( cmd )

" echo "CMD = " . cmd
" echo "Output = "
" echo output
" echo "L = " . l

let l += 1
endwhile
endif
endif

finish

End of Script

Have fun with it!
Reply all
Reply to author
Forward
0 new messages