如何删除vim中的当前文件? [英] How can I delete the current file in vim?

查看:114
本文介绍了如何删除vim中的当前文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从磁盘中删除 vim 中当前打开的文件?也可以关闭缓冲区.

How can I delete from the disk the current open file from within vim? Would be nice to also close the buffer.

我看到你可以使用NERDTree,但我不使用这个插件.

I see you can use NERDTree for that, but I don't use this plugin.

推荐答案

使用诸如 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.

这篇关于如何删除vim中的当前文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆