Skip to content

Commit cad3ae0

Browse files
awesome
1 parent bab5ad2 commit cad3ae0

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

lua/config/keymaps.lua

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,62 @@ vim.keymap.set('v', '<A-k>', ":m '<-2<CR>gv=gv", { desc = 'Move selection up' })
5050
vim.keymap.set('n', '<C-,>', 'gcc', { desc = 'Comment line', remap = true })
5151
vim.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' })

lua/plugins/file-operations.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- File operations plugin
2+
return {
3+
{
4+
'stevearc/dressing.nvim',
5+
event = 'VeryLazy',
6+
config = function()
7+
require('dressing').setup({
8+
input = {
9+
enabled = true,
10+
default_prompt = 'Input:',
11+
prompt_align = 'left',
12+
insert_only = true,
13+
start_in_insert = true,
14+
anchor = 'SW',
15+
border = 'rounded',
16+
relative = 'cursor',
17+
prefer_width = 40,
18+
width = nil,
19+
max_width = { 140, 0.9 },
20+
min_width = { 20, 0.2 },
21+
buf_options = {},
22+
win_options = {
23+
winblend = 10,
24+
wrap = false,
25+
},
26+
mappings = {
27+
n = {
28+
['<Esc>'] = 'Close',
29+
['<CR>'] = 'Confirm',
30+
},
31+
i = {
32+
['<C-c>'] = 'Close',
33+
['<CR>'] = 'Confirm',
34+
['<Up>'] = 'HistoryPrev',
35+
['<Down>'] = 'HistoryNext',
36+
},
37+
},
38+
},
39+
})
40+
end,
41+
},
42+
}

lua/plugins/ui.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ return {
4646
{ '<leader>W', group = '[W]orkspace' },
4747
{ '<leader>t', group = '[T]oggle' },
4848
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
49+
{ '<leader>n', group = '[N]ew' },
4950

5051
-- General keybinds
5152
{ '<leader>w', desc = 'Save File' },
@@ -105,6 +106,10 @@ return {
105106
{ '<leader>tb', desc = 'Toggle git show blame line' },
106107
{ '<leader>tD', desc = 'Toggle git show deleted' },
107108

109+
-- New file/directory keybinds
110+
{ '<leader>nf', desc = 'New File' },
111+
{ '<leader>nd', desc = 'New Directory' },
112+
108113
-- Function keys
109114
{ '<F1>', desc = 'Debug: Step Into' },
110115
{ '<F2>', desc = 'Debug: Step Over' },

0 commit comments

Comments
 (0)