Skip to content

Move Rename and Delete files in neovim with convenient commands that handle and respect buffers

Notifications You must be signed in to change notification settings

opsaaaaa/movefile.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

movefile.nvim

A Neovim plugin for moving and renaming files from within Neovim.

Features

  • :Move - Move files to new locations with buffer updates
  • :Rename - Rename the current file with smart completion
  • :Trash - Move files to trash or delete them
  • :Remove - Permanently delete files
  • :Mv - Alias for :Move
  • :Rn - Alias for :Rename
  • Preserves cursor position and buffer state
  • Updates all buffers pointing to moved files
  • File and directory completion for arguments
  • Smart completion for :Rename using filename segments

Installation

Using lazy.nvim:

return {
  "opsaaaaa/movefile.nvim",
  cmd = {"Move", "Rename", "Trash", "Remove", "Mv", "Rn"},
  config = function()
    require("movefile").setup({})
  end
}

Usage

:Move Command

Move the current file to a new location:

:Move ../notes/article.md

Move a specific file:

:Move old/name.md new/name.md

Move current file to a directory (keeps filename):

:Move ../archive/

:Rename Command

Rename the current file (preserves extension):

:Rename new-filename

Rename and change extension:

:Rename new-filename.txt

The :Rename command provides smart completion by splitting the current filename by separators (-, _, ., ). For a file named 20240116-project-notes.md, it would suggest:

20240116  -project  -notes  .md

This allows quick tab completion to build up the new filename.

:Trash Command

Trash the current file (moves to trash folder):

:Trash

Trash a specific file:

:Trash old/file.md

Delete an empty directory:

:Trash empty-folder/

:Remove Command

Permanently delete the current file:

:Remove

Permanently delete a specific file:

:Remove old/file.md

This command is equivalent to running :Trash with trash_soft_delete = true.

Configuration

require("movefile").setup({
  trash_folder = nil,        -- Custom trash folder path
  trash_soft_delete = false, -- Permanently delete instead of trash
})

If trash_folder is not specified, the plugin searches for:

  1. .Trash or .trash in the current directory
  2. ~/.local/share/Trash

When trash_soft_delete is false (default), files are moved to:

  • <trash_folder>/files/<filename>
  • A .trashinfo metadata file is created at <trash_folder>/info/<filename>.trashinfo

Buffer Handling

When moving or renaming files:

  • The buffer name is updated in place to preserve undo history and marks
  • All other open buffers pointing to the same file are updated
  • Cursor position is preserved after the operation

About

Move Rename and Delete files in neovim with convenient commands that handle and respect buffers

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages