How to use vimdiff for better diffs
Man, 'diff' is super useful, but 'vimdiff' is like 100x better because it's side-by-side. It is almost enough to make me want to switch from nano to vim as my main text editor!
(I have since been made aware of 'sdiff', but 'vimdiff' still is better, because it highlights the changes *in* each line)
(from https://gist.github.com/mattratleph/4026987)
In summary, *vimdiff file1 file2* and:
- *esc + qa!* to quit
- To navigate between panes *ctl-w w* ('ctl-w' key, then 'w' key)
- To navigate up and down to differences. To move to the previous change use: *[ c* ('[' key , then 'c' key). To move to the next change use: *] c*
- regular vi keys work, of course *h j k l* keys to navigate, *ctl-f* page forward, *ctl-b* back (and you can use cursor and paging keys as well), *g g* Go to top the file, *G* Go to bottom of the file.
- If you edit one file using * i, a, o* or other commands: *dp* Puts/gives the change at your cursor to the other file; *do* Obtains/gets the change from the other file; *:diffupdate* Forces vim to update the diff highlighting (should vim fall behind in updating); The more familiar you are with Vim, the easier and more naturally you'll be able to modify your text files.
When you examine the files, you'll probably notice that a
lot of the text is folded. That is, if there is a lot of
text between the files that is identical, there is not much
point in showing it all, so it's folded away.
====WORKING WITH TEXT FOLDING====
(The least you need to know for now.)
- *za* Toggles a text fold open/closed.
- *zo* Unfolds (opens) a fold.
- *zc* Closes (folds) a fold
- *zR* Unfolds all folds.
- *zM* Folds up all folds.
- *zn* Turns off the text folding feature.
- *zN* Turns text the folding feature back on.