Skip to content

babarot/rm.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

rm.nvim

A modern Neovim plugin for safely deleting files with trash/recycle bin support.

Features

  • πŸ—‘οΈ Custom Commands: Use any UNIX command for file deletion
  • βœ… Confirmation Prompts: Configurable confirmation before deletion
  • πŸ”§ Highly Configurable: Customize behavior to match your workflow
  • πŸ“¦ Buffer Cleanup: Automatically closes deleted file buffers
  • πŸš€ Modern Lua API: Built with Neovim's latest Lua features

Installation

{
  'babarot/rm.nvim',
  opts = {
    -- Optional: configure here
    -- command = 'gomi',
  },
}

Or with lazy loading:

{
  'babarot/rm.nvim',
  cmd = 'Rm',  -- Load when :Rm is executed
  opts = {
    command = 'gomi',
  },
}
use {
  'babarot/rm.nvim',
  config = function()
    require('rm').setup()
  end,
}
Plug 'babarot/rm.nvim'

lua << EOF
  require('rm').setup()
EOF

Usage

Quick Start

First, call setup() in your Neovim configuration:

require('rm').setup()

This creates the :Rm command by default.

Commands

  • :Rm - Delete current file with confirmation prompt
  • :Rm! - Delete current file without confirmation

Note: Commands are only created after calling setup(). You can customize the command name or disable it entirely (see Configuration section).

Lua API

-- Delete current file
require('rm').delete_current_file({ bang = false })

-- Delete multiple files
require('rm').delete_files({ 'file1.txt', 'file2.txt' }, { bang = false })

-- Get current configuration
local config = require('rm').get_config()

Configuration

Default configuration:

require('rm').setup({
  -- Custom deletion command
  -- If {file} placeholder is not present, file path is appended at the end
  -- Examples:
  --   'gomi'              -> 'gomi /path/to/file'
  --   'gomi {file}'       -> 'gomi /path/to/file'
  --   'mv {file} ~/.Trash/' -> 'mv /path/to/file ~/.Trash/'
  -- If nil, uses os.remove() for permanent deletion
  command = nil,

  -- Confirm before deletion by default
  confirm = true,

  -- Show notification after successful deletion
  notify = true,

  -- Notification level
  notify_level = vim.log.levels.INFO,

  -- Save file before deletion
  save_before_delete = true,

  -- Command creation settings
  create_commands = true, -- Set to false to disable automatic command creation

  -- Command names (only used when create_commands is true)
  commands = {
    delete = "Rm", -- Name of the delete command
  },
})

Example Configurations

Use gomi trash tool

require('rm').setup({
  command = 'gomi',
})

Use trash-cli (Linux)

require('rm').setup({
  command = 'trash',
})

Use GNOME gio trash

require('rm').setup({
  command = 'gio trash',
})

Move to Trash folder (macOS)

require('rm').setup({
  command = 'mv {file} ~/.Trash/',
})

Always skip confirmation

require('rm').setup({
  command = 'gomi',
  confirm = false,
})

Silent deletion

require('rm').setup({
  notify = false,
})

Custom command name

require('rm').setup({
  commands = {
    delete = "Delete",  -- Use :Delete instead of :Rm
  },
})

Disable automatic commands (Lua API only)

require('rm').setup({
  command = 'gomi',
  create_commands = false,  -- No :Rm command created
})

-- Use Lua API directly
vim.keymap.set('n', '<leader>fd', function()
  require('rm').delete_current_file({ bang = false })
end, { desc = 'Delete current file' })

Recommended Trash Tools

You can use any command-line trash tool with this plugin:

  • gomi - A trash tool written in Go
  • trash-cli - Command-line interface to freedesktop.org trash

By default (without configuration), the plugin uses os.remove() for permanent deletion.

Keybindings

You can set up custom keybindings for quick file deletion:

-- Delete current file with confirmation
vim.keymap.set('n', '<leader>fd', ':Rm<CR>', { desc = 'Delete current file' })

-- Delete current file without confirmation
vim.keymap.set('n', '<leader>fD', ':Rm!<CR>', { desc = 'Delete current file (no confirm)' })

-- Or use Lua API directly
vim.keymap.set('n', '<leader>fd', function()
  require('rm').delete_current_file({ bang = false })
end, { desc = 'Delete current file' })

Related Projects

  • gomi - A trash tool written in Go
  • trash-cli - Command-line interface to freedesktop.org trash

License

MIT

Author

babarot

About

Safe file deletion plugin for Neovim with customizable commands

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages