Reputation: 30492
Is it possible in VIM to highlight parts of some text the user has added/changed in a file?
Following situation demonstrates this:
and so on.
I am looking for a most compact solution - should it be an option or a simple vim script.
Upvotes: 0
Views: 97
Reputation: 3064
You can keep a backup of the original file, then :vsplit file.bak
, execute :diffthis
in both buffer.
Upvotes: 1
Reputation: 7307
Vim tracks and maintains an undo history which records all changes made to a file. You could use a plugin like 'sjl/gundo.vim' which gives you the ability to view diffs of subsequent changes to a file (very handy).
If you keep the file under vcs, like git, you can also see diffs. For git you should use 'tpope/vim-fugitive' and then you can view diffs in several different ways, most common being :Gdiff
Upvotes: 1
Reputation: 172540
For such difference reporting, it's best to use a revision control system. The numbers from your question then map cleanly to revision numbers, and there are indeed plugins that can show those differences (also across multiple revisions, and in the form of log messages, etc.)
The vcscommand.vim - CVS/SVN/SVK/git/hg/bzr integration plugin supports all widely-used systems, and offers this in the form of a vimdiff or a unified diff in a scratch buffer. There are also plugins (vim-signify - Advanced plugin for showing VCS diffs in the SignColumn, or GitGutter for Git) that visualize this neatly in the sign column.
If you don't / can't use a revision control system, there are plugins that show the differences to the saved version (but not across saves, as this information is not available).
If you want a lightweight, Vim-only revision control system solution that can do this, have a look at my writebackup plugin and writebackupVersionControl plugin plugins, which offer vimdiffs / unified diffs, too, without requiring an underlying revision control system.
Upvotes: 1
Reputation: 8806
The VIM plugin vim-gitgutter will indicate lines that have been added / removed / changed if the file you are editing is part of a Git repository. This might meet your needs.
Upvotes: 1