Go to file
Ralf Schmitz Bongiolo 3dd0e64e68 fix: OS detection when using vim.fn.has 2024-01-03 00:16:24 +01:00
.github chore: update config files 2023-12-30 12:46:48 +01:00
doc chore: Auto generate docs 2024-01-01 15:49:33 +00:00
lua/genghis fix: OS detection when using vim.fn.has 2024-01-03 00:16:24 +01:00
plugin fix: commands disabling 2023-12-20 14:34:13 +01:00
.editorconfig style: update .editorconfig 2023-10-13 12:45:03 +02:00
.ignore ci: ignore panvimdoc files 2023-07-24 13:48:12 +02:00
.luarc.json patch 2022-11-27 21:16:02 +01:00
.markdownlint.yaml chore: update config files 2023-12-30 12:46:48 +01:00
.stylua.toml chore: update config files 2023-12-30 12:46:48 +01:00
LICENSE chore 2023-07-24 13:48:28 +02:00
README.md break(trashFile)!: use CLIs instead of moving to trash (req. install) 2024-01-01 16:49:14 +01:00

README.md

nvim-genghis ⚔️

badge

Lightweight and quick file operations without being a full-blown file manager.

Features

  • Commands for moving, renaming, creating, deleting, or, duplicating files and more.
  • Commands for copying the path or name of the current file in various formats.
  • Renaming commands update import statements to the renamed file (if the LSP supports it).
  • Lightweight plugin, no file management UI or file tree.
  • Various quality-of-life improvements like automatically keeping the extensions when no extension is given.
  • Fully written in lua and makes use of up-to-date nvim features vim.ui.input. This that for example you can get nicer input fields with normal mode support via plugins like dressing.nvim.

Installation and Setup

-- Packer
use {"chrisgrieser/nvim-genghis", requires = "stevearc/dressing.nvim"}

-- Lazy
{"chrisgrieser/nvim-genghis", dependencies = "stevearc/dressing.nvim"},

nvim-genghis (and dressing.nvim) require no .setup() function. Just create keybindings for the commands you want to use:

local keymap = vim.keymap.set
local genghis = require("genghis")
keymap("n", "<leader>yp", genghis.copyFilepath)
keymap("n", "<leader>yn", genghis.copyFilename)
keymap("n", "<leader>cx", genghis.chmodx)
keymap("n", "<leader>rf", genghis.renameFile)
keymap("n", "<leader>mf", genghis.moveAndRenameFile)
keymap("n", "<leader>nf", genghis.createNewFile)
keymap("n", "<leader>yf", genghis.duplicateFile)
keymap("n", "<leader>df", genghis.trashFile)
keymap("x", "<leader>x", genghis.moveSelectionToNewFile)

Available Commands

File Operation Command

  • .createNewFile or :New: Create a new file.
  • .duplicateFile or :Duplicate: Duplicate the current file.
  • .moveSelectionToNewFile or :NewFromSelection: Prompts for a new file name and moves the current selection to that new file. (Note that this is a Visual Line Mode command; the selection is moved linewise.)
  • .renameFile or :Rename: Rename the current file.
  • .moveAndRenameFile or :Move: Move and Rename the current file. Keeps the old name if the new path ends with /. Works like the UNIX mv command. Can be used with autocompletion of directories.
  • .trashFile{trashCmd = "your_cli"} or :Trash: Move the current file to the trash location.
    • Defaults to gio trash on Linux, trash on Mac and Windows.
    • If bufdelete.nvim is available, require'bufdelete.nvim'.bufwipeout would be used to keep window layout intact instead of vim.cmd.bwipeout.

[!NOTE] The trash CLIs are not available by default, and must be installed.

The following applies to all commands above:

  • If no extension has been provided, uses the extension of the original file.
  • If the new file name includes a /, the new file is placed in the respective subdirectory, creating any non-existing folders. Except for .moveAndRenameFile, all operations take only place in the current working directory, so .moveAndRenameFile is the only command that can move to a parent directory.
  • All commands support autocompletion of existing directories.

renameFile and moveAndRenameFile notify any running LSP client about the renaming. LSP servers supporting the workspace/willRenameFiles method can use this information to update various code parts, for example use or import statements.

File Utility Commands

  • .copyFilename or :CopyFilename: Copy the file name. When clipboard="unnamed[plus]" has been set, copies to the + register, otherwise to ".
  • .copyFilepath or :CopyFilepath: Copy the absolute file path. When clipboard="unnamed[plus]" has been set, copies to the + register, otherwise to ".
  • .copyRelativePath or :CopyRelativePath: Copy the relative file path. When clipboard="unnamed[plus]" has been set, copies to the + register, otherwise to ".
  • .copyDirectoryPath or :CopyDirectoryPath: Copy the absolute directory path. When clipboard="unnamed[plus]" has been set, copies to the + register, otherwise to ".
  • .copyRelativeDirectoryPath or :CopyRelativeDirectoryPath: Copy the relative directory path. When clipboard="unnamed[plus]" has been set, copies to the + register, otherwise to ".
  • .chmodx or :Chmodx: Makes current file executable. Equivalent to chmod +x.

To always use system clipboard put this in your configuration file:

-- lua
vim.g.genghis_use_systemclipboard = true
-- viml
let g:genghis_use_systemclipboard = v:true

Disable Ex-Commands

Put this in your configuration file:

-- lua
vim.g.genghis_disable_commands = true
-- viml
let g:genghis_disable_commands = v:true

Autocompletion of directories

You can get autocompletion for directories by using dressing.nvim, nvim-cmp, and vim's omnifunc:

-- packer
use { "chrisgrieser/nvim-genghis", requires = {
		"stevearc/dressing.nvim",
		"hrsh7th/nvim-cmp",
		"hrsh7th/cmp-omni",
	},
}
-- lazy
{ "chrisgrieser/nvim-genghis", dependencies = {
		"stevearc/dressing.nvim",
		"hrsh7th/nvim-cmp",
		"hrsh7th/cmp-omni",
	},
},
-- required setup for cmp, somewhere after your main cmp-config
require("cmp").setup.filetype("DressingInput", {
	sources = cmp.config.sources { { name = "omni" } },
})

How is this different from vim.eunuch?

  • Various improvements like automatically keeping the extensions when no extension is given, or moving files to the trash instead of removing them.
  • Uses only vim-commands or lua os modules, so it has no dependencies and works cross-platform.
  • Makes use of up-to-date nvim features like vim.ui.input or vim.notify. This means you can get nicer input fields with normal mode support via plugins like dressing.nvim, and confirmation notices with plugins like nvim-notify, if they are installed and setup.
  • LSP support when renaming.
  • Written 100% in lua.

Why that name

A nod to vim.eunuch. As opposed to childless eunuchs, it is said that Genghis Khan has fathered thousands of children.

About me

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.

Blog
I also occasionally blog about vim: Nano Tips for Vim

Profiles

Buy Me a Coffee at ko-fi.com