225 lines
9.1 KiB
Lua
225 lines
9.1 KiB
Lua
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', '<C-u>', '<C-u>zz', opts)
|
|
map('n', 'n', 'nzzzv', opts)
|
|
map('n', 'N', 'Nzzzv', opts)
|
|
map('x', '<leader>p', '"_dP', opts) -- paste without yanking
|
|
map('v', '<', '<gv', opts) -- reselect after indent
|
|
map('v', '>', '>gv', opts)
|
|
map('v', 'J', ":m '>+1<CR>gv=gv", opts) -- move lines
|
|
map('v', 'K', ":m '<-2<CR>gv=gv", opts)
|
|
-- }}}
|
|
|
|
-- {{{ Buffer navigation
|
|
map('n', '<C-J>', ':bnext<CR>', opts)
|
|
map('n', '<C-K>', ':bprev<CR>', opts)
|
|
map('n', '<leader>bb', ':Telescope buffers<CR>', opts)
|
|
map('n', '<leader>bk', ':bdelete<CR>', opts)
|
|
map('n', '<leader>bn', ':bnext<CR>', opts)
|
|
map('n', '<leader>bp', ':bprev<CR>', 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', '<leader>' .. key, function()
|
|
term_toggle(term_factory(value))
|
|
end, opts)
|
|
end
|
|
|
|
map('v', 'op', '<C-\\><C-N>:ToggleTerm name=ipython')
|
|
map('v', 'oP', '<C-\\><C-N>:ToggleTerm name=ipython-full')
|
|
map('t', '<leader>tp', '<C-\\><C-N>:FloatermToggle ipython<CR>', opts)
|
|
map('t', '<leader>tP', '<C-\\><C-N>:FloatermToggle ipython-full<CR>', opts)
|
|
|
|
map('n', '<C-T>', ':ToggleTerm name=toggleterm<CR>', opts)
|
|
map('n', '<leader>tt', ':ToggleTerm name=toggleterm<CR>', opts)
|
|
map('n', '<leader>ts', ':TermSelect<CR>', opts)
|
|
map('n', '<leader>tv', ':ToggleTerm direction=vertical name=toggleterm-vert<CR>', opts)
|
|
map('n', '<leader>th', ':ToggleTerm direction=horizontal name=toggleterm-hori<CR>', opts)
|
|
map('n', '<leader>tf', ':ToggleTerm name=toggleterm<CR>', opts)
|
|
|
|
map('t', '<leader>tt', '<C-\\><C-N>:ToggleTerm<CR>', opts)
|
|
map('t', '<leader>tf', '<C-\\><C-N>:ToggleTerm<CR>', opts)
|
|
map('t', '<leader>tv', '<C-\\><C-N>:ToggleTerm --name=toggleterm-vert<CR>', opts)
|
|
map('t', '<leader>th', '<C-\\><C-N>:ToggleTerm --name=toggleterm-hori<CR>', opts)
|
|
map('t', '<C-T>', '<C-\\><C-n>:Toggleterm<CR>', opts)
|
|
map('t', '<Esc>', '<C-\\><C-n>', opts)
|
|
map('t', '<space>', '<space>', opts) -- fix space in terminal
|
|
--}}}
|
|
|
|
--{{{ LSP mappings
|
|
map('n', 'gA', vim.lsp.buf.code_action, opts)
|
|
map('n', 'gd', ':Telescope lsp_definitions<CR>', opts)
|
|
map('n', 'gDc', ':Telescope lsp_implementations<CR>', opts)
|
|
map('n', 'gDf', ':Telescope lsp_definitions<CR>', opts)
|
|
map('n', 'gF', ':edit <cfile><CR>', opts)
|
|
map('n', 'gT', ':Telescope lsp_type_definitions<CR>', opts)
|
|
map('n', 'gb', ':Gitsigns blame_line<CR>', opts)
|
|
map('n', 'gi', ':Telescope lsp_implementations<CR>', opts)
|
|
map('n', 'gj', ':Telescope jumplist<CR>', opts)
|
|
map('n', 'gl', vim.lsp.codelens.run, opts)
|
|
map('n', 'gr', ':Telescope lsp_references<CR>', opts)
|
|
map('n', 'gs', vim.lsp.buf.signature_help, opts)
|
|
map('n', 'K', vim.lsp.buf.hover, opts)
|
|
--}}}
|
|
|
|
--{{{ Code Companion and Copilot
|
|
map('n', '<leader>oc', ':CodeCompanionChat<CR>')
|
|
map('n', '<leader>cc', ':CodeCompanionChat<CR>', opts)
|
|
map('n', '<leader>ci', ':CodeCompanion ', opts)
|
|
map('n', '<leader>cp', ':vert Copilot panel<CR>', opts)
|
|
map('n', '<leader>Ca', ':CodeCompanionActions<CR>', opts)
|
|
map('v', '<leader>Cc', ':CodeCompanionChat Add<CR>', opts)
|
|
map('v', '<leader>Ce', ':CodeCompanion /explain<CR>', opts)
|
|
map('v', '<leader>Cf', ':CodeCompanion /fix<CR>', opts)
|
|
map('v', '<leader>Cl', ':CodeCompanion /lsp<CR>', opts)
|
|
map('v', '<leader>CT', ':CodeCompanion /tests<CR>', opts)
|
|
--}}}
|
|
|
|
--{{{ Diagnostics
|
|
-- nnoremap <leader>cd :Telescope diagnostics<CR>
|
|
-- nnoremap <leader>cDn :lua vim.diagnostic.goto_next()<CR>
|
|
-- nnoremap <leader>cDp :lua vim.diagnostic.goto_prev()<CR>
|
|
-- nnoremap <leader>cl :lua vim.diagnostic.setloclist()<CR>
|
|
map('n', "<leader>cd", ':Telescope diagnostics<CR>')
|
|
map('n', "<leader>cDn", ':lua vim.diagnostic.goto_next()<CR>')
|
|
map('n', "<leader>cDp", ':lua vim.diagnostic.goto_prev()<CR<CR>')
|
|
map('n', "<leader>cd", ':lua vim.diagnostic.setloclist()<CR>')
|
|
--}}}
|
|
|
|
--{{{ Telescope mappings
|
|
map('n', '//', ':Telescope current_buffer_fuzzy_find<CR>', opts)
|
|
map('n', '??', ':Telescope lsp_document_symbols<CR>', opts)
|
|
map('n', '<leader>fc',
|
|
':Telescope color_names theme=dropdown layout_config={width=0.45,height=25,prompt_position="bottom"} layout_strategy=vertical<CR>',
|
|
opts)
|
|
-- map('n', '<leader>ob', ':Telescope file_browser<CR>')
|
|
map('n', '<leader>ff', ':Telescope find_files<CR>', opts)
|
|
map('n', '<leader>sf', ':Telescope find_files<CR>', opts)
|
|
map('n', '<leader>fg', ':Telescope live_grep<CR>', opts)
|
|
map('n', '<leader>fG',
|
|
':Telescope glyph theme=dropdown layout_config={width=0.45,height=35,prompt_position="bottom"} layout_strategy=vertical<CR>',
|
|
opts)
|
|
map('n', '<leader>fb', ':Telescope file_browser<CR>', opts)
|
|
map('n', '<leader>fr', ':Telescope oldfiles<CR>', opts)
|
|
|
|
--{{{ Telescope Helper
|
|
map('n', '<leader>hc', ':Telescope commands<CR>')
|
|
map('n', '<leader>hv', ':Telescope vim_options<CR>')
|
|
map('n', '<leader>hk', ':Telescope keymaps<CR>')
|
|
map('n', '<leader>hs', ':Telescope spell_suggest<CR>')
|
|
map('n', '<leader>hm', ':Telescope man_pages<CR>')
|
|
--}}}
|
|
|
|
--{{{ Telescope Search
|
|
map('n', '<leader>sf', ':Telescope find_files<CR>')
|
|
map('n', '<leader>sg', ':Telescope live_grep<CR>')
|
|
map('n', '<leader>sh', ':Telescope command_history<CR>')
|
|
map('n', '<leader>sm', ':Telescope man_pages<CR>')
|
|
map('n', '<leader>s/', ':Telescope search_history<CR>')
|
|
--}}}
|
|
|
|
--}}}
|
|
|
|
--{{{ File explorer and tools
|
|
map('n', '<leader>n', ':NvimTreeToggle<CR>', opts)
|
|
map('n', '<leader>D', ':Dotenv .env<CR>', opts)
|
|
--}}}
|
|
|
|
--{{{ Git mappings
|
|
map('n', '<leader>gc', ':Telescope git_commits<CR>', opts)
|
|
map('n', '<leader>gf', ':Telescope git_files<CR>', opts)
|
|
--}}}
|
|
|
|
--{{{ Misc utilities
|
|
map('n', '<leader>x', '<cmd>!chmod +x %<CR>', opts)
|
|
map('n', '<leader>y', '"+', opts)
|
|
map('v', '<leader>y', '"+', opts)
|
|
map('n', '<leader>sc', ':nohls<CR>')
|
|
--}}}
|
|
|
|
--{{{ Goto Preview
|
|
map('n', "gpc", ':lua require("goto-preview").close_all_win()<CR>')
|
|
map('n', "gpd", ':lua require("goto-preview").goto_preview_definition()<CR>')
|
|
map('n', "gpi", ':lua require("goto-preview").goto_preview_implementation()<CR>')
|
|
--}}}
|
|
|
|
--{{{ Workspace management
|
|
map('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, opts)
|
|
map('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, opts)
|
|
map('n', '<leader>wl', function()
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
end, opts)
|
|
--}}}
|
|
|
|
--{{{ LSP
|
|
map('n', '<leader>ld', ':Telescope lsp_definitions<CR>')
|
|
map('n', '<leader>lD', ':Telescope diagnostic<CR>')
|
|
map('n', '<leader>la', ':lua vim.lsp.buf.code_action()<CR>')
|
|
map('n', '<leader>lci', ':Telescope lsp_incoming_calls<CR>')
|
|
map('n', '<leader>lco', ':Telescope lsp_outgoing_calls<CR>')
|
|
map('n', '<leader>lh', ':lua vim.lsp.buf.signature_help()<CR>')
|
|
map('n', '<leader>li', ':Telescope lsp_implementations<CR>')
|
|
map('n', '<leader>lr', ':Telescope lsp_references<CR>')
|
|
map('n', '<leader>lR', ':lua vim.lsp.buf.rename()<CR>')
|
|
map('n', '<leader>ls', ':Telescope lsp_document_symbols<CR>')
|
|
map('n', '<leader>lt', ':Telescope lsp_type_definitions<CR>')
|
|
map('n', '<leader>lw', ':Telescope lsp_dynamic_workspace_symbols<CR>')
|
|
--}}}
|