How to delete a file using the Vim editor

vim

I have a file testfile.xml that I want to open with Vim and delete in command mode

Best Answer

There are many ways:

  1. Using the intercative shell in vim

    When in the editor -

    :sh
    rm textfile.xml
    
  2. Using Bang(!)

    As DopeGhoti suggested -

    :!rm textfile.xml
    
  3. From this link.

    Add this to your ~/.vimrc

    command! -complete=file -nargs=1 Remove :echo 'Remove: '.'<f-args>'.' '.(delete(<f-args>) == 0 ? 'SUCCEEDED' : 'FAILED')
    

    Then,in vim,

    :Remove testfile.xml
    
  4. Again from the same link in #3

    Use this command:

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