This commit is contained in:
kyasuda
2025-12-03 14:12:00 -08:00
parent d8a0e95bb5
commit 7b7fae9b91
2 changed files with 22 additions and 2 deletions

View File

@@ -436,6 +436,14 @@ local misc_utilities_mappings = {
end, end,
group = "mkdir under cursor", group = "mkdir under cursor",
}, },
{
mode = "v",
key = "<leader>m",
cmd = function()
mkdir_under_cursor()
end,
group = "mkdir selection",
},
} }
-- }}} -- }}}

View File

@@ -2,8 +2,20 @@ local M = {}
vim.notify = require("notify") vim.notify = require("notify")
function M.mkdir_under_cursor() function M.mkdir_under_cursor()
-- Get the word under the cursor local word
local word = vim.fn.expand("<cWORD>")
-- Check if in visual mode
if vim.fn.mode():match("[vV]") then
-- Get visual selection
local start_pos = vim.fn.getpos("'<")
local end_pos = vim.fn.getpos("'>")
local line = vim.fn.getline(start_pos[2])
word = line:sub(start_pos[3], end_pos[3])
else
-- Get word under cursor
word = vim.fn.expand("<cWORD>")
end
-- Remove quotes if present -- Remove quotes if present
word = word:gsub("^[\"']", ""):gsub("[\"']$", "") word = word:gsub("^[\"']", ""):gsub("[\"']$", "")
-- Check if directory exists -- Check if directory exists