How can I delete the current file in vim?

后端 未结 6 2004
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 01:35

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

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

6条回答
  •  野性不改
    2021-01-30 02:04

    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.

提交回复
热议问题