Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing vimdiff to wrap lines?

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?

like image 689
mgouin Avatar asked May 30 '13 15:05

mgouin


People also ask

How do I turn on line wrap in Vim?

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.

How do you get to the next difference in Vimdiff?

You can jump to the "next difference" ( ] c ), but this will jump to the next line with a difference.

What does set wrap do in Vim?

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 .

What is Nowrap in Vim?

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.


1 Answers

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.

like image 172
Nikita Kouevda Avatar answered Sep 17 '22 12:09

Nikita Kouevda