function! Comment() let l:line = "#".getline(".") call setline(".",l:line) endfunction map ## :call Comment() function! UnComment() let l:line = getline(".") let l:pos = stridx(l:line,"#") if l:pos > -1 let l:line = strpart(l:line,0,l:pos).strpart(l:line,l:pos+1) endif call setline(".",l:line) endfunction map !# :call UnComment()