2022-07-06 14:50:45 +00:00
|
|
|
local keymap = vim.api.nvim_set_keymap
|
|
|
|
local NORMAL = 'n'
|
|
|
|
local INSERT = 'i'
|
|
|
|
local VISUAL = 'v'
|
|
|
|
local COMMAND = 'c'
|
|
|
|
|
|
|
|
|
2022-07-24 16:38:33 +00:00
|
|
|
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
|
2022-12-07 11:51:41 +00:00
|
|
|
if vim.api.nvim_buf_is_loaded(bufnr) and not vim.api.nvim_buf_get_option(bufnr, "modified") then
|
2022-07-24 16:38:33 +00:00
|
|
|
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
|
|
|
if bufname ~= current_buffer_name then
|
|
|
|
vim.cmd(":bd " .. bufnr)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end, {})
|
|
|
|
|
2022-12-08 10:36:02 +00:00
|
|
|
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, {})
|
|
|
|
|
2023-01-14 03:00:05 +00:00
|
|
|
-- command mode
|
|
|
|
keymap(COMMAND, '<C-a>', '<Home>', { noremap = true })
|
|
|
|
keymap(COMMAND, '<C-e>', '<End>', { noremap = true })
|
|
|
|
keymap(COMMAND, '<C-f>', '<Right>', { noremap = true })
|
|
|
|
keymap(COMMAND, '<C-b>', '<Left>', { noremap = true })
|
|
|
|
keymap(COMMAND, '<C-d>', '<Delete>', { noremap = true })
|
|
|
|
keymap(COMMAND, '<C-n>', '<Down>', { noremap = true })
|
|
|
|
keymap(COMMAND, '<C-p>', '<Up>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<c-s>', ':w<cr>', { noremap = true })
|
|
|
|
keymap(INSERT, '<c-s>', '<esc>:w<cr>a', { noremap = true })
|
2022-07-24 16:38:33 +00:00
|
|
|
|
2022-07-06 14:50:45 +00:00
|
|
|
keymap(NORMAL, '<leader>w', ':w<cr>', { noremap = true })
|
|
|
|
keymap(VISUAL, '<leader>y', '"+y<cr>', { noremap = true })
|
2022-07-09 14:29:52 +00:00
|
|
|
keymap(NORMAL, '<leader>yp', ':let @+=expand("%:p")<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>yn', ':let @+=expand("%:t")<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>yl', ':let @+=expand("%") . ":" . line(".")<cr>', { noremap = true })
|
2022-07-08 07:14:39 +00:00
|
|
|
keymap(VISUAL, '<leader>p', '"0p<cr>', { noremap = true })
|
2022-07-06 14:50:45 +00:00
|
|
|
keymap(NORMAL, '<leader>q', ':bd<cr>', { noremap = true })
|
2022-12-08 10:36:02 +00:00
|
|
|
keymap(NORMAL, '<leader>qq', ':Exit<cr>', { noremap = true })
|
2022-07-06 14:50:45 +00:00
|
|
|
keymap(NORMAL, '<leader>ne', ':e %:h<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>h', '<c-w>h', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>j', '<c-w>j', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>k', '<c-w>k', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>l', '<c-w>l', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>oo', '<c-w>o', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader><esc>', ':noh<cr>', { noremap = true })
|
2023-01-14 03:00:05 +00:00
|
|
|
keymap(NORMAL, '<leader>cn', ':cnext<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>cp', ':cprev<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>bo', ':CloseOtherBuffers<cr>', { noremap = true })
|
|
|
|
-- search and replace highlighted
|
|
|
|
keymap(VISUAL, '/', "y/\\V<C-R>=escape(@\",'/\\')<CR><CR>", { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>r', ':%s///g<left><left>', { noremap = true })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
keymap(NORMAL, '<c-pagedown>', ':bnext<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<c-pageup>', ':bprev<cr>', { noremap = true })
|
|
|
|
keymap(INSERT, '<c-pagedown>', '<esc>:bnext<cr>', { noremap = true })
|
|
|
|
keymap(INSERT, '<c-pageup>', '<esc>:bprev<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>ss', ':source ~/.config/nvim/init.lua<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>sc', ':source %<cr>', { noremap = true })
|
2022-07-06 14:50:45 +00:00
|
|
|
keymap(NORMAL, '<c-p>', ':Telescope find_files follow=true<cr>', { noremap = true })
|
2022-07-07 15:29:02 +00:00
|
|
|
keymap(NORMAL, '<leader>t', ':NvimTreeToggle<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>tf', ':NvimTreeFindFile<cr>', { noremap = true })
|
2022-07-06 14:50:45 +00:00
|
|
|
keymap(NORMAL, '<leader>ts', ':Telescope live_grep<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>tt', ':Telescope file_browser path=%:p:h<cr>', { noremap = true })
|
2022-07-09 14:29:52 +00:00
|
|
|
keymap(NORMAL, '<leader>tb', ':Telescope buffers<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>tm', ':Telescope media_files<cr>', { noremap = true })
|
2022-07-06 14:50:45 +00:00
|
|
|
keymap(NORMAL, '<leader>gc', ':Telescope git_branches<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>gr', ':Telescope lsp_references<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>gds', ':Telescope lsp_document_symbols<cr>', { noremap = true })
|
2022-09-24 07:59:11 +00:00
|
|
|
keymap(NORMAL, '<leader>ca', ':lua vim.lsp.buf.code_action', { noremap = true })
|
2022-07-06 14:50:45 +00:00
|
|
|
keymap(NORMAL, '<leader>gs', ':Git<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>gp', ':Git push<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>gg', ':Git pull<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>gb', ':Git blame<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>gl', ':Git log<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>gpr', ':!gpr<cr>', { noremap = true })
|
2022-07-24 16:38:33 +00:00
|
|
|
keymap(NORMAL, 'gp', ':GotoParent<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>sif', ':SearchInFolder<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>cx', ':ToggleExecutable<cr>', { noremap = true })
|
|
|
|
keymap(NORMAL, '<leader>rs', ':RunScript<cr>', { noremap = true })
|
2022-10-23 14:34:26 +00:00
|
|
|
keymap(NORMAL, '<leader>do', ':lua vim.diagnostic.open_float()<cr>', { noremap = true })
|
2022-07-06 14:50:45 +00:00
|
|
|
|
|
|
|
|
2022-07-09 14:29:52 +00:00
|
|
|
-- keymap(INSERT, '<C-a>', '<Home>', { noremap = true })
|
|
|
|
-- keymap(INSERT, '<C-e>', '<End>', { noremap = true })
|
|
|
|
-- keymap(INSERT, '<C-f>', '<Right>', { noremap = true })
|
|
|
|
-- keymap(INSERT, '<C-b>', '<Left>', { noremap = true })
|
|
|
|
-- keymap(INSERT, '<C-d>', '<Delete>', { noremap = true })
|
|
|
|
-- keymap(INSERT, '<C-n>', '<Down>', { noremap = true })
|
|
|
|
-- keymap(INSERT, '<C-p>', '<Up>', { noremap = true })
|
2022-07-24 16:38:33 +00:00
|
|
|
|
|
|
|
vim.g.AutoPairsShortcutToggle = "<leader>ap"
|
2022-07-30 02:23:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- xnoremap <leader>r :s///g<left><left>
|
|
|
|
|
|
|
|
-- debugger
|
|
|
|
local dap_ok, dap = pcall(require, "dap")
|
|
|
|
if dap_ok then
|
|
|
|
vim.keymap.set('n', '<leader>db', function() dap.toggle_breakpoint() end)
|
|
|
|
vim.keymap.set('n', '<leader>dc', function() dap.set_breakpoint(vim.fn.input('Breakpoint condition: ')) end)
|
|
|
|
vim.keymap.set('n', '<C-k>', function() dap.step_out() end)
|
|
|
|
vim.keymap.set('n', "<C-l>", function() dap.step_into() end)
|
|
|
|
vim.keymap.set('n', '<C-j>', function() dap.step_over() end)
|
|
|
|
vim.keymap.set('n', '<C-h>', function() dap.continue() end)
|
|
|
|
vim.keymap.set('n', '<leader>dl', function() dap.run_to_cursor() end)
|
|
|
|
vim.keymap.set('n', '<leader>de', function() dap.terminate() end)
|
|
|
|
vim.keymap.set('n', '<leader>dB', function() dap.clear_breakpoints() end)
|
|
|
|
-- vim.keymap.set('n', '<leader>de', function() dap.set_exception_breakpoints({ "all" }) end)
|
|
|
|
vim.keymap.set('n', '<leader>da', function() require "debugHelper".attach() end)
|
|
|
|
vim.keymap.set('n', '<leader>dA', function() require "debugHelper".attachToRemote() end)
|
|
|
|
vim.keymap.set('n', '<leader>dh', function() require "dap.ui.widgets".hover() end)
|
|
|
|
vim.keymap.set('n', '<leader>d?', function() local w = require "dap.ui.widgets"; w.centered_float(w.scopes) end)
|
|
|
|
vim.keymap.set('n', '<leader>dk', function() dap.up() end)
|
|
|
|
vim.keymap.set('n', '<leader>dj', function() dap.down() end)
|
|
|
|
vim.keymap.set('n', '<leader>dr', function() dap.repl.toggle({}, "vsplit") end)
|
|
|
|
vim.keymap.set('n', '<leader>tds', ':Telescope dap frames<CR>')
|
|
|
|
vim.keymap.set('n', '<leader>tdb', ':Telescope dap list_breakpoints<CR>')
|
|
|
|
end
|