Fork me on GitHub
#vim
<
2022-12-11
>
practicalli-johnny10:12:28

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)

nbardiuk11:12:49

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

nbardiuk11:12:02

although I don't delete buffer - it stays in memory until I close vim

emilaasa11:12:32

Do you use nvim-tree ? NvimTreeFindFile and d probably works?

Jan K13:12:00

> It seems a pain to have to remember the exact path to the file to use :!rm ... You can do :!rm %

7
fuad16:12:41

I use vim-eunuch's :Delete command for this https://github.com/tpope/vim-eunuch

☝️ 2
fuad16:12:05

It works well but I never looked into how it's implemented tbh

practicalli-johnny16:12:12

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 @U6T7M9DBR Using !rm % is a nice alternative , thanks.

1
👍 2
Proctor13:12:44

I generally do a !rm % pretty much the same as if I wanted to run any other shell command on that specific file

Abhinav05:12:26

@US03ZP2F5 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!

Martynas Maciulevičius18:12:59

I use NvimTree and I configured it to track the current file. Then I open it and press d , then y to confirm.