diff --git a/.config/nvim/lua/core/keymaps.lua b/.config/nvim/lua/core/keymaps.lua index 0ee0c2c..8d05b12 100644 --- a/.config/nvim/lua/core/keymaps.lua +++ b/.config/nvim/lua/core/keymaps.lua @@ -436,6 +436,14 @@ local misc_utilities_mappings = { end, group = "mkdir under cursor", }, + { + mode = "v", + key = "m", + cmd = function() + mkdir_under_cursor() + end, + group = "mkdir selection", + }, } -- }}} diff --git a/.config/nvim/lua/utils/functions/mkdir_under_cursor/init.lua b/.config/nvim/lua/utils/functions/mkdir_under_cursor/init.lua index b2b3486..2bb6321 100644 --- a/.config/nvim/lua/utils/functions/mkdir_under_cursor/init.lua +++ b/.config/nvim/lua/utils/functions/mkdir_under_cursor/init.lua @@ -2,8 +2,20 @@ local M = {} vim.notify = require("notify") function M.mkdir_under_cursor() - -- Get the word under the cursor - local word = vim.fn.expand("") + local word + + -- 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("") + end + -- Remove quotes if present word = word:gsub("^[\"']", ""):gsub("[\"']$", "") -- Check if directory exists