ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [20230206]vim diff 小技巧.txt

[20230206]vim diff 小技巧.txt

原创 Linux操作系统 作者:lfree 时间:2023-02-09 21:41:19 0 删除 编辑

[20230206]vim diff 小技巧.txt

--//昨天看了一个vim diff小技巧,在编辑过程中看看改动那些.
--//链接:https://linuxhandbook.com/pro-vim-tips/

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博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2934659/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969582