diff --git a/init.lua b/init.lua index 06e2cfd4..d1fba00d 100644 --- a/init.lua +++ b/init.lua @@ -125,6 +125,11 @@ end) -- [[ Basic Keymaps ]] +vim.keymap.set('n', 'Ss', 'SessionSave', { desc = 'Save session' }) +vim.keymap.set('n', 'Sl', 'SessionLoad', { desc = 'Load session' }) + +vim.keymap.set('n', '', 'w', { desc = 'Save file' }) + -- Clear highlights on search when pressing in normal mode vim.keymap.set('n', '', 'nohlsearch', { desc = 'Clear search highlights' }) vim.keymap.set('n', '', 'nohlsearch', { desc = 'Clear search highlights' }) @@ -171,7 +176,10 @@ vim.keymap.set('n', '', 'zz', { desc = 'Half page down (centered)' }) vim.keymap.set('n', '', 'zz', { desc = 'Half page up (centered)' }) -- Delete without yanking -vim.keymap.set({ 'n', 'v' }, 'd', '"_d', { desc = 'Delete without yanking' }) +vim.keymap.set({ 'n', 'v' }, 'D', '"_d', { desc = 'Delete without yanking' }) + +-- Paste without yanking +vim.keymap.set('x', 'p', [["_dP]], { desc = 'Paste without yanking' }) -- Buffer navigation vim.keymap.set('n', 'bn', 'bnext', { desc = 'Next buffer' }) @@ -195,7 +203,7 @@ vim.keymap.set('n', 'J', 'mzJ`z', { desc = 'Join lines and keep cursor position' -- ============================================================================ -- Copy Full File-Path -vim.keymap.set('n', 'ypa', function() +vim.keymap.set('n', 'yp', function() local path = vim.fn.expand '%:p' vim.fn.setreg('+', path) print('file:', path) @@ -237,7 +245,7 @@ vim.api.nvim_create_autocmd('FileType', { vim.api.nvim_create_autocmd('FileType', { group = augroup, - pattern = { 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'json', 'html', 'css' }, + pattern = { 'javascript', 'typescript', 'javascriptreact', 'typescriptreact', 'json', 'html', 'css', 'go' }, callback = function() vim.opt_local.tabstop = 2 vim.opt_local.shiftwidth = 2 @@ -274,11 +282,13 @@ vim.api.nvim_create_autocmd('VimResized', { -- Create directories when saving files vim.api.nvim_create_autocmd('BufWritePre', { - group = augroup, callback = function() - local dir = vim.fn.expand ':p:h' - if vim.fn.isdirectory(dir) == 0 then - vim.fn.mkdir(dir, 'p') + local filepath = vim.fn.expand ':p:h' + if filepath:match '^oil://' or vim.uv.fs_realpath(filepath) == nil then + return + end + if vim.fn.isdirectory(filepath) == 0 then + vim.fn.mkdir(filepath, 'p') end end, }) @@ -468,17 +478,7 @@ vim.keymap.set('n', 'td', duplicate_tab, { desc = 'Duplicate current tab vim.keymap.set('n', 'tr', close_tabs_right, { desc = 'Close tabs to the right' }) vim.keymap.set('n', 'tL', close_tabs_left, { desc = 'Close tabs to the left' }) --- Function to close buffer but keep tab if it's the only buffer in tab -local function smart_close_buffer() - local buffers_in_tab = #vim.fn.tabpagebuflist() - if buffers_in_tab > 1 then - vim.cmd 'bdelete' - else - -- If it's the only buffer in tab, close the tab - vim.cmd 'tabclose' - end -end -vim.keymap.set('n', 'x', smart_close_buffer, { desc = 'Smart close buffer/tab' }) +vim.keymap.set('n', 'x', 'q', { desc = 'Smart close buffer/tab' }) -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info diff --git a/lua/custom/plugins/oil.lua b/lua/custom/plugins/oil.lua index 86195cb5..6a2d7d02 100644 --- a/lua/custom/plugins/oil.lua +++ b/lua/custom/plugins/oil.lua @@ -8,7 +8,7 @@ return { local oil = require 'oil' oil.setup { - default_file_explorer = true, + -- default_file_explorer = true, delete_to_trash = true, skip_confirm_for_simple_edits = true, @@ -19,13 +19,15 @@ return { [''] = { 'actions.select' }, [''] = { 'actions.select' }, [''] = { 'actions.parent' }, - [''] = { 'actions.select_split' }, [''] = { 'actions.close', mode = 'n' }, [''] = { 'actions.close', mode = 'n' }, + [''] = { 'actions.select', opts = { vertical = true } }, + [''] = { 'actions.select', opts = { horizontal = true } }, + [''] = { 'actions.select', opts = { tab = true } }, }, view_options = { show_hidden = true, - natural_order = true, + natural_order = 'fast', is_always_hidden = function(name, _) return name == '..' or name == '.git' end, @@ -34,6 +36,19 @@ return { signcolumn = 'yes:2', wrap = true, }, + preview_win = { + disable_preview = function(filename) + return filename:match '^%.' + end, + }, + sort = { + { 'name', 'asc' }, + }, + buf_options = { + buflisted = false, + bufhidden = 'delete', -- Delete the buffer immediately when hidden + }, + cleanup_delay_ms = 0, -- Or set to false to disable auto-cleanup entirely if you prefer } vim.keymap.set('n', '-', oil.toggle_float, { desc = 'Open parent directory' })