diff --git a/init.lua b/init.lua index 564e366..cdb5c2b 100644 --- a/init.lua +++ b/init.lua @@ -10,5 +10,32 @@ vim.api.nvim_create_autocmd('User', { require 'feline' -- require 'dressing' require 'NeoSwap' + + local Terminal = require('toggleterm.terminal').Terminal + local lazygit = Terminal:new({ + cmd = "lazygit", + dir = "git_dir", + direction = "float", + float_opts = { + border = "none", + }, + -- function to run on opening the terminal + on_open = function(term) + vim.cmd("startinsert!") + vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "close", + { noremap = true, silent = true }) + end, + -- function to run on closing the terminal + on_close = function(_) + vim.cmd("startinsert!") + end, + }) + + function _lazygit_toggle() + lazygit:toggle() + end + + vim.api.nvim_set_keymap("n", "g", "lua _lazygit_toggle()", + { noremap = true, silent = true }) end, }) diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua index 6c8b7b4..0ff031e 100644 --- a/lua/config/autocmds.lua +++ b/lua/config/autocmds.lua @@ -1,31 +1,31 @@ local function augroup(name) - return vim.api.nvim_create_augroup("my_" .. name, { clear = false }) + return vim.api.nvim_create_augroup("my_" .. name, { clear = false }) end vim.api.nvim_create_autocmd( - { "BufEnter", "FocusGained", "InsertLeave", "WinEnter", "CmdlineLeave" }, - { - group = augroup("toggle_relative_number"), - callback = function() - if not vim.opt.number:get() and not vim.opt.relativenumber:get() then - return - end - vim.opt.relativenumber = vim.api.nvim_get_mode().mode ~= "i" - end, - } + { "BufEnter", "FocusGained", "InsertLeave", "WinEnter", "CmdlineLeave" }, + { + group = augroup("toggle_relative_number"), + callback = function() + if not vim.opt.number:get() and not vim.opt.relativenumber:get() then + return + end + vim.opt.relativenumber = vim.api.nvim_get_mode().mode ~= "i" + end, + } ) vim.api.nvim_create_autocmd( - { "BufLeave", "FocusLost", "InsertEnter", "WinLeave", "CmdlineEnter" }, - { - group = augroup("toggle_relative_number"), - callback = function(ev) - vim.opt.relativenumber = false - if ev.event == "CmdlineEnter" then - vim.cmd("redraw") - end - end, - } + { "BufLeave", "FocusLost", "InsertEnter", "WinLeave", "CmdlineEnter" }, + { + group = augroup("toggle_relative_number"), + callback = function(ev) + vim.opt.relativenumber = false + if ev.event == "CmdlineEnter" then + vim.cmd("redraw") + end + end, + } ) -- close some filetypes with @@ -95,6 +95,10 @@ vim.cmd [[ augroup END ]] +vim.cmd [[ +autocmd VimLeave * call writefile([getcwd()], expand('~/.cache/nvim/cwd')) +]] + -- Fixes Autocomment -- vim.api.nvim_create_autocmd({ 'BufWinEnter' }, { -- callback = function() diff --git a/lua/config/mappings.lua b/lua/config/mappings.lua index 1f1d6c3..5916094 100644 --- a/lua/config/mappings.lua +++ b/lua/config/mappings.lua @@ -1,6 +1,8 @@ local opt = { noremap = true, silent = true } local keymap = vim.api.nvim_set_keymap +keymap('n', 'gx', '!xdg-open ', opt) + keymap('n', '', 'silent! NeoSwapPrev', opt) keymap('n', '', 'silent! NeoSwapNext', opt) keymap('n', '', 'Lazy profile', opt) diff --git a/lua/plugins/editor.lua b/lua/plugins/editor.lua index cf28c99..57db895 100644 --- a/lua/plugins/editor.lua +++ b/lua/plugins/editor.lua @@ -79,7 +79,7 @@ return { { 'fb', telescope 'buffers', desc = 'buffers' }, { 'fc', telescope 'colorscheme', desc = 'colorscheme' }, { 'fh', telescope 'oldfiles', desc = 'history' }, - { 'fj', telescope 'jumplist', desc = 'history' }, + { 'fj', telescope 'jumplist', desc = 'jumplist' }, } end, config = function() diff --git a/lua/plugins/lsp/ui.lua b/lua/plugins/lsp/ui.lua index 806243b..0e190dd 100644 --- a/lua/plugins/lsp/ui.lua +++ b/lua/plugins/lsp/ui.lua @@ -29,25 +29,25 @@ end function M.on_attach(client, bufnr) -- Highlight references - -- if client.server_capabilities.documentHighlightProvider then - -- vim.api.nvim_create_augroup("lsp_document_highlight", { - -- clear = false, - -- }) - -- vim.api.nvim_clear_autocmds({ - -- group = "lsp_document_highlight", - -- buffer = bufnr, - -- }) - -- -- vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { - -- -- group = "lsp_document_highlight", - -- -- buffer = bufnr, - -- -- callback = vim.lsp.buf.document_highlight, - -- -- }) - -- -- vim.api.nvim_create_autocmd("CursorMoved", { - -- -- group = "lsp_document_highlight", - -- -- buffer = bufnr, - -- -- callback = vim.lsp.buf.clear_references, - -- -- }) - -- end + if client.server_capabilities.documentHighlightProvider then + vim.api.nvim_create_augroup("lsp_document_highlight", { + clear = false, + }) + vim.api.nvim_clear_autocmds({ + group = "lsp_document_highlight", + buffer = bufnr, + }) + vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { + group = "lsp_document_highlight", + buffer = bufnr, + callback = vim.lsp.buf.document_highlight, + }) + vim.api.nvim_create_autocmd("CursorMoved", { + group = "lsp_document_highlight", + buffer = bufnr, + callback = vim.lsp.buf.clear_references, + }) + end end return M diff --git a/lua/plugins/misc.lua b/lua/plugins/misc.lua index 5e9443d..12966e5 100644 --- a/lua/plugins/misc.lua +++ b/lua/plugins/misc.lua @@ -61,5 +61,80 @@ return { }, }) end - } + }, + { + "willothy/flatten.nvim", + opts = function() + ---@type Terminal? + local saved_terminal + + return { + window = { + open = "alternate", + }, + callbacks = { + should_block = function(argv) + -- Note that argv contains all the parts of the CLI command, including + -- Neovim's path, commands, options and files. + -- See: :help v:argv + + -- In this case, we would block if we find the `-b` flag + -- This allows you to use `nvim -b file1` instead of + -- `nvim --cmd 'let g:flatten_wait=1' file1` + return vim.tbl_contains(argv, "-b") + + -- Alternatively, we can block if we find the diff-mode option + -- return vim.tbl_contains(argv, "-d") + end, + pre_open = function() + local term = require("toggleterm.terminal") + local termid = term.get_focused_id() + saved_terminal = term.get(termid) + end, + post_open = function(bufnr, winnr, ft, is_blocking) + if is_blocking and saved_terminal then + -- Hide the terminal while it's blocking + saved_terminal:close() + else + -- If it's a normal file, just switch to its window + vim.api.nvim_set_current_win(winnr) + -- vim.api.nvim_set_current_bufnr(bufnr) + + -- If we're in a different wezterm pane/tab, switch to the current one + -- Requires willothy/wezterm.nvim + -- require("wezterm").switch_pane.id( + -- tonumber(os.getenv("WEZTERM_PANE")) + -- ) + end + + -- If the file is a git commit, create one-shot autocmd to delete its buffer on write + -- If you just want the toggleable terminal integration, ignore this bit + if ft == "gitcommit" or ft == "gitrebase" then + vim.api.nvim_create_autocmd("BufWritePost", { + buffer = bufnr, + once = true, + callback = vim.schedule_wrap(function() + vim.api.nvim_buf_delete(bufnr, {}) + end), + }) + end + end, + block_end = function() + -- After blocking ends (for a git commit, etc), reopen the terminal + vim.schedule(function() + if saved_terminal then + saved_terminal:open() + saved_terminal = nil + end + end) + end, + }, + } + end, + -- or pass configuration with + -- opts = { } + -- Ensure that it runs first to minimize delay when opening file from terminal + lazy = false, + priority = 1001, + }, } diff --git a/lua/plugins/ui.lua b/lua/plugins/ui.lua index ca05594..5537546 100644 --- a/lua/plugins/ui.lua +++ b/lua/plugins/ui.lua @@ -144,7 +144,7 @@ return { end) vim.g.rainbow_delimiters = { highlight = highlight } - require("ibl").setup { scope = { highlight = highlight, show_start = false } } + require("ibl").setup { scope = { highlight = highlight, show_start = false, show_end = false } } hooks.register(hooks.type.SCOPE_HIGHLIGHT, hooks.builtin.scope_highlight_from_extmark) end diff --git a/lua/plugins/git.lua b/lua/plugins/unused/git.lua.bak similarity index 100% rename from lua/plugins/git.lua rename to lua/plugins/unused/git.lua.bak