How can I delete the current file in vim?

后端 未结 6 1905
爱一瞬间的悲伤
爱一瞬间的悲伤 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 01:58

    Sometimes a plugin can be an attractive solution even for a simple problem. In this case we're lucky as there is eunuch.vim by the almighty Tim Pope.

    In its own words eunuch.vim provides

    Vim sugar for the UNIX shell commands that need it the most. Delete or rename a buffer and the underlying file at the same time. Load a find or a locate into the quickfix list. And so on.

    Perfect. It has what we need, plus some additional tools if we're on a UNIX system.

    The command you are looking for is

    :Remove!
    

    Again, remap it if you need it a lot, e.g. :nnoremap rm :Remove!.

提交回复
热议问题