[20230206]vim diff 小技巧.txt

lfree發表於2023-02-09

[20230206]vim diff 小技巧.txt

--//昨天看了一個vim diff小技巧,在編輯過程中看看改動那些.
--//連結:

7: Show diff before saving the file

We have all been there. "I modified this file, but don't know what I changed and now I am afraid the change will cause
unexpected issues down the road."

The remedy to this problem is to view the difference between the buffer and the file.

To do so, execute the following command in Vim itself:

:w !diff % -

Let's break this down so you understand what is happening...

    :w is the Vim command to save/write. In this particular scenario, where no file name is specified in the command,
     the output is written to the STDIN (standard input) file.
    :!<command> is the syntax for executing a shell command. In our case, we are running the diff command in our shell.
    % represents the name of the current file that is unmodified. Try this with :!echo %.
    - is the STDIN file for the diff command.

So, this command first writes all the [unsaved] content to the STDIN file. Then the diff command reads the current file
(%) and comparing it against the STDIN (-) file.

This command roughly equates to this shell command -> diff <original-file> <Vim's STDOUT>.

--//in windows , because space ,use "%" 代替 % ,注意w ! 之間存在空格,不然建立一個人新檔案"dff -Nur".
:w !diff -Nur "%"  -


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2934659/,如需轉載,請註明出處,否則將追究法律責任。

相關文章