2021-08-25 05:28:56 +00:00
|
|
|
local utils = require "core.utils"
|
|
|
|
|
2022-04-27 15:42:28 +00:00
|
|
|
local map = utils.map
|
2021-08-25 05:28:56 +00:00
|
|
|
local cmd = vim.cmd
|
2022-04-27 23:04:14 +00:00
|
|
|
local user_cmd = vim.api.nvim_create_user_command
|
2021-08-22 07:49:15 +00:00
|
|
|
|
2022-01-22 07:21:12 +00: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
|
2022-04-27 15:42:28 +00:00
|
|
|
|
|
|
|
-- Don't copy the replaced text after pasting in visual mode
|
2022-05-08 03:15:13 +00:00
|
|
|
-- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#Alternative_mapping_for_paste
|
|
|
|
map("v", "p", 'p:let @+=@0<CR>:let @"=@0<CR>', { silent = true })
|
2022-04-27 15:42:28 +00:00
|
|
|
|
|
|
|
-- Allow moving the cursor through wrapped lines with j, k, <Up> and <Down>
|
|
|
|
-- http<cmd> ://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
|
|
|
|
-- empty mode is same as using <cmd> :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("", "<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 })
|
|
|
|
|
|
|
|
-- use ESC to turn off search highlighting
|
|
|
|
map("n", "<Esc>", "<cmd> :noh <CR>")
|
|
|
|
|
|
|
|
-- move cursor within insert mode
|
|
|
|
map("i", "<C-h>", "<Left>")
|
|
|
|
map("i", "<C-e>", "<End>")
|
|
|
|
map("i", "<C-l>", "<Right>")
|
|
|
|
map("i", "<C-j>", "<Down>")
|
|
|
|
map("i", "<C-k>", "<Up>")
|
|
|
|
map("i", "<C-a>", "<ESC>^i")
|
|
|
|
|
|
|
|
-- navigation between windows
|
|
|
|
map("n", "<C-h>", "<C-w>h")
|
|
|
|
map("n", "<C-l>", "<C-w>l")
|
|
|
|
map("n", "<C-k>", "<C-w>k")
|
|
|
|
map("n", "<C-j>", "<C-w>j")
|
|
|
|
|
|
|
|
map("n", "<leader>x", function()
|
|
|
|
require("core.utils").close_buffer()
|
|
|
|
end)
|
|
|
|
|
|
|
|
map("n", "<C-c>", "<cmd> :%y+ <CR>") -- copy whole file content
|
|
|
|
map("n", "<S-t>", "<cmd> :enew <CR>") -- new buffer
|
|
|
|
map("n", "<C-t>b", "<cmd> :tabnew <CR>") -- new tabs
|
|
|
|
map("n", "<leader>n", "<cmd> :set nu! <CR>")
|
|
|
|
map("n", "<leader>rn", "<cmd> :set rnu! <CR>") -- relative line numbers
|
|
|
|
map("n", "<C-s>", "<cmd> :w <CR>") -- ctrl + s to save file
|
|
|
|
|
|
|
|
-- terminal mappings
|
|
|
|
|
|
|
|
-- get out of terminal mode
|
|
|
|
map("t", { "jk" }, "<C-\\><C-n>")
|
|
|
|
|
|
|
|
-- Add Packer commands because we are not loading it at startup
|
|
|
|
|
|
|
|
local packer_cmd = function(callback)
|
|
|
|
return function()
|
|
|
|
require "plugins"
|
|
|
|
require("packer")[callback]()
|
2022-01-22 07:21:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-30 18:07:31 +00:00
|
|
|
-- 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 = "+" })
|
|
|
|
|
2022-04-27 15:42:28 +00:00
|
|
|
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", {})
|
2021-08-22 07:49:15 +00:00
|
|
|
|
2022-04-27 15:42:28 +00:00
|
|
|
-- add NvChadUpdate command and mapping
|
|
|
|
cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()"
|
|
|
|
map("n", "<leader>uu", "<cmd> :NvChadUpdate <CR>")
|
2021-08-22 07:49:15 +00:00
|
|
|
|
2022-04-27 15:42:28 +00:00
|
|
|
-- load overriden misc mappings
|
2022-04-27 23:04:14 +00:00
|
|
|
require("core.utils").load_config().mappings.misc()
|
2021-08-22 07:49:15 +00:00
|
|
|
|
2022-04-27 15:42:28 +00:00
|
|
|
local M = {}
|
|
|
|
|
2021-08-31 15:16:57 +00:00
|
|
|
-- below are all plugin related mappings
|
2021-08-22 07:49:15 +00:00
|
|
|
|
|
|
|
M.bufferline = function()
|
2022-04-27 15:42:28 +00:00
|
|
|
map("n", "<TAB>", "<cmd> :BufferLineCycleNext <CR>")
|
|
|
|
map("n", "<S-Tab>", "<cmd> :BufferLineCyclePrev <CR>")
|
2021-08-22 07:49:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
M.comment = function()
|
2022-04-27 15:42:28 +00:00
|
|
|
map("n", "<leader>/", "<cmd> :lua require('Comment.api').toggle_current_linewise()<CR>")
|
2022-04-28 07:58:35 +00:00
|
|
|
map("v", "<leader>/", "<esc><cmd> :lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())<CR>")
|
2021-08-22 07:49:15 +00:00
|
|
|
end
|
|
|
|
|
2022-05-01 12:54:40 +00:00
|
|
|
M.lspconfig = function()
|
2022-04-27 15:42:28 +00:00
|
|
|
-- See `<cmd> :help vim.lsp.*` for documentation on any of the below functions
|
2022-05-01 12:54:40 +00:00
|
|
|
map("n", "gD", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.declaration()
|
|
|
|
end)
|
|
|
|
|
2022-05-01 12:54:40 +00:00
|
|
|
map("n", "gd", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.definition()
|
|
|
|
end)
|
|
|
|
|
2022-05-01 12:54:40 +00:00
|
|
|
map("n", "K", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.hover()
|
|
|
|
end)
|
|
|
|
|
2022-05-01 12:54:40 +00:00
|
|
|
map("n", "gi", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.implementation()
|
|
|
|
end)
|
|
|
|
|
2022-05-01 12:54:40 +00:00
|
|
|
map("n", "<C-k>", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.signature_help()
|
|
|
|
end)
|
|
|
|
|
2022-05-02 13:33:17 +00:00
|
|
|
map("n", "<leader>D", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.type_definition()
|
|
|
|
end)
|
|
|
|
|
2022-05-02 13:33:17 +00:00
|
|
|
map("n", "<leader>ra", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.rename()
|
|
|
|
end)
|
|
|
|
|
2022-05-02 13:33:17 +00:00
|
|
|
map("n", "<leader>ca", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.code_action()
|
|
|
|
end)
|
|
|
|
|
2022-05-01 12:54:40 +00:00
|
|
|
map("n", "gr", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.references()
|
|
|
|
end)
|
|
|
|
|
2022-05-02 13:33:17 +00:00
|
|
|
map("n", "<leader>f", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.diagnostic.open_float()
|
|
|
|
end)
|
|
|
|
|
2022-05-01 12:54:40 +00:00
|
|
|
map("n", "[d", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.diagnostic.goto_prev()
|
|
|
|
end)
|
|
|
|
|
2022-05-01 12:54:40 +00:00
|
|
|
map("n", "d]", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.diagnostic.goto_next()
|
|
|
|
end)
|
|
|
|
|
2022-05-02 13:33:17 +00:00
|
|
|
map("n", "<leader>q", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.diagnostic.setloclist()
|
|
|
|
end)
|
|
|
|
|
2022-05-02 13:33:17 +00:00
|
|
|
map("n", "<leader>fm", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.formatting()
|
|
|
|
end)
|
|
|
|
|
2022-05-02 13:33:17 +00:00
|
|
|
map("n", "<leader>wa", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.add_workspace_folder()
|
|
|
|
end)
|
|
|
|
|
2022-05-02 13:33:17 +00:00
|
|
|
map("n", "<leader>wr", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
vim.lsp.buf.remove_workspace_folder()
|
|
|
|
end)
|
|
|
|
|
2022-05-02 13:33:17 +00:00
|
|
|
map("n", "<leader>wl", function()
|
2022-04-27 15:42:28 +00:00
|
|
|
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
|
|
|
end)
|
2021-12-18 22:39:59 +00:00
|
|
|
end
|
|
|
|
|
2021-08-22 07:49:15 +00:00
|
|
|
M.nvimtree = function()
|
2022-04-27 15:42:28 +00:00
|
|
|
map("n", "<C-n>", "<cmd> :NvimTreeToggle <CR>")
|
|
|
|
map("n", "<leader>e", "<cmd> :NvimTreeFocus <CR>")
|
2021-08-22 07:49:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
M.telescope = function()
|
2022-04-27 15:42:28 +00:00
|
|
|
map("n", "<leader>fb", "<cmd> :Telescope buffers <CR>")
|
|
|
|
map("n", "<leader>ff", "<cmd> :Telescope find_files <CR>")
|
|
|
|
map("n", "<leader>fa", "<cmd> :Telescope find_files follow=true no_ignore=true hidden=true <CR>")
|
|
|
|
map("n", "<leader>cm", "<cmd> :Telescope git_commits <CR>")
|
|
|
|
map("n", "<leader>gt", "<cmd> :Telescope git_status <CR>")
|
|
|
|
map("n", "<leader>fh", "<cmd> :Telescope help_tags <CR>")
|
|
|
|
map("n", "<leader>fw", "<cmd> :Telescope live_grep <CR>")
|
|
|
|
map("n", "<leader>fo", "<cmd> :Telescope oldfiles <CR>")
|
|
|
|
map("n", "<leader>th", "<cmd> :Telescope themes <CR>")
|
2022-05-05 16:16:02 +00:00
|
|
|
map("n", "<leader>tk", "<cmd> :Telescope keymaps <CR>")
|
2022-04-27 15:42:28 +00:00
|
|
|
|
|
|
|
-- pick a hidden term
|
|
|
|
map("n", "<leader>W", "<cmd> :Telescope terms <CR>")
|
2021-08-22 07:49:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return M
|