Skip to content

Latest commit

 

History

History
153 lines (127 loc) · 5.59 KB

README.md

File metadata and controls

153 lines (127 loc) · 5.59 KB

nvim-genghis ⚔️

badge

Lightweight and quick file operations without being a full-blown file manager. For when you prefer a fuzzy finder over a file tree, but still want some convenient file operations inside nvim.

Showcase for renaming files

Table of contents

Features

  • Perform common file operations: moving, renaming, creating, deleting, or duplicating files.
  • Copy the path or name of the current file in various formats.
  • All movement and renaming commands update import statements to the renamed file (if the LSP supports workspace/willRenameFiles).
  • Quality-of-life: automatically keep the extension when no extension is given, use vim motions in the input field, confirmatory notifications, and more.
  • Lightweight: no file management UI or file tree.

Installation

Requirements

  • nvim 0.10+
  • a vim.ui.input provider such as dressing.nvim or snacks.nvim for an input UI that supports vim motions and also looks much nicer
  • for the trash command: an OS-specific trash CLI like trash or gio trash
-- lazy.nvim
{ "chrisgrieser/nvim-genghis" },

-- packer
use { "chrisgrieser/nvim-genghis" }

Configuration

The setup call is required for lazy.nvim, but otherwise optional.

-- default config
require("genghis").setup {
	-- default is `"trash"` on Mac/Windows, and `{ "gio", "trash" }` on Linux
	trashCmd = "trash",

	-- set to empty string to disable
	-- (some icons are only used for notification plugins like `snacks.nvim`)
	icons = {
		chmodx = "󰒃",
		copyPath = "󰅍",
		copyFile = "󱉥",
		duplicate = "",
		file = "󰈔",
		move = "󰪹",
		new = "󰝒",
		rename = "󰑕",
		trash = "󰩹",
	}
}

Usage

You can access a command as lua function:

require("genghis").createNewFile()

Or you can use the ex command :Genghis with the respective sub-command:

:Genghis createNewFile

File operations

  • .createNewFile: Create a new file.
  • .duplicateFile: Duplicate the current file.
  • .moveSelectionToNewFile: Prompts for a new file name and moves the current selection to that new file. (Visual Line command, the selection is moved linewise.)
  • .renameFile: Rename the current file.
  • .moveAndRenameFile: Move and Rename the current file. Keeps the old name if the new path ends with /. Works like the Unix mv command.
  • .moveToFolderInCwd: Move the current file to an existing folder in the current working directory.
  • .chmodx: Makes current file executable. Equivalent to chmod +x.
  • .trashFile: Move the current file to the trash. Defaults to gio trash on Linux, and trash on macOS or Windows. (The trash CLIs must usually be installed.)
  • .showInSystemExplorer: Reveals the current file in the system explorer, such as macOS Finder. (Currently only on macOS, PRs welcome.)

The following applies to all commands above:

  1. If no extension has been provided, uses the extension of the original file.
  2. If the new file name includes a /, the new file is placed in the respective subdirectory, creating any non-existing intermediate folders.
  3. All movement and renaming commands update import statements to the renamed file (if the LSP supports workspace/willRenameFiles).

Copy operations

  • .copyFilename: Copy the file name.
  • .copyFilepath: Copy the absolute file path.
  • .copyFilepathWithTilde: Copy the absolute file path, replacing the home directory with ~.
  • .copyRelativePath: Copy the relative file path.
  • .copyDirectoryPath: Copy the absolute directory path.
  • .copyRelativeDirectoryPath: Copy the relative directory path.
  • .copyFileItself: Copies the file itself. This means you can paste it into the browser or file manager. (Currently only on macOS, PRs welcome.)

All commands use the system clipboard.

Why the name "Genghis"?

A nod to vim.eunuch, an older vimscript plugin with a similar goal. As opposed to childless eunuchs, it is said that Genghis Khan has fathered thousands of children.

About the author

In my day job, I am a sociologist studying the social mechanisms underlying the digital economy. For my PhD project, I investigate the governance of the app economy and how software ecosystems manage the tension between innovation and compatibility. If you are interested in this subject, feel free to get in touch.

I also occasionally blog about vim: Nano Tips for Vim

Buy Me a Coffee at ko-fi.com