1

I know that it is possible to jump to last change in vim, like this :

`. 

-- That is: a backtick, followed by a dot.

I would like to know if it is possible to get a history of changes made or at least show last change made, not just jumping to it - is there a way to use diff to help display changes?

Also, how many changes is stored?

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
serup
  • 3,676
  • 2
  • 30
  • 34

2 Answers2

2

You can list the changes by typing :changes or use the :DiffOrig after putting in your .vimrc the command below to see the changes made to the original file:

command! DiffOrig rightbelow vertical new | set bt=nofile | r # | 0d_ | diffthis | wincmd p | diffthis

Explanation:


  • command DiffOrig rightbelow vertical new

Create a new command named DiffOrig which will split a new empty vertical window and move cursor to it.

Now we have two buffers if you type :buffers or :files or :ls it will list all the existed buffers where each one has a unique id number and a name:

. The current buffer (where the cursor is active) is called %

. The buffer where the cursor was previously is called #

  • set bt=nofile

Set the buffertype of the new buffer to nofile

  • read #

Put the content of the alternate buffer (original one) in the current buffer (%) (after the line where the command is executed) (the content will be the last saved status)

  • 0d_

Delete the line to move the content one line up.

  • diffthis

Activate diff in the buffer in order to display the changes.

  • wincmd p

Move to the other buffer window (the command is same as ctrl-w p)

  • diffthis

Activate diff in this buffer too to display the changes.

  • 1
    it seems this answer is the best, especially the :changes which was what I was really looking for - thanks – serup Dec 28 '16 at 12:40
  • any chance that you could explain in detail what this command is actually doing? – serup Dec 28 '16 at 12:45
  • the command line you posted consists of several commands, I just wanted to know a bit more about how it is working – serup Dec 28 '16 at 12:52
0

it seems that this have already been answered in :

see changes in vim before save

after adding following to my .vimrc :

function! s:DiffWithSaved()
  let filetype=&ft
  diffthis
  vnew | r # | normal! 1Gdd
  diffthis
  exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()

then I can use following command :

:DiffSaved

and I will get something like this:

example of vim in terminal

in example I changed F to f

Community
  • 1
  • 1
serup
  • 3,676
  • 2
  • 30
  • 34