Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move a file to a new directory with its existing name, closes #35 #36

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ keymap("x", "<leader>x", genghis.moveSelectionToNewFile)
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. Works like
the UNIX `mv` command. Best used with [autocompletion of
directories](#autocompletion-of-directories).
- `.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. Best
used with [autocompletion of directories](#autocompletion-of-directories).

The following applies to all commands above:
- If no extension has been provided, uses the extension of the original file.
Expand Down
5 changes: 4 additions & 1 deletion lua/genghis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ local function fileOp(op)
-- VALIDATION OF FILENAME
if not newName then return end -- input has been canceled

if newName:find("/$") then
newName = newName .. oldName -- use the new directory with the old name
end

local invalidName = newName:find("^%s+$")
or newName:find("[\\:]")
or newName:find("/$")
or (newName:find("^/") and not op == "move-rename")
local sameName = newName == oldName
local emptyInput = newName == ""
Expand Down