local utils = require "core.utils" local map = utils.map local cmd = vim.cmd local user_cmd = vim.api.nvim_create_user_command -- This is a wrapper function made to disable a plugin mapping from chadrc -- If keys are nil, false or empty string, then the mapping will be not applied -- Useful when one wants to use that keymap for any other purpose -- Don't copy the replaced text after pasting in visual mode map("v", "p", "p:let @+=@0") -- Allow moving the cursor through wrapped lines with j, k, and -- http ://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ -- empty mode is same as using :map -- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour map({ "n", "x", "o" }, "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) map({ "n", "x", "o" }, "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) map("", "", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) map("", "", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) -- use ESC to turn off search highlighting map("n", "", " :noh ") -- move cursor within insert mode map("i", "", "") map("i", "", "") map("i", "", "") map("i", "", "") map("i", "", "") map("i", "", "^i") -- navigation between windows map("n", "", "h") map("n", "", "l") map("n", "", "k") map("n", "", "j") map("n", "x", function() require("core.utils").close_buffer() end) map("n", "", " :%y+ ") -- copy whole file content map("n", "", " :enew ") -- new buffer map("n", "b", " :tabnew ") -- new tabs map("n", "n", " :set nu! ") map("n", "rn", " :set rnu! ") -- relative line numbers map("n", "", " :w ") -- ctrl + s to save file -- terminal mappings -- get out of terminal mode map("t", { "jk" }, "") -- hide a term from within terminal mode map("t", { "JK" }, function() require("nvchad.terminal").hide() end) -- Add Packer commands because we are not loading it at startup local packer_cmd = function(callback) return function() require "plugins" require("packer")[callback]() end end -- snapshot stuff user_cmd("PackerSnapshot", function(info) require "plugins" require("packer").snapshot(info.args) end, { nargs = "+" }) user_cmd("PackerSnapshotDelete", function(info) require "plugins" require("packer.snapshot").delete(info.args) end, { nargs = "+" }) user_cmd("PackerSnapshotRollback", function(info) require "plugins" require("packer").rollback(info.args) end, { nargs = "+" }) user_cmd("PackerClean", packer_cmd "clean", {}) user_cmd("PackerCompile", packer_cmd "compile", {}) user_cmd("PackerInstall", packer_cmd "install", {}) user_cmd("PackerStatus", packer_cmd "status", {}) user_cmd("PackerSync", packer_cmd "sync", {}) user_cmd("PackerUpdate", packer_cmd "update", {}) -- add NvChadUpdate command and mapping cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" map("n", "uu", " :NvChadUpdate ") -- load overriden misc mappings require("core.utils").load_config().mappings.misc() local M = {} -- below are all plugin related mappings M.bufferline = function() map("n", "", " :BufferLineCycleNext ") map("n", "", " :BufferLineCyclePrev ") end M.comment = function() map("n", "/", " :lua require('Comment.api').toggle_current_linewise()") map("v", "/", " :lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())") end M.lspconfig = function(bufnr) -- See ` :help vim.lsp.*` for documentation on any of the below functions local buf_map = function(...) local key, lhs, rhs = ... map(key, lhs, rhs, { buffer = bufnr }) end buf_map("n", "gD", function() vim.lsp.buf.declaration() end) buf_map("n", "gd", function() vim.lsp.buf.definition() end) buf_map("n", "K", function() vim.lsp.buf.hover() end) buf_map("n", "gi", function() vim.lsp.buf.implementation() end) buf_map("n", "", function() vim.lsp.buf.signature_help() end) buf_map("n", "D", function() vim.lsp.buf.type_definition() end) buf_map("n", "ra", function() vim.lsp.buf.rename() end) buf_map("n", "ca", function() vim.lsp.buf.code_action() end) buf_map("n", "gr", function() vim.lsp.buf.references() end) buf_map("n", "f", function() vim.diagnostic.open_float() end) buf_map("n", "[d", function() vim.diagnostic.goto_prev() end) buf_map("n", "d]", function() vim.diagnostic.goto_next() end) buf_map("n", "q", function() vim.diagnostic.setloclist() end) buf_map("n", "fm", function() vim.lsp.buf.formatting() end) buf_map("n", "wa", function() vim.lsp.buf.add_workspace_folder() end) buf_map("n", "wr", function() vim.lsp.buf.remove_workspace_folder() end) buf_map("n", "wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end) end M.nvimtree = function() map("n", "", " :NvimTreeToggle ") map("n", "e", " :NvimTreeFocus ") end M.telescope = function() map("n", "fb", " :Telescope buffers ") map("n", "ff", " :Telescope find_files ") map("n", "fa", " :Telescope find_files follow=true no_ignore=true hidden=true ") map("n", "cm", " :Telescope git_commits ") map("n", "gt", " :Telescope git_status ") map("n", "fh", " :Telescope help_tags ") map("n", "fw", " :Telescope live_grep ") map("n", "fo", " :Telescope oldfiles ") map("n", "th", " :Telescope themes ") -- pick a hidden term map("n", "W", " :Telescope terms ") end return M