local utils = require "core.utils" local config = utils.load_config() local map_wrapper = utils.map local maps = config.mappings local plugin_maps = maps.plugins local nvChad_options = config.options.nvChad local cmd = vim.cmd -- 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 local map = function(...) local keys = select(2, ...) if not keys or keys == "" then return end map_wrapper(...) end local M = {} -- these mappings will only be called during initialization M.misc = function() local function non_config_mappings() -- Don't copy the replaced text after pasting in visual mode map_wrapper("v", "p", '"_dP') -- 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_wrapper("", "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) map_wrapper("", "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) map_wrapper("", "", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true }) map_wrapper("", "", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true }) -- use ESC to turn off search highlighting map_wrapper("n", "", ":noh ") -- center cursor when moving (goto_definition) -- yank from current cursor to end of line map_wrapper("n", "Y", "yg$") end local function optional_mappings() -- don't yank text on cut ( x ) if not nvChad_options.copy_cut then map_wrapper({ "n", "v" }, "x", '"_x') end -- don't yank text on delete ( dd ) if not nvChad_options.copy_del then map_wrapper({ "n", "v" }, "d", '"_d') end -- navigation within insert mode if nvChad_options.insert_nav then local inav = maps.insert_nav map("i", inav.backward, "") map("i", inav.end_of_line, "") map("i", inav.forward, "") map("i", inav.next_line, "") map("i", inav.prev_line, "") map("i", inav.beginning_of_line, "^i") end -- easier navigation between windows if nvChad_options.window_nav then local wnav = maps.window_nav map("n", wnav.moveLeft, "h") map("n", wnav.moveRight, "l") map("n", wnav.moveUp, "k") map("n", wnav.moveDown, "j") end end local function required_mappings() map("n", maps.misc.cheatsheet, ":lua require('nvchad.cheatsheet').show() ") -- show keybinds map("n", maps.misc.close_buffer, ":lua require('core.utils').close_buffer() ") -- close buffer map("n", maps.misc.copy_whole_file, ":%y+ ") -- copy whole file content map("n", maps.misc.new_buffer, ":enew ") -- new buffer map("n", maps.misc.new_tab, ":tabnew ") -- new tabs map("n", maps.misc.line_number_toggle, ":set nu! ") -- toggle numbers map("n", maps.misc.save_file, ":w ") -- ctrl + s to save file -- terminal mappings -- local term_maps = maps.terminal -- get out of terminal mode map("t", term_maps.esc_termmode, "") -- hide a term from within terminal mode map("t", term_maps.esc_hide_termmode, " :lua require('core.utils').close_buffer() ") -- pick a hidden term map("n", term_maps.pick_term, ":Telescope terms ") -- Open terminals -- TODO this opens on top of an existing vert/hori term, fixme map("n", term_maps.new_horizontal, ":execute 15 .. 'new +terminal' | let b:term_type = 'hori' | startinsert ") map("n", term_maps.new_vertical, ":execute 'vnew +terminal' | let b:term_type = 'vert' | startinsert ") map("n", term_maps.new_window, ":execute 'terminal' | let b:term_type = 'wind' | startinsert ") -- terminal mappings end -- -- Add Packer commands because we are not loading it at startup cmd "silent! command PackerClean lua require 'plugins' require('packer').clean()" cmd "silent! command PackerCompile lua require 'plugins' require('packer').compile()" cmd "silent! command PackerInstall lua require 'plugins' require('packer').install()" cmd "silent! command PackerStatus lua require 'plugins' require('packer').status()" cmd "silent! command PackerSync lua require 'plugins' require('packer').sync()" cmd "silent! command PackerUpdate lua require 'plugins' require('packer').update()" -- add NvChadUpdate command and mapping cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" map("n", maps.misc.update_nvchad, ":NvChadUpdate ") end non_config_mappings() optional_mappings() required_mappings() end -- below are all plugin related mappings M.bufferline = function() local m = plugin_maps.bufferline map("n", m.next_buffer, ":BufferLineCycleNext ") map("n", m.prev_buffer, ":BufferLineCyclePrev ") end M.comment = function() local m = plugin_maps.comment.toggle map("n", m, ":lua require('Comment.api').toggle_current_linewise()") map("v", m, ":lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())") end M.dashboard = function() local m = plugin_maps.dashboard map("n", m.bookmarks, ":DashboardJumpMarks ") map("n", m.new_file, ":DashboardNewFile ") map("n", m.open, ":Dashboard ") map("n", m.session_load, ":SessionLoad ") map("n", m.session_save, ":SessionSave ") end M.lspconfig = function() local m = plugin_maps.lspconfig -- See `:help vim.lsp.*` for documentation on any of the below functions map("n", m.declaration, "lua vim.lsp.buf.declaration()") map("n", m.definition, "lua vim.lsp.buf.definition()") map("n", m.hover, "lua vim.lsp.buf.hover()") map("n", m.implementation, "lua vim.lsp.buf.implementation()") map("n", m.signature_help, "lua vim.lsp.buf.signature_help()") map("n", m.add_workspace_folder, "lua vim.lsp.buf.add_workspace_folder()") map("n", m.remove_workspace_folder, "lua vim.lsp.buf.remove_workspace_folder()") map("n", m.list_workspace_folders, "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))") map("n", m.type_definition, "lua vim.lsp.buf.type_definition()") map("n", m.rename, "lua vim.lsp.buf.rename()") map("n", m.code_action, "lua vim.lsp.buf.code_action()") map("n", m.references, "lua vim.lsp.buf.references()") map("n", m.float_diagnostics, "lua vim.diagnostic.open_float()") map("n", m.goto_prev, "lua vim.diagnostic.goto_prev()") map("n", m.goto_next, "lua vim.diagnostic.goto_next()") map("n", m.set_loclist, "lua vim.diagnostic.setloclist()") map("n", m.formatting, "lua vim.lsp.buf.formatting()") end M.nvimtree = function() map("n", plugin_maps.nvimtree.toggle, ":NvimTreeToggle ") map("n", plugin_maps.nvimtree.focus, ":NvimTreeFocus ") end M.telescope = function() local m = plugin_maps.telescope map("n", m.buffers, ":Telescope buffers ") map("n", m.find_files, ":Telescope find_files ") map("n", m.find_hiddenfiles, ":Telescope find_files follow=true no_ignore=true hidden=true ") map("n", m.git_commits, ":Telescope git_commits ") map("n", m.git_status, ":Telescope git_status ") map("n", m.help_tags, ":Telescope help_tags ") map("n", m.live_grep, ":Telescope live_grep ") map("n", m.oldfiles, ":Telescope oldfiles ") map("n", m.themes, ":Telescope themes ") end return M