Forcing vimdiff to wrap lines?

mgouin picture mgouin · May 30, 2013 · Viewed 12k times · Source

When diffing 2 files in VIM, I prefer the lines to be wrapped. However, vimdiff sets wrap to off by default.

Is there a way to set line wrap automatically for every diff?

Answer

Nikita Kouevda picture Nikita Kouevda · Jun 26, 2013

I use the following:

autocmd FilterWritePre * if &diff | setlocal wrap< | endif

FilterWritePre is triggered immediately before a generated diff is written to the buffer, and setlocal wrap< copies the global value of wrap. Of course it's also possible to simply force setlocal wrap.