From cad3ae08461d16db70634771ef08c7b6c30d1f69 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 6 Aug 2025 21:55:44 +0200 Subject: [PATCH] awesome --- lua/config/keymaps.lua | 60 ++++++++++++++++++++++++++++++++- lua/plugins/file-operations.lua | 42 +++++++++++++++++++++++ lua/plugins/ui.lua | 5 +++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 lua/plugins/file-operations.lua diff --git a/lua/config/keymaps.lua b/lua/config/keymaps.lua index 26633e13..dd48f68f 100644 --- a/lua/config/keymaps.lua +++ b/lua/config/keymaps.lua @@ -50,4 +50,62 @@ vim.keymap.set('v', '', ":m '<-2gv=gv", { desc = 'Move selection up' }) vim.keymap.set('n', '', 'gcc', { desc = 'Comment line', remap = true }) vim.keymap.set('v', '', 'gc', { desc = 'Comment selection', remap = true }) -vim.keymap.set('v', '', '"+y', { desc = 'Copy to clipboard' }) \ No newline at end of file +vim.keymap.set('v', '', '"+y', { desc = 'Copy to clipboard' }) + +-- New file and directory creation +vim.keymap.set('n', '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', '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' }) \ No newline at end of file diff --git a/lua/plugins/file-operations.lua b/lua/plugins/file-operations.lua new file mode 100644 index 00000000..756eba46 --- /dev/null +++ b/lua/plugins/file-operations.lua @@ -0,0 +1,42 @@ +-- File operations plugin +return { + { + 'stevearc/dressing.nvim', + event = 'VeryLazy', + config = function() + require('dressing').setup({ + input = { + enabled = true, + default_prompt = 'Input:', + prompt_align = 'left', + insert_only = true, + start_in_insert = true, + anchor = 'SW', + border = 'rounded', + relative = 'cursor', + prefer_width = 40, + width = nil, + max_width = { 140, 0.9 }, + min_width = { 20, 0.2 }, + buf_options = {}, + win_options = { + winblend = 10, + wrap = false, + }, + mappings = { + n = { + [''] = 'Close', + [''] = 'Confirm', + }, + i = { + [''] = 'Close', + [''] = 'Confirm', + [''] = 'HistoryPrev', + [''] = 'HistoryNext', + }, + }, + }, + }) + end, + }, +} \ No newline at end of file diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua index d281b890..a28be3d8 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/ui.lua @@ -46,6 +46,7 @@ return { { 'W', group = '[W]orkspace' }, { 't', group = '[T]oggle' }, { 'h', group = 'Git [H]unk', mode = { 'n', 'v' } }, + { 'n', group = '[N]ew' }, -- General keybinds { 'w', desc = 'Save File' }, @@ -105,6 +106,10 @@ return { { 'tb', desc = 'Toggle git show blame line' }, { 'tD', desc = 'Toggle git show deleted' }, + -- New file/directory keybinds + { 'nf', desc = 'New File' }, + { 'nd', desc = 'New Directory' }, + -- Function keys { '', desc = 'Debug: Step Into' }, { '', desc = 'Debug: Step Over' },