local keymap = vim.api.nvim_set_keymap local NORMAL = 'n' local INSERT = 'i' local VISUAL = 'v' local COMMAND = 'c' vim.api.nvim_create_user_command("CloseOtherBuffers", function() local current_buffer_name = vim.api.nvim_buf_get_name(0) for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do if vim.api.nvim_buf_is_loaded(bufnr) and not vim.api.nvim_buf_get_option(bufnr, "modified") then local bufname = vim.api.nvim_buf_get_name(bufnr) if bufname ~= current_buffer_name then vim.cmd(":bd " .. bufnr) end end end end, {}) vim.api.nvim_create_user_command("Exit", function() for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do if vim.api.nvim_buf_is_loaded(bufnr) and not vim.api.nvim_buf_get_option(bufnr, "buflisted") then vim.cmd(":bd! " .. bufnr) end end vim.cmd(":qall") end, {}) -- command mode keymap(COMMAND, '', '', { noremap = true }) keymap(COMMAND, '', '', { noremap = true }) keymap(COMMAND, '', '', { noremap = true }) keymap(COMMAND, '', '', { noremap = true }) keymap(COMMAND, '', '', { noremap = true }) keymap(COMMAND, '', '', { noremap = true }) keymap(COMMAND, '', '', { noremap = true }) keymap(NORMAL, '', ':w', { noremap = true }) keymap(INSERT, '', ':wa', { noremap = true }) keymap(NORMAL, 'w', ':w', { noremap = true }) keymap(VISUAL, 'y', '"+y', { noremap = true }) keymap(NORMAL, 'yp', ':let @+=expand("%:p")', { noremap = true }) keymap(NORMAL, 'yn', ':let @+=expand("%:t")', { noremap = true }) keymap(NORMAL, 'yl', ':let @+=expand("%") . ":" . line(".")', { noremap = true }) keymap(VISUAL, 'p', '"0p', { noremap = true }) keymap(NORMAL, 'q', ':bd', { noremap = true }) keymap(NORMAL, 'qq', ':Exit', { noremap = true }) keymap(NORMAL, 'ne', ':e %:h', { noremap = true }) keymap(NORMAL, 'h', 'h', { noremap = true }) keymap(NORMAL, 'j', 'j', { noremap = true }) keymap(NORMAL, 'k', 'k', { noremap = true }) keymap(NORMAL, 'l', 'l', { noremap = true }) keymap(NORMAL, 'oo', 'o', { noremap = true }) keymap(NORMAL, '', ':noh', { noremap = true }) keymap(NORMAL, 'cn', ':cnext', { noremap = true }) keymap(NORMAL, 'cp', ':cprev', { noremap = true }) keymap(NORMAL, 'bo', ':CloseOtherBuffers', { noremap = true }) -- search and replace highlighted keymap(VISUAL, '/', "y/\\V=escape(@\",'/\\')", { noremap = true }) keymap(NORMAL, 'r', ':%s///g', { noremap = true }) keymap(NORMAL, '', ':bnext', { noremap = true }) keymap(NORMAL, '', ':bprev', { noremap = true }) keymap(INSERT, '', ':bnext', { noremap = true }) keymap(INSERT, '', ':bprev', { noremap = true }) keymap(NORMAL, 'ss', ':source ~/.config/nvim/init.lua', { noremap = true }) keymap(NORMAL, 'sc', ':source %', { noremap = true }) keymap(NORMAL, '', ':Telescope find_files follow=true', { noremap = true }) keymap(NORMAL, 't', ':NvimTreeToggle', { noremap = true }) keymap(NORMAL, 'tf', ':NvimTreeFindFile', { noremap = true }) keymap(NORMAL, 'ts', ':Telescope live_grep', { noremap = true }) keymap(NORMAL, 'tt', ':Telescope file_browser path=%:p:h', { noremap = true }) keymap(NORMAL, 'tb', ':Telescope buffers', { noremap = true }) keymap(NORMAL, 'tm', ':Telescope media_files', { noremap = true }) keymap(NORMAL, 'gc', ':Telescope git_branches', { noremap = true }) keymap(NORMAL, 'gr', ':Telescope lsp_references', { noremap = true }) keymap(NORMAL, 'gds', ':Telescope lsp_document_symbols', { noremap = true }) keymap(NORMAL, 'ca', ':lua vim.lsp.buf.code_action', { noremap = true }) keymap(NORMAL, 'gs', ':Git', { noremap = true }) keymap(NORMAL, 'gp', ':Git push', { noremap = true }) keymap(NORMAL, 'gg', ':Git pull', { noremap = true }) keymap(NORMAL, 'gb', ':Git blame', { noremap = true }) keymap(NORMAL, 'gl', ':Git log', { noremap = true }) keymap(NORMAL, 'gpr', ':!gpr', { noremap = true }) keymap(NORMAL, 'gp', ':GotoParent', { noremap = true }) keymap(NORMAL, 'sif', ':SearchInFolder', { noremap = true }) keymap(NORMAL, 'cx', ':ToggleExecutable', { noremap = true }) keymap(NORMAL, 'rs', ':RunScript', { noremap = true }) keymap(NORMAL, 'do', ':lua vim.diagnostic.open_float()', { noremap = true }) -- keymap(INSERT, '', '', { noremap = true }) -- keymap(INSERT, '', '', { noremap = true }) -- keymap(INSERT, '', '', { noremap = true }) -- keymap(INSERT, '', '', { noremap = true }) -- keymap(INSERT, '', '', { noremap = true }) -- keymap(INSERT, '', '', { noremap = true }) -- keymap(INSERT, '', '', { noremap = true }) vim.g.AutoPairsShortcutToggle = "ap" -- xnoremap r :s///g -- debugger local dap_ok, dap = pcall(require, "dap") if dap_ok then vim.keymap.set('n', 'db', function() dap.toggle_breakpoint() end) vim.keymap.set('n', 'dc', function() dap.set_breakpoint(vim.fn.input('Breakpoint condition: ')) end) vim.keymap.set('n', '', function() dap.step_out() end) vim.keymap.set('n', "", function() dap.step_into() end) vim.keymap.set('n', '', function() dap.step_over() end) vim.keymap.set('n', '', function() dap.continue() end) vim.keymap.set('n', 'dl', function() dap.run_to_cursor() end) vim.keymap.set('n', 'de', function() dap.terminate() end) vim.keymap.set('n', 'dB', function() dap.clear_breakpoints() end) -- vim.keymap.set('n', 'de', function() dap.set_exception_breakpoints({ "all" }) end) vim.keymap.set('n', 'da', function() require "debugHelper".attach() end) vim.keymap.set('n', 'dA', function() require "debugHelper".attachToRemote() end) vim.keymap.set('n', 'dh', function() require "dap.ui.widgets".hover() end) vim.keymap.set('n', 'd?', function() local w = require "dap.ui.widgets"; w.centered_float(w.scopes) end) vim.keymap.set('n', 'dk', function() dap.up() end) vim.keymap.set('n', 'dj', function() dap.down() end) vim.keymap.set('n', 'dr', function() dap.repl.toggle({}, "vsplit") end) vim.keymap.set('n', 'tds', ':Telescope dap frames') vim.keymap.set('n', 'tdb', ':Telescope dap list_breakpoints') end