docs: docs for rename

This commit is contained in:
Folke Lemaitre 2024-11-06 13:07:44 +01:00
parent 6673551e12
commit dd97a2a659
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 40 additions and 3 deletions

View file

@ -5,14 +5,16 @@ local M = {}
local uv = vim.uv or vim.loop
---@param path string
function M.realpath(path)
local function realpath(path)
return vim.fs.normalize(uv.fs_realpath(path) or path)
end
-- Prompt for the new filename,
-- do the rename, and trigger LSP handlers
function M.rename_file()
local buf = vim.api.nvim_get_current_buf()
local old = assert(M.realpath(vim.api.nvim_buf_get_name(buf)))
local root = assert(M.realpath(uv.cwd() or "."))
local old = assert(realpath(vim.api.nvim_buf_get_name(buf)))
local root = assert(realpath(uv.cwd() or "."))
if old:find(root, 1, true) ~= 1 then
root = vim.fn.fnamemodify(old, ":p:h")