Soft wrapping text
Long lines of text can be wrapped if they don’t fit inside the window. By default, Vim will happily split in the middle of a word. This episode demonstrates how to use the ‘linebreak’ option to make Vim break lines without breaking words.
Default wrapping unsatisfactory.
:set wrap nolist linebreak
:set list breaks the linebreak.
:set nowrap breaks the linebreak.
Add to .vimrc:
nmap <leader>l :set list!<CR> nmap <leader>w :set wrap!<CR> command! -nargs=* Wrap set wrap linebreak nolist
k don’t work as you might expect. (Also
Expected behaviour from:
gj gk g0 g^ g$
) for moving back/forward through sentences.
Demonstrate delete sentence, and swap sentence order.
C on last sentence.
A from anywhere in paragraph.
Knowing what’s what
:set showbreak=> :set showbreak=…
To insert the elipsis:
If I switch line numbering off, it’s actually very hard to tell whether you are looking at numbered lines or display lines. By default, the ‘showbreak’ setting is blank, but if you set this to a string then it will be printed at the beginning of each continued line. I like to use the unicode elipsis character. If you are working with softwrapped text, I would suggest that you enable either line numbering or showbreak to prevent confusion.
The information in this video is summarized in the accompanying shownotes.
Demonstrate TextMate’s ‘Soft Wrap’ + ‘Use window frame’ option. Then show ‘Soft Wrap’ + 78 and so on. Not possible in Vim with soft wrap.
With vertical split, resize current width with:
:vertical resize N
Set the width of the window with: