2021-08-25 06:28:56 +01:00
|
|
|
local utils = require "core.utils"
|
|
|
|
|
|
|
|
local config = utils.load_config()
|
|
|
|
local map = utils.map
|
|
|
|
|
2021-08-22 08:49:15 +01:00
|
|
|
local maps = config.mappings
|
|
|
|
local plugin_maps = maps.plugin
|
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
local cmd = vim.cmd
|
2021-08-22 08:49:15 +01:00
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
local M = {}
|
2021-08-22 08:49:15 +01:00
|
|
|
|
|
|
|
-- 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
|
2021-08-25 06:28:56 +01:00
|
|
|
map("v", "p", '"_dP')
|
2021-08-22 08:49:15 +01:00
|
|
|
|
|
|
|
-- Allow moving the cursor through wrapped lines with j, k, <Up> and <Down>
|
|
|
|
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
|
|
|
|
-- empty mode is same as using :map
|
2021-08-27 04:00:14 +01:00
|
|
|
-- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour
|
|
|
|
map("", "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true })
|
|
|
|
map("", "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true })
|
|
|
|
map("", "<Down>", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true })
|
|
|
|
map("", "<Up>", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true })
|
2021-08-22 08:49:15 +01:00
|
|
|
|
|
|
|
-- use ESC to turn off search highlighting
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", "<Esc>", ":noh <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function optional_mappings()
|
2021-08-22 20:40:31 +01:00
|
|
|
-- 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
|
|
|
|
|
2021-08-22 08:49:15 +01:00
|
|
|
-- navigation within insert mode
|
|
|
|
if config.options.insert_nav then
|
|
|
|
local inav = maps.insert_nav
|
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
map("i", inav.backward, "<Left>")
|
|
|
|
map("i", inav.end_of_line, "<End>")
|
|
|
|
map("i", inav.forward, "<Right>")
|
|
|
|
map("i", inav.next_line, "<Up>")
|
|
|
|
map("i", inav.prev_line, "<Down>")
|
|
|
|
map("i", inav.top_of_line, "<ESC>^i")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- check the theme toggler
|
|
|
|
if config.ui.theme_toggler then
|
|
|
|
map(
|
|
|
|
"n",
|
|
|
|
maps.theme_toggler,
|
2021-08-25 15:43:47 +01:00
|
|
|
":lua require('nvchad').toggle_theme(require('core.utils').load_config().ui.theme_toggler.fav_themes) <CR>"
|
2021-08-22 08:49:15 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function required_mappings()
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", maps.close_buffer, ":lua require('core.utils').close_buffer() <CR>") -- close buffer
|
|
|
|
map("n", maps.copy_whole_file, ":%y+ <CR>") -- copy whole file content
|
|
|
|
map("n", maps.new_buffer, ":enew <CR>") -- new buffer
|
|
|
|
map("n", maps.new_tab, ":tabnew <CR>") -- new tabs
|
|
|
|
map("n", maps.line_number_toggle, ":set nu! <CR>") -- toggle numbers
|
|
|
|
map("n", maps.save_file, ":w <CR>") -- ctrl + s to save file
|
2021-08-22 08:49:15 +01:00
|
|
|
|
|
|
|
-- terminal mappings --
|
|
|
|
local term_maps = maps.terminal
|
|
|
|
-- get out of terminal mode
|
2021-08-25 06:28:56 +01:00
|
|
|
map("t", term_maps.esc_termmode, "<C-\\><C-n>")
|
2021-08-22 08:49:15 +01:00
|
|
|
-- hide a term from within terminal mode
|
2021-08-25 06:28:56 +01:00
|
|
|
map("t", term_maps.esc_hide_termmode, "<C-\\><C-n> :lua require('core.utils').close_buffer() <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
-- pick a hidden term
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", term_maps.pick_term, ":Telescope terms <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
-- Open terminals
|
|
|
|
-- TODO this opens on top of an existing vert/hori term, fixme
|
2021-08-25 15:43:47 +01:00
|
|
|
map("n", term_maps.new_horizontal, ":execute 15 .. 'new +terminal' | let b:term_type = 'hori' | startinsert <CR>")
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", term_maps.new_vertical, ":execute 'vnew +terminal' | let b:term_type = 'vert' | startinsert <CR>")
|
|
|
|
map("n", term_maps.new_window, ":execute 'terminal' | let b:term_type = 'wind' | startinsert <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
-- terminal mappings end --
|
|
|
|
|
|
|
|
-- Add Packer commands because we are not loading it at startup
|
2021-08-21 17:59:15 +01:00
|
|
|
cmd "silent! command PackerClean lua require 'plugins' require('packer').clean()"
|
2021-08-22 08:49:15 +01:00
|
|
|
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()"
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", maps.update_nvchad, ":NvChadUpdate <CR>")
|
2021-08-25 15:39:20 +01:00
|
|
|
|
|
|
|
-- add ChadReload command and maping
|
2021-08-26 18:29:05 +01:00
|
|
|
-- cmd "silent! command! NvChadReload lua require('nvchad').reload_config()"
|
2021-08-25 06:28:56 +01:00
|
|
|
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
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
non_config_mappings()
|
|
|
|
optional_mappings()
|
|
|
|
required_mappings()
|
2021-08-25 06:28:56 +01:00
|
|
|
user_config_mappings()
|
2021-08-22 08:49:15 +01:00
|
|
|
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
|
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", m.next_buffer, ":BufferLineCycleNext <CR>")
|
|
|
|
map("n", m.prev_buffer, ":BufferLineCyclePrev <CR>")
|
2021-08-27 06:50:07 +01:00
|
|
|
map("n", m.moveLeft, "<C-w>h")
|
|
|
|
map("n", m.moveRight, "<C-w>l")
|
|
|
|
map("n", m.moveUp, "<C-w>k")
|
|
|
|
map("n", m.moveDown, "<C-w>j")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
M.chadsheet = function()
|
|
|
|
local m = plugin_maps.chadsheet
|
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", m.default_keys, ":lua require('cheatsheet').show_cheatsheet_telescope() <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
map(
|
|
|
|
"n",
|
|
|
|
m.user_keys,
|
2021-08-25 15:43:47 +01:00
|
|
|
":lua require('cheatsheet').show_cheatsheet_telescope{bundled_cheatsheets = false, bundled_plugin_cheatsheets = false } <CR>"
|
2021-08-22 08:49:15 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
M.comment = function()
|
|
|
|
local m = plugin_maps.comment.toggle
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", m, ":CommentToggle <CR>")
|
|
|
|
map("v", m, ":CommentToggle <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
M.dashboard = function()
|
|
|
|
local m = plugin_maps.dashboard
|
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", m.bookmarks, ":DashboardJumpMarks <CR>")
|
|
|
|
map("n", m.new_file, ":DashboardNewFile <CR>")
|
|
|
|
map("n", m.open, ":Dashboard <CR>")
|
|
|
|
map("n", m.session_load, ":SessionLoad <CR>")
|
|
|
|
map("n", m.session_save, ":SessionSave <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
M.nvimtree = function()
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", plugin_maps.nvimtree.toggle, ":NvimTreeToggle <CR>")
|
2021-08-25 15:43:47 +01:00
|
|
|
map("n", plugin_maps.nvimtree.focus, ":NvimTreeFocus <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
M.neoformat = function()
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", plugin_maps.neoformat.format, ":Neoformat <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
M.telescope = function()
|
|
|
|
local m = plugin_maps.telescope
|
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", m.buffers, ":Telescope buffers <CR>")
|
|
|
|
map("n", m.find_files, ":Telescope find_files <CR>")
|
2021-08-25 15:43:47 +01:00
|
|
|
map("n", m.find_hiddenfiles, ":Telescope find_files hidden=true <CR>")
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", m.git_commits, ":Telescope git_commits <CR>")
|
|
|
|
map("n", m.git_status, ":Telescope git_status <CR>")
|
|
|
|
map("n", m.help_tags, ":Telescope help_tags <CR>")
|
|
|
|
map("n", m.live_grep, ":Telescope live_grep <CR>")
|
|
|
|
map("n", m.oldfiles, ":Telescope oldfiles <CR>")
|
|
|
|
map("n", m.themes, ":Telescope themes <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
M.telescope_media = function()
|
|
|
|
local m = plugin_maps.telescope_media
|
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", m.media_files, ":Telescope media_files <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
M.truezen = function()
|
|
|
|
local m = plugin_maps.truezen
|
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", m.ataraxis_mode, ":TZAtaraxis <CR>")
|
|
|
|
map("n", m.focus_mode, ":TZFocus <CR>")
|
|
|
|
map("n", m.minimalistic_mode, ":TZMinimalist <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
M.vim_fugitive = function()
|
|
|
|
local m = plugin_maps.vim_fugitive
|
|
|
|
|
2021-08-25 06:28:56 +01:00
|
|
|
map("n", m.git, ":Git <CR>")
|
|
|
|
map("n", m.git_blame, ":Git blame <CR>")
|
|
|
|
map("n", m.diff_get_2, ":diffget //2 <CR>")
|
|
|
|
map("n", m.diff_get_3, ":diffget //3 <CR>")
|
2021-08-22 08:49:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|