@@ -50,4 +50,62 @@ vim.keymap.set('v', '<A-k>', ":m '<-2<CR>gv=gv", { desc = 'Move selection up' })
5050vim .keymap .set (' n' , ' <C-,>' , ' gcc' , { desc = ' Comment line' , remap = true })
5151vim .keymap .set (' v' , ' <C-,>' , ' gc' , { desc = ' Comment selection' , remap = true })
5252
53- vim .keymap .set (' v' , ' <C-c>' , ' "+y' , { desc = ' Copy to clipboard' })
53+ vim .keymap .set (' v' , ' <C-c>' , ' "+y' , { desc = ' Copy to clipboard' })
54+
55+ -- New file and directory creation
56+ vim .keymap .set (' n' , ' <leader>nf' , function ()
57+ local current_dir = vim .fn .expand (' %:p:h' )
58+ if current_dir == ' ' then
59+ current_dir = vim .fn .getcwd ()
60+ end
61+
62+ vim .ui .input ({
63+ prompt = ' New file name: ' ,
64+ default = current_dir .. ' /' ,
65+ completion = ' file' ,
66+ }, function (input )
67+ if input then
68+ local file_path = input
69+ -- If it's not an absolute path, make it relative to current file's directory
70+ if not vim .startswith (file_path , ' /' ) then
71+ file_path = current_dir .. ' /' .. file_path
72+ end
73+
74+ -- Create parent directories if they don't exist
75+ local parent_dir = vim .fn .fnamemodify (file_path , ' :h' )
76+ vim .fn .mkdir (parent_dir , ' p' )
77+
78+ -- Create and open the file
79+ vim .cmd (' edit ' .. vim .fn .fnameescape (file_path ))
80+ end
81+ end )
82+ end , { desc = ' New File' })
83+
84+ vim .keymap .set (' n' , ' <leader>nd' , function ()
85+ local current_dir = vim .fn .expand (' %:p:h' )
86+ if current_dir == ' ' then
87+ current_dir = vim .fn .getcwd ()
88+ end
89+
90+ vim .ui .input ({
91+ prompt = ' New directory name: ' ,
92+ default = current_dir .. ' /' ,
93+ completion = ' dir' ,
94+ }, function (input )
95+ if input then
96+ local dir_path = input
97+ -- If it's not an absolute path, make it relative to current file's directory
98+ if not vim .startswith (dir_path , ' /' ) then
99+ dir_path = current_dir .. ' /' .. dir_path
100+ end
101+
102+ -- Create the directory
103+ local success = vim .fn .mkdir (dir_path , ' p' )
104+ if success == 1 then
105+ print (' Created directory: ' .. dir_path )
106+ else
107+ print (' Failed to create directory: ' .. dir_path )
108+ end
109+ end
110+ end )
111+ end , { desc = ' New Directory' })
0 commit comments