How can I delete the current file in vim?

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('%'))

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

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)