local map = vim.keymap.set local Terminal = require("toggleterm.terminal").Terminal local notify = require("notify") local function term_factory(cfg) cfg["on_stderr"] = function(_, job, data, name) notify(name .. " encountered an error on job: " .. job .. "\nData: " .. data) end cfg["on_stdout"] = function(_, job, data, name) notify(name .. " output for job" .. job .. "\nData: " .. data) end return Terminal:new(cfg) end local function term_toggle(term) term:toggle() end local opts = { silent = true, noremap = true } local notsilent = { silent = false, noremap = true } local function ReloadConfig() dofile(vim.fn.stdpath("config") .. "/init.lua") dofile(vim.fn.stdpath("config") .. "/lua/core/keymaps.lua") dofile(vim.fn.stdpath("config") .. "/lua/core/autocmds.lua") dofile(vim.fn.stdpath("config") .. "/lua/core/options.lua") dofile(vim.fn.stdpath("config") .. "/lua/core/plugins.lua") dofile(vim.fn.stdpath("config") .. "/lua/plugins/ui/init.lua") dofile(vim.fn.stdpath("config") .. "/lua/plugins/ui/toggleterm.lua") dofile(vim.fn.stdpath("config") .. "/lua/plugins/ai/init.lua") dofile(vim.fn.stdpath("config") .. "/lua/plugins/lsp/init.lua") dofile(vim.fn.stdpath("config") .. "/lua/plugins/colorscheme/init.lua") end -- Leader key vim.g.mapleader = " " vim.g.maplocalleader = "," -- Custom commands vim.api.nvim_create_user_command("PS", ":PackerSync", {}) vim.api.nvim_create_user_command("Reload", ReloadConfig, {}) vim.api.nvim_create_user_command("Config", "edit ~/.config/nvim", {}) vim.api.nvim_create_user_command("Plugins", "edit ~/.config/nvim/lua/core/plugins.lua", {}) vim.api.nvim_create_user_command("Keymaps", "edit ~/.config/nvim/lua/core/keymaps.lua", {}) -- {{{ Basic mappings map("n", "", "zz", opts) map("n", "n", "nzzzv", opts) map("n", "N", "Nzzzv", opts) map("x", "p", '"_dP', opts) -- paste without yanking map("v", "<", "", ">gv", opts) map("v", "J", ":m '>+1gv=gv", opts) -- move lines map("v", "K", ":m '<-2gv=gv", opts) -- }}} -- {{{ Buffer navigation map("n", "", ":bnext", opts) map("n", "", ":bprev", opts) map("n", "bb", ":Telescope buffers", opts) map("n", "bk", ":bdelete", opts) map("n", "bn", ":bnext", opts) map("n", "bp", ":bprev", opts) -- }}} --{{{ Terminal mappings local programs_map = { gg = { cmd = "lazygit", display_name = "lazygit", direction = "tab", hidden = true }, op = { cmd = "ipython", display_name = "ipython", direction = "vertical", hidden = true }, oP = { cmd = "ipython", display_name = "ipython-full", direction = "tab", hidden = true }, on = { cmd = "ncmpcpp", display_name = "ncmpcpp", direction = "tab", hidden = true }, ob = { cmd = "btop", display_name = "btop", direction = "tab", hidden = true }, od = { cmd = "lazydocker", display_name = "lazydocker", direction = "tab", hidden = true }, } for key, value in pairs(programs_map) do map("n", "" .. key, function() term_toggle(term_factory(value)) end, opts) end map("v", "op", ":ToggleTerm name=ipython") map("v", "oP", ":ToggleTerm name=ipython-full") map("n", "", ":ToggleTerm name=toggleterm", opts) map("n", "tt", ":ToggleTerm name=toggleterm", opts) map("n", "tT", ":ToggleTerm name=toggleterm-full direction=tab", opts) map("n", "ot", ":ToggleTerm name=toggleterm", opts) map("n", "oT", ":ToggleTerm name=toggleterm-full direction=tab", opts) map("n", "ts", ":TermSelect", opts) map("n", "tv", ":ToggleTerm direction=vertical name=toggleterm-vert", opts) map("n", "th", ":ToggleTerm direction=horizontal name=toggleterm-hori", opts) map("n", "ov", ":ToggleTerm direction=vertical name=toggleterm-vert", opts) map("n", "oh", ":ToggleTerm direction=horizontal name=toggleterm-hori", opts) map("n", "tf", ":ToggleTerm name=toggleterm", opts) map("n", "-", ":ToggleTerm direction='horizontal'", opts) map("n", "|", ":ToggleTerm direction='vertical'", opts) function _G.set_terminal_keymaps() local opts = { buffer = 0 } map("t", "", [[]], opts) map("t", "", [[]], opts) -- map("t", "", "", { buffer = 0, silent = true }) -- fix space in terminal end -- if you only want these mappings for toggle term use term://*toggleterm#* instead vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()") --}}} --{{{ LSP mappings map("n", "gA", vim.lsp.buf.code_action, opts) map("n", "gd", ":Telescope lsp_definitions", opts) map("n", "gDc", ":Telescope lsp_implementations", opts) map("n", "gDf", ":Telescope lsp_definitions", opts) map("n", "gF", ":edit ", opts) map("n", "gT", ":Telescope lsp_type_definitions", opts) map("n", "gb", ":Gitsigns blame_line", opts) map("n", "gi", ":Telescope lsp_implementations", opts) map("n", "gj", ":Telescope jumplist", opts) map("n", "gl", vim.lsp.codelens.run, opts) map("n", "gr", ":Telescope lsp_references", opts) map("n", "gs", vim.lsp.buf.signature_help, opts) map("n", "K", vim.lsp.buf.hover, opts) map("n", "cd", ":Telescope lsp_definitions") map("n", "ca", vim.lsp.buf.code_action) map("n", "cci", ":Telescope lsp_incoming_calls") map("n", "cco", ":Telescope lsp_outgoing_calls") map("n", "ch", ":lua vim.lsp.buf.signature_help()") map("n", "ci", ":Telescope lsp_implementations") map("n", "cr", ":Telescope lsp_references") map("n", "cR", ":lua vim.lsp.buf.rename()") map("n", "cs", ":Telescope lsp_document_symbols") map("n", "ct", ":Telescope lsp_type_definitions") map("n", "cw", ":Telescope lsp_dynamic_workspace_symbols") map("n", "cd", ":Telescope diagnostics") map("n", "cDs", ":Telescope diagnostics") map("n", "cDn", ":lua vim.diagnostic.goto_next()") map("n", "cDp", ":lua vim.diagnostic.goto_prev()") map("n", "cl", ":lua vim.diagnostic.setloclist()") --}}} --{{{ Code Companion and Copilot map("n", "cp", ":vert Copilot panel", opts) map("n", "oc", ":CodeCompanionChat Toggle") map("n", "Cc", ":CodeCompanionChat Toggle", opts) map("n", "Ci", ":CodeCompanion ", opts) map("n", "CT", ":CodeCompanionChat Toggle", opts) map("n", "Ca", ":CodeCompanionActions", opts) map("v", "Cc", ":CodeCompanionChat Add", opts) map("v", "Ci", ":CodeCompanion /buffer ", notsilent) map("v", "Ce", ":CodeCompanion /explain", notsilent) map("v", "Cf", ":CodeCompanion /fix", notsilent) map("v", "Cl", ":CodeCompanion /lsp", notsilent) map("v", "Ct", ":CodeCompanion /tests", notsilent) --}}} --{{{ Telescope mappings -- {{{ Telescope Finders map("n", "//", ":Telescope current_buffer_fuzzy_find", opts) map("n", "??", ":Telescope lsp_document_symbols", opts) map( "n", "fc", ':Telescope color_names theme=dropdown layout_config={width=0.45,height=25,prompt_position="bottom"} layout_strategy=vertical', opts ) -- map('n', 'ob', ':Telescope file_browser') map( "n", "ff", ":Telescope find_files find_command=rg,--ignore,--follow,--hidden,--files prompt_prefix=🔍", opts ) map("n", "fg", ":Telescope live_grep", opts) map( "n", "fG", ':Telescope glyph theme=dropdown layout_config={width=0.45,height=35,prompt_position="bottom"} layout_strategy=vertical', opts ) map("n", "fb", ":Telescope file_browser", opts) map("n", "fr", ":Telescope oldfiles", opts) -- }}} --{{{ Telescope Help map("n", "hc", ":Telescope commands") map("n", "hv", ":Telescope vim_options") map("n", "hk", ":Telescope keymaps") map("n", "hs", ":Telescope spell_suggest") map("n", "hm", ":Telescope man_pages") --}}} --{{{ Telescope Search map( "n", "sf", ":Telescope find_files find_command=rg,--ignore,--follow,--hidden,--files prompt_prefix=🔍", opts ) map("n", "sF", ":Telescope fidget") map("n", "sg", ":Telescope live_grep") map("n", "sh", ":Telescope command_history") map("n", "sm", ":Telescope man_pages") map("n", "s/", ":Telescope search_history") --}}} --{{{ Git mappings map("n", "gc", ":Telescope git_commits", opts) map("n", "gf", ":Telescope git_files", opts) --}}} map("n", "Q", ":Telescope cmdline", opts) map("n", "", ":Telescope cmdline", opts) --}}} --{{{ File explorer and tools map("n", "n", ":NvimTreeToggle", opts) map("n", "D", ":Dotenv .env", opts) --}}} --{{{ Misc utilities map("n", "x", "!chmod +x %", opts) map("n", "y", '"+', opts) map("v", "y", '"+', opts) map("n", "sc", ":nohls") --}}} --{{{ Goto Preview map("n", "gpc", ':lua require("goto-preview").close_all_win()') map("n", "gpd", ':lua require("goto-preview").goto_preview_definition()') map("n", "gpi", ':lua require("goto-preview").goto_preview_implementation()') --}}} --{{{ Workspace management map("n", "wa", vim.lsp.buf.add_workspace_folder, opts) map("n", "wr", vim.lsp.buf.remove_workspace_folder, opts) map("n", "wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, opts) --}}}