local utils = require "core.utils" local config = utils.load_config() local map = utils.map local maps = config.mappings local plugin_maps = maps.plugin local cmd = vim.cmd 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("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 map("", "j", 'v:count ? "j" : "gj"', { expr = true }) map("", "k", 'v:count ? "k" : "gk"', { expr = true }) map("", "", 'v:count ? "j" : "gj"', { expr = true }) map("", "", 'v:count ? "k" : "gk"', { expr = true }) -- use ESC to turn off search highlighting map("n", "", ":noh ") end local function optional_mappings() -- don't yank text on cut ( x ) if not config.options.copy_cut then map({ "n", "v" }, "x", '"_x') end -- don't yank text on delete ( dd ) if not config.options.copy_del then map({ "n", "v" }, "dd", '"_dd') end -- navigation within insert mode if config.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.top_of_line, "^i") end -- check the theme toggler if config.ui.theme_toggler then map( "n", maps.theme_toggler, ":lua require('nvchad').toggle_theme(require('core.utils').load_config().ui.theme_toggler.fav_themes) " ) end end local function required_mappings() map("n", maps.close_buffer, ":lua require('core.utils').close_buffer() ") -- close buffer map("n", maps.copy_whole_file, ":%y+ ") -- copy whole file content map("n", maps.new_buffer, ":enew ") -- new buffer map("n", maps.new_tab, ":tabnew ") -- new tabs map("n", maps.line_number_toggle, ":set nu! ") -- toggle numbers map("n", maps.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.update_nvchad, ":NvChadUpdate ") -- add ChadReload command and maping cmd "silent! command! NvChadReload lua require('nvchad').reload_config()" end local function user_config_mappings() local custom_maps = config.custom.mappings or "" if type(custom_maps) ~= "table" then return end for _, map_table in pairs(custom_maps) do map(unpack(map_table)) end end non_config_mappings() optional_mappings() required_mappings() user_config_mappings() end -- below are all plugin related mappinsg M.better_escape = function() vim.g.better_escape_shortcut = plugin_maps.better_escape.esc_insertmode or { "" } end M.bufferline = function() local m = plugin_maps.bufferline map("n", m.next_buffer, ":BufferLineCycleNext ") map("n", m.prev_buffer, ":BufferLineCyclePrev ") end M.chadsheet = function() local m = plugin_maps.chadsheet map("n", m.default_keys, ":lua require('cheatsheet').show_cheatsheet_telescope() ") map( "n", m.user_keys, ":lua require('cheatsheet').show_cheatsheet_telescope{bundled_cheatsheets = false, bundled_plugin_cheatsheets = false } " ) end M.comment = function() local m = plugin_maps.comment.toggle map("n", m, ":CommentToggle ") map("v", m, ":CommentToggle ") 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.nvimtree = function() map("n", plugin_maps.nvimtree.toggle, ":NvimTreeToggle ") map("n", plugin_maps.nvimtree.focus, ":NvimTreeFocus ") end M.neoformat = function() map("n", plugin_maps.neoformat.format, ":Neoformat ") 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 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 M.telescope_media = function() local m = plugin_maps.telescope_media map("n", m.media_files, ":Telescope media_files ") end M.truezen = function() local m = plugin_maps.truezen map("n", m.ataraxis_mode, ":TZAtaraxis ") map("n", m.focus_mode, ":TZFocus ") map("n", m.minimalistic_mode, ":TZMinimalist ") end M.vim_fugitive = function() local m = plugin_maps.vim_fugitive map("n", m.git, ":Git ") map("n", m.git_blame, ":Git blame ") map("n", m.diff_get_2, ":diffget //2 ") map("n", m.diff_get_3, ":diffget //3 ") end return M