Thursday, December 28, 2006

VIM: Auto commenting for function closing braces

You can use the following code to perform auto commenting. Put this in your .vimrc file.
This script will add the following comment after }//
}// end

" abbrevation for doing commenting at end of functin curly bracket end "}"
" use }// to comment the code
iab }// ^[:call CurlyBracket()^MA

function CurlyBracket()
let l:my_linenum = line(".")
let l:linenum = searchpair('{', '', '}', 'bW')
let l:line = getline(l:linenum - 1)
let l:str = strpart( line, 4 )
sil exe ":" . l:my_linenum
sil exe "normal a} // end " . str
endfunction

No comments:

Post a Comment