Ayman
Ayman

Reputation: 11585

How to highlight lines changed since the last save of a file in Vim?

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.

Upvotes: 25

Views: 10859

Answers (4)

DrAl
DrAl

Reputation: 72616

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!

Upvotes: 23

From Vim Wiki:

Type :changes to display lines where changes occurred.

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

Upvotes: 10

UncleZeiv
UncleZeiv

Reputation: 18488

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.

Upvotes: 0

chillitom
chillitom

Reputation: 25686

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).

Upvotes: 2

Related Questions