且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何删除vim中的当前文件?

更新时间:2023-01-28 13:30:44

使用诸如 rm(1) 之类的外部工具没问题,但 Vim 也有自己的 delete() 用于删除文件的函数.这具有便携性的优点.

Using an external tool such as rm(1) is fine, but Vim also has its own delete() function for deleting files. This has the advantage of being portable.

:call delete(expand('%'))

另一种表达方式是 :call delete(@%),它使用 %(当前文件)寄存器(@accolade 提示).

An alternative way of expressing this is :call delete(@%), which uses the % (current file) register (tip by @accolade).

要彻底清除当前缓冲区,包括磁盘上的文件表示和 Vim 缓冲区,请附加 :bdelete:

To completely purge the current buffer, both the file representation on disk and the Vim buffer, append :bdelete:

:call delete(expand('%')) | bdelete!

您可能希望根据自己的喜好映射它.

You'll probably want to map this according to your preferences.