2021-08-25 07:28:56 +02:00
|
|
|
local utils = require "core.utils"
|
|
|
|
|
|
|
|
local config = utils.load_config()
|
2022-01-22 08:21:12 +01:00
|
|
|
local map_wrapper = utils.map
|
2021-09-04 06:34:16 +02:00
|
|
|
|
2021-08-22 09:49:15 +02:00
|
|
|
local maps = config.mappings
|
2021-09-19 10:11:28 +02:00
|
|
|
local plugin_maps = maps.plugins
|
|
|
|
local nvChad_options = config.options.nvChad
|
2022-03-20 22:22:16 +01:00
|
|
|
local terminal_options = config.options.terminal
|
2021-08-22 09:49:15 +02:00
|
|
|
|
2021-08-25 07:28:56 +02:00
|
|
|
local cmd = vim.cmd
|
2021-08-22 09:49:15 +02:00
|
|
|
|
2022-01-22 08:21:12 +01:00
|
|
|
-- 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
|
|
|
|
|
2021-08-25 07:28:56 +02:00
|
|
|
local M = {}
|
2021-08-22 09:49:15 +02: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
|
2022-03-01 08:13:34 +01:00
|
|
|
map_wrapper("v", "p", "p:let @+=@0<CR>")
|
2021-08-22 09:49:15 +02: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 05:00:14 +02:00
|
|
|
-- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour
|
2022-04-01 08:17:05 +02:00
|
|
|
map_wrapper({ "n", "x", "o" }, "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true })
|
|
|
|
map_wrapper({ "n", "x", "o" }, "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true })
|
2022-01-22 08:21:12 +01:00
|
|
|
map_wrapper("", "<Down>", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { expr = true })
|
|
|
|
map_wrapper("", "<Up>", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { expr = true })
|
2021-08-22 09:49:15 +02:00
|
|
|
|
|
|
|
-- use ESC to turn off search highlighting
|
2022-01-22 08:21:12 +01:00
|
|
|
map_wrapper("n", "<Esc>", ":noh <CR>")
|
2021-11-24 15:38:11 +01:00
|
|
|
|
|
|
|
-- center cursor when moving (goto_definition)
|
|
|
|
|
|
|
|
-- yank from current cursor to end of line
|
2022-01-22 08:21:12 +01:00
|
|
|
map_wrapper("n", "Y", "yg$")
|
2021-08-22 09:49:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function optional_mappings()
|
2021-08-22 21:40:31 +02:00
|
|
|
-- don't yank text on cut ( x )
|
2021-09-19 10:11:28 +02:00
|
|
|
if not nvChad_options.copy_cut then
|
2022-01-22 08:21:12 +01:00
|
|
|
map_wrapper({ "n", "v" }, "x", '"_x')
|
2021-08-22 21:40:31 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- don't yank text on delete ( dd )
|
2021-09-19 10:11:28 +02:00
|
|
|
if not nvChad_options.copy_del then
|
2022-01-22 08:21:12 +01:00
|
|
|
map_wrapper({ "n", "v" }, "d", '"_d')
|
2021-08-22 21:40:31 +02:00
|
|
|
end
|
|
|
|
|
2021-08-22 09:49:15 +02:00
|
|
|
-- navigation within insert mode
|
2021-09-19 10:11:28 +02:00
|
|
|
if nvChad_options.insert_nav then
|
2021-08-22 09:49:15 +02:00
|
|
|
local inav = maps.insert_nav
|
|
|
|
|
2021-08-25 07:28:56 +02: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>")
|
2021-10-16 17:54:17 +02:00
|
|
|
map("i", inav.beginning_of_line, "<ESC>^i")
|
2021-08-22 09:49:15 +02:00
|
|
|
end
|
|
|
|
|
2021-09-04 06:34:16 +02:00
|
|
|
-- easier navigation between windows
|
2021-09-19 10:11:28 +02:00
|
|
|
if nvChad_options.window_nav then
|
2021-09-04 06:34:16 +02:00
|
|
|
local wnav = maps.window_nav
|
|
|
|
|
|
|
|
map("n", wnav.moveLeft, "<C-w>h")
|
|
|
|
map("n", wnav.moveRight, "<C-w>l")
|
|
|
|
map("n", wnav.moveUp, "<C-w>k")
|
|
|
|
map("n", wnav.moveDown, "<C-w>j")
|
2021-09-24 15:27:36 +02:00
|
|
|
end
|
2021-08-22 09:49:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function required_mappings()
|
2021-12-04 16:34:04 +01:00
|
|
|
map("n", maps.misc.cheatsheet, ":lua require('nvchad.cheatsheet').show() <CR>") -- show keybinds
|
2021-11-14 08:13:36 +01:00
|
|
|
map("n", maps.misc.close_buffer, ":lua require('core.utils').close_buffer() <CR>") -- close buffer
|
2022-03-02 10:06:21 +01:00
|
|
|
map("n", maps.misc.cp_whole_file, ":%y+ <CR>") -- copy whole file content
|
2021-11-14 08:13:36 +01:00
|
|
|
map("n", maps.misc.new_buffer, ":enew <CR>") -- new buffer
|
|
|
|
map("n", maps.misc.new_tab, ":tabnew <CR>") -- new tabs
|
2022-03-01 08:13:34 +01:00
|
|
|
map("n", maps.misc.lineNR_toggle, ":set nu! <CR>")
|
|
|
|
map("n", maps.misc.lineNR_rel_toggle, ":set rnu! <CR>") -- relative line numbers
|
2021-11-14 08:13:36 +01:00
|
|
|
map("n", maps.misc.save_file, ":w <CR>") -- ctrl + s to save file
|
2021-08-22 09:49:15 +02:00
|
|
|
|
|
|
|
-- terminal mappings --
|
|
|
|
local term_maps = maps.terminal
|
|
|
|
-- get out of terminal mode
|
2021-08-25 07:28:56 +02:00
|
|
|
map("t", term_maps.esc_termmode, "<C-\\><C-n>")
|
2021-08-22 09:49:15 +02:00
|
|
|
-- hide a term from within terminal mode
|
2022-03-20 22:22:16 +01:00
|
|
|
map("t", term_maps.esc_hide_termmode, "<CMD>lua require('nvchad.terminal').hide() <CR>")
|
2021-08-22 09:49:15 +02:00
|
|
|
-- pick a hidden term
|
2021-08-25 07:28:56 +02:00
|
|
|
map("n", term_maps.pick_term, ":Telescope terms <CR>")
|
2021-08-22 09:49:15 +02:00
|
|
|
-- Open terminals
|
|
|
|
-- TODO this opens on top of an existing vert/hori term, fixme
|
2022-03-20 22:22:16 +01:00
|
|
|
map(
|
|
|
|
{ "n", "t" },
|
|
|
|
term_maps.new_horizontal,
|
|
|
|
"<CMD>lua require('nvchad.terminal').new_or_toggle('horizontal', "
|
|
|
|
.. tostring(terminal_options.window.split_height)
|
|
|
|
.. ")<CR>"
|
|
|
|
)
|
|
|
|
map(
|
|
|
|
{ "n", "t" },
|
|
|
|
term_maps.new_vertical,
|
|
|
|
"<CMD>lua require('nvchad.terminal').new_or_toggle('vertical', "
|
|
|
|
.. tostring(terminal_options.window.vsplit_width)
|
|
|
|
.. ")<CR>"
|
|
|
|
)
|
2022-04-01 08:17:05 +02:00
|
|
|
|
|
|
|
-- spawns terminals
|
|
|
|
map(
|
|
|
|
"n",
|
|
|
|
term_maps.spawn_horizontal,
|
|
|
|
":execute 15 .. 'new +terminal' | let b:term_type = 'hori' | startinsert <CR>"
|
|
|
|
)
|
|
|
|
map("n", term_maps.spawn_vertical, ":execute 'vnew +terminal' | let b:term_type = 'vert' | startinsert <CR>")
|
2022-04-01 09:24:37 +02:00
|
|
|
map("n", term_maps.spawn_window, ":execute 'terminal' | let b:term_type = 'wind' | startinsert <CR>")
|
2022-04-01 08:17:05 +02:00
|
|
|
|
2021-08-22 09:49:15 +02:00
|
|
|
-- terminal mappings end --
|
|
|
|
|
|
|
|
-- Add Packer commands because we are not loading it at startup
|
2021-08-21 18:59:15 +02:00
|
|
|
cmd "silent! command PackerClean lua require 'plugins' require('packer').clean()"
|
2021-08-22 09:49:15 +02: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-11-14 08:13:36 +01:00
|
|
|
map("n", maps.misc.update_nvchad, ":NvChadUpdate <CR>")
|
2021-08-25 07:28:56 +02:00
|
|
|
end
|
|
|
|
|
2021-08-22 09:49:15 +02:00
|
|
|
non_config_mappings()
|
|
|
|
optional_mappings()
|
|
|
|
required_mappings()
|
|
|
|
end
|
|
|
|
|
2021-08-31 17:16:57 +02:00
|
|
|
-- below are all plugin related mappings
|
2021-08-22 09:49:15 +02:00
|
|
|
|
|
|
|
M.bufferline = function()
|
|
|
|
local m = plugin_maps.bufferline
|
|
|
|
|
2021-08-25 07:28:56 +02:00
|
|
|
map("n", m.next_buffer, ":BufferLineCycleNext <CR>")
|
|
|
|
map("n", m.prev_buffer, ":BufferLineCyclePrev <CR>")
|
2021-08-22 09:49:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
M.comment = function()
|
|
|
|
local m = plugin_maps.comment.toggle
|
2021-12-16 14:25:33 +01:00
|
|
|
map("n", m, ":lua require('Comment.api').toggle_current_linewise()<CR>")
|
|
|
|
map("v", m, ":lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())<CR>")
|
2021-08-22 09:49:15 +02:00
|
|
|
end
|
|
|
|
|
2021-12-18 23:39:59 +01:00
|
|
|
M.lspconfig = function()
|
|
|
|
local m = plugin_maps.lspconfig
|
|
|
|
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
|
|
map("n", m.declaration, "<cmd>lua vim.lsp.buf.declaration()<CR>")
|
|
|
|
map("n", m.definition, "<cmd>lua vim.lsp.buf.definition()<CR>")
|
|
|
|
map("n", m.hover, "<cmd>lua vim.lsp.buf.hover()<CR>")
|
|
|
|
map("n", m.implementation, "<cmd>lua vim.lsp.buf.implementation()<CR>")
|
|
|
|
map("n", m.signature_help, "<cmd>lua vim.lsp.buf.signature_help()<CR>")
|
|
|
|
map("n", m.add_workspace_folder, "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>")
|
|
|
|
map("n", m.remove_workspace_folder, "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>")
|
|
|
|
map("n", m.list_workspace_folders, "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>")
|
|
|
|
map("n", m.type_definition, "<cmd>lua vim.lsp.buf.type_definition()<CR>")
|
|
|
|
map("n", m.rename, "<cmd>lua vim.lsp.buf.rename()<CR>")
|
|
|
|
map("n", m.code_action, "<cmd>lua vim.lsp.buf.code_action()<CR>")
|
|
|
|
map("n", m.references, "<cmd>lua vim.lsp.buf.references()<CR>")
|
2021-12-22 13:35:07 +01:00
|
|
|
map("n", m.float_diagnostics, "<cmd>lua vim.diagnostic.open_float()<CR>")
|
|
|
|
map("n", m.goto_prev, "<cmd>lua vim.diagnostic.goto_prev()<CR>")
|
|
|
|
map("n", m.goto_next, "<cmd>lua vim.diagnostic.goto_next()<CR>")
|
2021-12-23 13:54:42 +01:00
|
|
|
map("n", m.set_loclist, "<cmd>lua vim.diagnostic.setloclist()<CR>")
|
2021-12-18 23:39:59 +01:00
|
|
|
map("n", m.formatting, "<cmd>lua vim.lsp.buf.formatting()<CR>")
|
|
|
|
end
|
|
|
|
|
2021-08-22 09:49:15 +02:00
|
|
|
M.nvimtree = function()
|
2021-08-25 07:28:56 +02:00
|
|
|
map("n", plugin_maps.nvimtree.toggle, ":NvimTreeToggle <CR>")
|
2021-08-25 16:43:47 +02:00
|
|
|
map("n", plugin_maps.nvimtree.focus, ":NvimTreeFocus <CR>")
|
2021-08-22 09:49:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
M.telescope = function()
|
|
|
|
local m = plugin_maps.telescope
|
|
|
|
|
2021-08-25 07:28:56 +02:00
|
|
|
map("n", m.buffers, ":Telescope buffers <CR>")
|
2021-12-27 01:20:58 +01:00
|
|
|
map("n", m.find_files, ":Telescope find_files <CR>")
|
2022-01-08 02:54:55 +01:00
|
|
|
map("n", m.find_hiddenfiles, ":Telescope find_files follow=true no_ignore=true hidden=true <CR>")
|
2021-08-25 07:28:56 +02: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 09:49:15 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|