25

Is it possible to have Vim highlight the changed lines since the last save? I know it can be done with version control, but can it be done without? I do not want to use any version control system, because the code I work on does not have that.

I think, UltraEdit has something like that.

ib.
  • 27,830
  • 11
  • 80
  • 100
Ayman
  • 11,265
  • 16
  • 66
  • 92
  • It sounds like you are trying to make vim be a version control system, so in effect you are trying to add a VCS. Why not use a tool designed for that task? – William Pursell Aug 27 '09 at 12:05
  • 2
    Although I've given a more direct answer to your question, I have to agree with William Pursell that there would be a lot to be said for using a VCS, even if it's just one with the repository held locally to the working folder of the project (like bazaar, mercurial or git). There's no server to set up and it gives you an invaluable undo facility beyond what can be done with any editor. Just my opinion though... – DrAl Aug 27 '09 at 12:29
  • 1
    I do have svn for most of my other projects, and I know how valuable it is, but not this particular one. And I do not want to setup a repository for some files. The answer by AI is just want I needed. – Ayman Aug 27 '09 at 17:42
  • Integrating a light layer of VCS into the editor helps because it keeps you from switching to a terminal or other program just to see a summary of your changes. It's a workflow optimization thing. – Steven Lu Jul 02 '13 at 04:03

4 Answers4

23

Straight from Vim documentation (see :help :DiffOrig):

if !exists(":DiffOrig")
    command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
          \ | wincmd p | diffthis
endif

Then just do :DiffOrig et voila!

ib.
  • 27,830
  • 11
  • 80
  • 100
DrAl
  • 70,428
  • 10
  • 106
  • 108
  • 1
    Use `:diffoff` to switch this off again. There is already some discussion on `:DiffOrig` on Stackoverflow, eg. [here](http://stackoverflow.com/questions/6426154/taking-a-quick-look-at-difforig-then-switching-back). – glts Jun 26 '12 at 19:08
10

From Vim Wiki:

Type :changes to display lines where changes occurred.

Use g; and g, to jump to changed lines.

ib.
  • 27,830
  • 11
  • 80
  • 100
2

if you're using CVS, Git or Subversion for your source files then this plugin script will do what you want: VIM svndiff

it probably wouldn't be too difficult to get it to work from a diff of a temp file instead (if it doesn't have that option already).

chillitom
  • 24,888
  • 17
  • 83
  • 118
0

You need a temporary file to compare against, and I'm not sure that Vim has one (it has a .swp file but I don't know how it could be exploited).

Anyway a (quirky) possibility could be to use the generic SCMdiff and write a commandline script that performs a diff between the current file and a .tmp version of it. You should also map a command that saves the .tmp file for the current version, maybe calling automatically each time you save.

UncleZeiv
  • 18,272
  • 7
  • 49
  • 77