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?
If you want to wrap lines in a specific area, move the cursor to the text you want to format and type gq followed by the range. For example, gqq wraps the current line and gqip wraps the current paragraph.
You can jump to the "next difference" ( ] c ), but this will jump to the next line with a difference.
If you want to make Vim wrap long lines to fit in the window, you first have to enable :set wrap . By default Vim will break lines at exactly the width of the window, which causes some words to be split across two lines. To prevent this from happening, you can enable :set linebreak .
Answer: To get Vim to not wrap text, issue the "vim set nowrap" command, like this: :set nowrap. By default vim will wrap long lines in the editor, but this command changes that display, so long lines will now go off-screen to your right.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With