Why use 0d_ in DiffOrig in Vim?

In the Vim online manual, it :help DiffOrig will show the recommended sequence of commands for receiving changes to the current editing file.

There he is:

command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
                   \ | wincmd p | diffthis

I wonder what the effect is 0d_. I tried 0d_in normal mode, it works like dd, but I can’t understand why it is used here.

+5
source share
1 answer

Let's explain this a bit: suppose you have the original foo.txt containing (with line numbers):

1 a
2 c
3 d
~

You added a line containing "b" between lines 1 and 2:

  • :vert newcreates a new empty buffer in a vertical split ( :help :new)
  • :set bt=nofilemakes a buffer from scratch ( :help 'bt'). Note:

    1 a  | 1 ·<cursor here
    2 b  | ~
    3 c  | ~
    4 d  | ~
    ~    | ~
    
  • :r # , (#), . , . (:help alternate-file).
    :help :r , . :

    1 a  | 1
    2 b  | 2 a
    3 c  | 3 c
    4 d  | 4 d
    ~    | ~
    
  • :0d_ . 0, , :1d_. :help range :

    0 () 1

    _ , . :help :d :d ex, linewise.

.

+8

All Articles