local map = vim.keymap.set local Terminal = require('toggleterm.terminal').Terminal local lazygit = Terminal:new({ cmd = 'lazygit', hidden = true }) local ipython = Terminal:new({ cmd = 'ipython', hidden = true }) 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 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/init.lua', {}) 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('t', 'tp', ':FloatermToggle ipython', opts) map('t', 'tP', ':FloatermToggle ipython-full', opts) map('n', '', ':ToggleTerm name=toggleterm', opts) map('n', 'tt', ':ToggleTerm name=toggleterm', 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', 'tf', ':ToggleTerm name=toggleterm', opts) map('t', 'tt', ':ToggleTerm', opts) map('t', 'tf', ':ToggleTerm', opts) map('t', 'tv', ':ToggleTerm --name=toggleterm-vert', opts) map('t', 'th', ':ToggleTerm --name=toggleterm-hori', opts) map('t', '', ':Toggleterm', opts) map('t', '', '', opts) map('t', '', '', opts) -- fix space in terminal --}}} --{{{ 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) --}}} --{{{ Code Companion and Copilot map('n', 'oc', ':CodeCompanionChat') map('n', 'cc', ':CodeCompanionChat', opts) map('n', 'ci', ':CodeCompanion ', opts) map('n', 'cp', ':vert Copilot panel', opts) map('n', 'Ca', ':CodeCompanionActions', opts) map('v', 'Cc', ':CodeCompanionChat Add', opts) map('v', 'Ce', ':CodeCompanion /explain', opts) map('v', 'Cf', ':CodeCompanion /fix', opts) map('v', 'Cl', ':CodeCompanion /lsp', opts) map('v', 'CT', ':CodeCompanion /tests', opts) --}}} --{{{ Diagnostics -- nnoremap cd :Telescope diagnostics -- nnoremap cDn :lua vim.diagnostic.goto_next() -- nnoremap cDp :lua vim.diagnostic.goto_prev() -- nnoremap cl :lua vim.diagnostic.setloclist() map('n', "cd", ':Telescope diagnostics') map('n', "cDn", ':lua vim.diagnostic.goto_next()') map('n', "cDp", ':lua vim.diagnostic.goto_prev()') map('n', "cd", ':lua vim.diagnostic.setloclist()') --}}} --{{{ Telescope mappings 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', opts) map('n', 'sf', ':Telescope find_files', 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 Helper 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') map('n', 'sg', ':Telescope live_grep') map('n', 'sh', ':Telescope command_history') map('n', 'sm', ':Telescope man_pages') map('n', 's/', ':Telescope search_history') --}}} --}}} --{{{ File explorer and tools map('n', 'n', ':NvimTreeToggle', opts) map('n', 'D', ':Dotenv .env', opts) --}}} --{{{ Git mappings map('n', 'gc', ':Telescope git_commits', opts) map('n', 'gf', ':Telescope git_files', 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) --}}} --{{{ LSP map('n', 'ld', ':Telescope lsp_definitions') map('n', 'lD', ':Telescope diagnostic') map('n', 'la', ':lua vim.lsp.buf.code_action()') map('n', 'lci', ':Telescope lsp_incoming_calls') map('n', 'lco', ':Telescope lsp_outgoing_calls') map('n', 'lh', ':lua vim.lsp.buf.signature_help()') map('n', 'li', ':Telescope lsp_implementations') map('n', 'lr', ':Telescope lsp_references') map('n', 'lR', ':lua vim.lsp.buf.rename()') map('n', 'ls', ':Telescope lsp_document_symbols') map('n', 'lt', ':Telescope lsp_type_definitions') map('n', 'lw', ':Telescope lsp_dynamic_workspace_symbols') --}}}