How do people generally delete a file that is open in the current buffer using (neo)vim commands ?
It seems a pain to have to remember the exact path to the file to use :!rm ... and if I am going to use rm then I may as well do that in my highly optimised terminal shell. Maybe I am missing something
Reading the neovim docs just got me confused and I havent found a tutorial yet.
According to Stack Overflow it seems the simplest way is :call delete(@%) although this doesnt delete the buffer, so it looks like it doesnt work. Using :call delete(@%) | bdelete! seems to be more like what I am after (although this seems to hang my neovim setup) Is there a nicer way? Like a :filedelete command I am missing?
I would like to have a nice key binding to delete a file, something like <leader>fD
Or do you not use (neo)vim commands and use the command line or visual file manager (e.g. nvim-tree)
I open current dir with current file under cursor in netrw using - (mapping from vim-vinegar plugin), then D to delete file under cursor, then enter to confirm - 3 keys
although I don't delete buffer - it stays in memory until I close vim
Do you use nvim-tree ? NvimTreeFindFile and d probably works?
> It seems a pain to have to remember the exact path to the file to use :!rm ...
You can do :!rm %
I use vim-eunuch's :Delete command for this
https://github.com/tpope/vim-eunuch
It works well but I never looked into how it's implemented tbh
Using :NvimTreeFindFile highlights the file in the nvim-tree buffer, so d does delete it, providing a confirmation prompt first. The buffer is also removed too, so that's a nice bonus. This probably fits my workflow the best, thanks @emilaasa
Using !rm % is a nice alternative , thanks.
@steven.proctor thanks for the tip. I have been using :source % a lot to reload my vimrc file. It just hit me that % was a way to refer to the file in the current buffer. thanks!
I use NvimTree and I configured it to track the current file. Then I open it and press d , then y to confirm.
I generally do a !rm %
pretty much the same as if I wanted to run any other shell command on that specific file