vim.g.mapleader = " " vim.g.maplocalleader = " "
local map = vim.api.nvim_set_keymap local opt = { noremap = true, silent = true }
map("n", "Q", ":q<cr>", opt) map("n", "qQ", ":q!<cr>", opt) map("n", "W", ":w<cr>", opt) map("n", "S", ":wq<cr>", opt) map("n", "U", ":PackerSync<cr>", opt)
map("n", "h", "i", opt) map("i", "jj", "<esc>", opt) map("v", "jj", "<esc>", opt) map("i", "ji", "<esc>la", opt)
map("n", "i", "k", opt) map("n", "k", "j", opt) map("n", "j", "h", opt)
map("n", "I", "5k", opt) map("n", "K", "5j", opt) map("n", "J", "5h", opt) map("n", "L", "5l", opt)
map("n", "<C-i>", "15k", opt) map("n", "<C-k>", "15j", opt) map("n", "<C-j>", "15h", opt) map("n", "<C-l>", "15l", opt)
map("v", "i", "k", opt) map("v", "k", "j", opt) map("v", "j", "h", opt)
map("v", "I", "5k", opt) map("v", "K", "5j", opt) map("v", "J", "5h", opt) map("v", "L", "5l", opt)
map("v", "<C-i>", "15k", opt) map("v", "<C-k>", "15j", opt) map("v", "<C-j>", "15h", opt) map("v", "<C-l>", "15l", opt)
map("n", "s", "", opt)
map("n", "sl", ":vsp<CR>", opt) map("n", "sj", ":vsp<CR><C-w>h", opt) map("n", "sk", ":sp<CR>", opt) map("n", "si", ":sp<CR><C-w>k", opt)
map("n", "sc", "<C-w>c", opt)
map("n", "so", "<C-w>o", opt)
map("n", "<A-j>", "<C-w>h", opt) map("n", "<A-k>", "<C-w>j", opt) map("n", "<A-i>", "<C-w>k", opt) map("n", "<A-l>", "<C-w>l", opt)
map("n", "<A-L>", ":vertical resize -5<CR>", opt) map("n", "<A-J>", ":vertical resize +5<cr>", opt) map("n", "<leader>l", ":vertical resize -20<CR>", opt) map("n", "<leader>j", ":vertical resize +20<CR>", opt)
map("n", "<leader>i", ":resize +10<CR>", opt) map("n", "<leader>k", ":resize -10<CR>", opt) map("n", "<A-I>", ":resize +5<CR>", opt) map("n", "<A-K>", ":resize -5<CR>", opt)
map("n", "s=", "<C-w>=", opt)
map("n", "<leader>t", ":sp | terminal<CR>", opt) map("n", "<leader>vt", ":vsp | terminal<CR>", opt) map("t", "<Esc>", "<C-\\><C-n>", opt) map("t", "<A-j>", [[ <C-\><C-N><C-w>h ]], opt) map("t", "<A-k>", [[ <C-\><C-N><C-w>j ]], opt) map("t", "<A-j>", [[ <C-\><C-N><C-w>k ]], opt) map("t", "<A-l>", [[ <C-\><C-N><C-w>l ]], opt)
map("v", "<", "<gv", opt) map("v", ">", ">gv", opt)
map("v", "<C-K>", ":move '>+1<CR>gv-gv", opt) map("v", "<C-I>", ":move '<-2<CR>gv-gv", opt)
map("v", "p", '"_dP', opt)
map("i", "<C-j>", "<ESC>I", opt) map("i", "<C-l>", "<ESC>A", opt)
local pluginKeys = {}
map("n", "<A-m>", ":NvimTreeToggle<CR>", opt)
pluginKeys.nvimTreeList = { { key = { "<CR>", "o", "<2-LeftMouse>" }, action = "edit" }, { key = "v", action = "vsplit" }, { key = "h", action = "split" }, { key = ".", action = "toggle_dotfiles" }, { key = "<F5>", action = "refresh" }, { key = "a", action = "create" }, { key = "d", action = "remove" }, { key = "r", action = "rename" }, { key = "x", action = "cut" }, { key = "c", action = "copy" }, { key = "p", action = "paste" }, }
map("n", "<C-j>", ":BufferLineCyclePrev<CR>", opt) map("n", "<C-l>", ":BufferLineCycleNext<CR>", opt)
map("n", "<C-w>", ":Bdelete!<CR>", opt) map("n", "<leader>bl", ":BufferLineCloseRight<CR>", opt) map("n", "<leader>bh", ":BufferLineCloseLeft<CR>", opt) map("n", "<leader>bc", ":BufferLinePickClose<CR>", opt)
map("n", "<C-p>", ":Telescope find_files<CR>", opt)
map("n", "<C-f>", ":Telescope live_grep<CR>", opt) pluginKeys.telescopeList = { i = { ["<C-k>"] = "move_selection_next", ["<C-i>"] = "move_selection_previous", ["<Down>"] = "move_selection_next", ["<Up>"] = "move_selection_previous", ["<C-n>"] = "cycle_history_next", ["<C-p>"] = "cycle_history_prev", ["<C-c>"] = "close", ["<Esc>"] = "close", ["<C-u>"] = "preview_scrolling_up", ["<C-d>"] = "preview_scrolling_down", }, }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
local on_attach = function(client, bufnr) vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') local bufopts = { noremap=true, silent=true, buffer=bufnr } vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) map("n", "gh", vim.lsp.buf.hover, opt) vim.keymap.set('n', 'gh', vim.lsp.buf.hover, bufopts) vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) vim.keymap.set('n', '<space>wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, bufopts) vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts) vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, bufopts) end local lsp_flags = { debounce_text_changes = 150, } require('lspconfig')['pyright'].setup{ on_attach = on_attach, flags = lsp_flags, } require('lspconfig')['clangd'].setup{ on_attach = on_attach, flags = lsp_flags, }
pluginKeys.cmp = function(cmp) local feedkey = function(key, mode) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) end
local has_words_before = function() local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end
return {
["<C-l>"] = cmp.mapping(function(_) if vim.fn["vsnip#available"](1) == 1 then feedkey("<Plug>(vsnip-expand-or-jump)", "") end end, { "i", "s" }),
["<C-h>"] = cmp.mapping(function() if vim.fn["vsnip#jumpable"](-1) == 1 then feedkey("<Plug>(vsnip-jump-prev)", "") end end, { "i", "s" }),
["<Tab>"] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif vim.fn["vsnip#available"](1) == 1 then feedkey("<Plug>(vsnip-expand-or-jump)", "") elseif has_words_before() then cmp.complete() else fallback() end end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function() if cmp.visible() then cmp.select_prev_item() elseif vim.fn["vsnip#jumpable"](-1) == 1 then feedkey("<Plug>(vsnip-jump-prev)", "") end end, { "i", "s" }), } end
map("n", "<leader>f", ":Format<CR>", opt) map("n", "<leader>F", ":FormatWrite<CR>", opt)
return pluginKeys
|