zoning |
2007-06-21
|
The number one irritation I had when editing zone files was having to update the serial number.
After googling for a while, I found some ideas on how to make vim help there. And then I tweaked it a little for my Fedora Core setup, and made it automatic so that it does it when I open the file. That's fine, since only if you save the file (which means, you made a change you want) does it actually update the serial on disk.
Now it's edit - save - reload.
.vimrc snippet:
" define command to increment the SOA in zone files
function! UPDSERIAL(date, num)
if (strftime("%Y%m%d") == a:date)
return a:date . a:num+1
endif
return strftime("%Y%m%d") . '01'
endfunction
command Soa :%s/(2[0-9]{7})([0-9]{2})(s*; serial)/=UPDSERIAL(submatch(1), submatch(2)) . submatch(3)/g
" executed the command when you edit the zone file
autocmd BufRead /var/named/*zone Soa
Nice :-) Months ago, I made a little sh script to do that for a zone, but didn’t even think to make a vim function out of it…
Comment by Simon van der Linden — 2007-06-21 @ 19:17
[…] Here is a nice trick for using Vim to edit zone files. […]
Pingback by Edit zone files with Vim at MontyNet — 2007-06-23 @ 15:51