コメントブロックを挿入する Vim スクリプトを書いた

ActionScript のコードにコメントブロックを挿入する Vim スクリプトを書いた。カーソル位置に任意の文字ブロックを挿入するスマートな方法がよくわからず、泥臭い書き方になった。

function! ASCommentWriter()
let c = col(".")
let l = a:firstline - 1
let s = ''
while len(s) < (c - 1)
let s = s . " "
endwhile
call append(l, s . ' */')
call append(l, s . ' *')
call append(l, s . '/**')
endfunction
autocmd FileType actionscript map <C-c> :call ASCommentWriter()<CR>

適当な関数の先頭行にカーソルを移動して、

private function hoge():void {
}

C-c で、

/**
*
*/
private function hoge():void {
}

こうなる。