This commit is contained in:
Sebastian 2025-08-06 21:55:44 +02:00
parent bab5ad2587
commit cad3ae0846
3 changed files with 106 additions and 1 deletions

View file

@ -50,4 +50,62 @@ vim.keymap.set('v', '<A-k>', ":m '<-2<CR>gv=gv", { desc = 'Move selection up' })
vim.keymap.set('n', '<C-,>', 'gcc', { desc = 'Comment line', remap = true })
vim.keymap.set('v', '<C-,>', 'gc', { desc = 'Comment selection', remap = true })
vim.keymap.set('v', '<C-c>', '"+y', { desc = 'Copy to clipboard' })
vim.keymap.set('v', '<C-c>', '"+y', { desc = 'Copy to clipboard' })
-- New file and directory creation
vim.keymap.set('n', '<leader>nf', function()
local current_dir = vim.fn.expand('%:p:h')
if current_dir == '' then
current_dir = vim.fn.getcwd()
end
vim.ui.input({
prompt = 'New file name: ',
default = current_dir .. '/',
completion = 'file',
}, function(input)
if input then
local file_path = input
-- If it's not an absolute path, make it relative to current file's directory
if not vim.startswith(file_path, '/') then
file_path = current_dir .. '/' .. file_path
end
-- Create parent directories if they don't exist
local parent_dir = vim.fn.fnamemodify(file_path, ':h')
vim.fn.mkdir(parent_dir, 'p')
-- Create and open the file
vim.cmd('edit ' .. vim.fn.fnameescape(file_path))
end
end)
end, { desc = 'New File' })
vim.keymap.set('n', '<leader>nd', function()
local current_dir = vim.fn.expand('%:p:h')
if current_dir == '' then
current_dir = vim.fn.getcwd()
end
vim.ui.input({
prompt = 'New directory name: ',
default = current_dir .. '/',
completion = 'dir',
}, function(input)
if input then
local dir_path = input
-- If it's not an absolute path, make it relative to current file's directory
if not vim.startswith(dir_path, '/') then
dir_path = current_dir .. '/' .. dir_path
end
-- Create the directory
local success = vim.fn.mkdir(dir_path, 'p')
if success == 1 then
print('Created directory: ' .. dir_path)
else
print('Failed to create directory: ' .. dir_path)
end
end
end)
end, { desc = 'New Directory' })