setg formatprg=cmdfmt\ 80 function! UpdateFormatprg() let &g:formatprg = substitute( &g:formatprg , '\d\+$', &textwidth , "" ) endfunction augroup UpdateFormatprgGroup autocmd! autocmd VimEnter,BufEnter * call UpdateFormatprg() autocmd OptionSet textwidth call UpdateFormatprg() augroup END