0

This is going to sound weird, bear with me. I am not looking for the regular word wrap, which I already know how to toggle.

Is there any possibility to do a "document wrap" or "text wrap" in Notepad++? Example, imagine a text file with three long lines (line number at beginning):

1 A 111111111 222222222 333333333 444444444 555555555 666666666 777777777 888888888 999999999 000000000 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee fffffffff ggggggggg hhhhhhhhh iiiiiiiii jjjjjjjjj kkkkkkkkk
2 B 111111111 222222222 333333333 444444444 555555555 666666666 777777777 888888888 999999999 000000000 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee fffffffff ggggggggg hhhhhhhhh iiiiiiiii jjjjjjjjj kkkkkkkkk
3 C 111111111 222222222 333333333 444444444 555555555 666666666 777777777 888888888 999999999 000000000 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee fffffffff ggggggggg hhhhhhhhh iiiiiiiii jjjjjjjjj kkkkkkkkk

A "document wrapped" version would look like this:

1 A 111111111 222222222 333333333 444444444 555555555 666666666 777777777 8888
2 B 111111111 222222222 333333333 444444444 555555555 666666666 777777777 8888
3 C 111111111 222222222 333333333 444444444 555555555 666666666 777777777 8888
<wrapped>
1 88888 999999999 000000000 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee 
2 88888 999999999 000000000 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee 
3 88888 999999999 000000000 aaaaaaaaa bbbbbbbbb ccccccccc ddddddddd eeeeeeeee 
<wrapped>
1 fffffffff ggggggggg hhhhhhhhh iiiiiiiii jjjjjjjjj kkkkkkkkk
2 fffffffff ggggggggg hhhhhhhhh iiiiiiiii jjjjjjjjj kkkkkkkkk
3 fffffffff ggggggggg hhhhhhhhh iiiiiiiii jjjjjjjjj kkkkkkkkk

Best is to have Notepad++ automatically do and undo it (similar to Word Wrap toggle). However, we can also use a solution that permanently modifies the file content - perhaps using a regex to cut the excess of lines exceeding a column number, and paste them at the bottom of file.

I can also try a vim feature if any.

  • 2
    I don't think there's a direct way to do this. But both editors have scripting capabilities. – Ouroborus Jan 6 '16 at 6:23
3

Enter the following in your vimrc, then press F12 to use. Press u to undo the changes.

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

This assumes a maximum width of 79 characters. For other amounts, change occurrences of 80 and 79 in the functions above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.