Digite o seguinte no seu vimrc e pressione F12 para usar. Pressione u para desfazer as alterações.
nmap <F12> :call FileWrapOuter()<CR>
function! FileWrapOuter()
while FileWrap()
endwhile
endfunction
function! FileWrap()
" Go to end of file and set mark 'a'.
norm G
norm ma
let w:madeChange = 0
" Call FileWrapInner() for each long line.
:%g/.\{80\}/call FileWrapInner()
if w:madeChange
" Return to mark 'a' and add <wrapped>.
norm 'a
norm o<wrapped>
return 1
endif
return 0
endfunction
function! FileWrapInner()
" Copy current line into 't' buffer.
norm "tyy
" Delete anything in line after 79th character.
norm 0
norm 79l
norm d$
" Paste 't' buffer at end of file.
norm G
norm "tp
" Delete first 79 characters.
norm 0
norm 79x
let w:madeChange = 1
endfunction
Isso pressupõe uma largura máxima de 79 caracteres. Para outros valores, altere as ocorrências de 80
e 79
nas funções acima.