I want to create a function that I can call to replace a specific string pattern with md5sum
of current buffer.
I have no experience writing VimL before and can't figure out the way to do it.
This is what I roughly have in my mind:
" Calculate text hash and replace the old one
function! HashBuffer()
:redir @a
" Will this work? Is this a buffer contents or previously save file?
:!md5sum %
:redir END
" replace with @a (How?)
%s/%%%HASH.*%%%/%%%HASH-XXXXXXXXX%%%/
endfunction
Usage example:
Let say I have a file, I am working on
# %%%HASH-XXXXXXXXX%%%
the content of file ....
....
..
I want the hash to be calculate when I manually :call HashBuffer()
# %%%HASH-1d4171a91c31af2c59acb89a042836e1%%%
the content of file ....
....
..
It's obviously not working but I don't have any idea what to do next.