From 77452d989d2e567779d66d46206f8da683fb0a71 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 14 Mar 2024 23:17:27 +0000 Subject: [PATCH] Add :Remove command, to remove file of current buffer --- init.lua | 1 + lua/commands.lua | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 lua/commands.lua diff --git a/init.lua b/init.lua index 7193627..73569d6 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,6 @@ require('settings') require('mappings') +require('commands') require('netrw') require('autocmds') require('statusline') diff --git a/lua/commands.lua b/lua/commands.lua new file mode 100644 index 0000000..ac5a83f --- /dev/null +++ b/lua/commands.lua @@ -0,0 +1,18 @@ +-- TODO: :Rename +-- vim.loop.fs_rename + +-- :Remove the file associated with the current buffer, then delete the buffer +vim.api.nvim_create_user_command('Remove', function() + local path = vim.fn.expand('%:p') + vim.loop.fs_unlink(path, function(err, success) + if success then + vim.schedule(function() + vim.api.nvim_buf_delete(vim.api.nvim_get_current_buf(), {}) + end) + else + error(err) + end + end) +end, {}) + +-- TODO: :Move