From afd88703588df9e18d102ef9ff4001334d64f861 Mon Sep 17 00:00:00 2001 From: siduck Date: Tue, 27 Feb 2024 12:31:36 +0530 Subject: [PATCH] misc clean --- lua/core/init.lua | 9 -- lua/core/mappings.lua | 214 +++++++++++++----------------- lua/plugins/configs/cmp.lua | 13 +- lua/plugins/configs/lspconfig.lua | 6 +- lua/plugins/init.lua | 2 +- 5 files changed, 104 insertions(+), 140 deletions(-) diff --git a/lua/core/init.lua b/lua/core/init.lua index 8087d6a..59eaf75 100644 --- a/lua/core/init.lua +++ b/lua/core/init.lua @@ -136,12 +136,3 @@ local new_cmd = vim.api.nvim_create_user_command new_cmd("NvChadUpdate", function() require "nvchad.updater"() end, {}) - ---------------------------------------- globals ------------------------------------------- -vim.g.whichkey_maps = true -vim.g.blankline_maps = true -vim.g.terminal_maps = true -vim.g.telescope_maps = true -vim.g.nvimtree_maps = true -vim.g.comment_maps = true -vim.g.tabufline_maps = true diff --git a/lua/core/mappings.lua b/lua/core/mappings.lua index d955e30..74ba012 100644 --- a/lua/core/mappings.lua +++ b/lua/core/mappings.lua @@ -6,7 +6,6 @@ map("i", "", "", { desc = "Move left | general" }) map("i", "", "", { desc = "Move right | general" }) map("i", "", "", { desc = "Move down | general" }) map("i", "", "", { desc = "Move up | general" }) - map("n", "", "noh", { desc = "Clear highlights | general" }) map("n", "", "h", { desc = "Window left | general" }) map("n", "", "l", { desc = "Window right | general" }) @@ -19,134 +18,107 @@ map("n", "rn", "set rnu!", { desc = "Toggle relative number | g map("n", "b", "enew", { desc = "New buffer | general" }) map("n", "ch", "NvCheatsheet", { desc = "Mapping cheatsheet | general" }) +-- global lsp mappings map("n", "fm", function() vim.lsp.buf.format { async = true } end, { desc = "LSP formatting | lsp" }) -vim.keymap.set("n", "lf", vim.diagnostic.open_float, { desc = "floating diagnostics | lsp" }) -vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "prev diagnostic | lsp" }) -vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "next diagnostic | lsp" }) -vim.keymap.set("n", "q", vim.diagnostic.setloclist, { desc = "diagnostic loclist | lsp" }) +map("n", "lf", vim.diagnostic.open_float, { desc = "floating diagnostics | lsp" }) +map("n", "[d", vim.diagnostic.goto_prev, { desc = "prev diagnostic | lsp" }) +map("n", "]d", vim.diagnostic.goto_next, { desc = "next diagnostic | lsp" }) +map("n", "q", vim.diagnostic.setloclist, { desc = "diagnostic loclist | lsp" }) + +-- tabufline +map("n", "", function() + require("nvchad.tabufline").tabuflineNext() +end, { desc = "Goto next buffer | tabufline" }) + +map("n", "", function() + require("nvchad.tabufline").tabuflinePrev() +end, { desc = "Goto prev buffer | tabufline" }) + +map("n", "x", function() + require("nvchad.tabufline").close_buffer() +end, { desc = "Close buffer | tabufline" }) + +map("n", "/", function() + require("Comment.api").toggle.linewise.current() +end, { desc = "Toggle comment | comment" }) + +map( + "v", + "/", + ":lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", + { desc = "Toggle comment | comment" } +) + +map("n", "", "NvimTreeToggle", { desc = "Toggle nvimtree | nvimtree" }) +map("n", "e", "NvimTreeFocus", { desc = "Focus nvimtree | nvimtree" }) + +map("n", "fw", "Telescope live_grep", { desc = "Live grep | telescope" }) +map("n", "fb", "Telescope buffers", { desc = "Find buffers | telescope" }) +map("n", "fh", "Telescope help_tags", { desc = "Help page | telescope" }) +map("n", "fo", "Telescope oldfiles", { desc = "Find oldfiles | telescope" }) +map("n", "fz", "Telescope current_buffer_fuzzy_find", { desc = "Find in current buffer | telescope" }) +map("n", "cm", "Telescope git_commits", { desc = "Git commits | telescope" }) +map("n", "gt", "Telescope git_status", { desc = "Git status | telescope" }) +map("n", "pt", "Telescope terms", { desc = "Pick hidden term | telescope" }) +map("n", "th", "Telescope themes", { desc = "Nvchad themes | telescope" }) +map("n", "ff", "Telescope find_files", { desc = "Find files | telescope" }) --- Mappings for terminal mode map( - "t", - "", - vim.api.nvim_replace_termcodes("", true, true, true), - { desc = "Escape terminal mode | general" } + "n", + "fa", + "Telescope find_files follow=true no_ignore=true hidden=true", + { desc = "Find all | telescope" } ) --- Mappings for M.tabufline -if vim.g.tabufline_maps then - map("n", "", function() - require("nvchad.tabufline").tabuflineNext() - end, { desc = "Goto next buffer | tabufline" }) - - map("n", "", function() - require("nvchad.tabufline").tabuflinePrev() - end, { desc = "Goto prev buffer | tabufline" }) - - map("n", "x", function() - require("nvchad.tabufline").close_buffer() - end, { desc = "Close buffer | tabufline" }) -end - -if vim.g.comment_maps then - map("n", "/", function() - require("Comment.api").toggle.linewise.current() - end, { desc = "Toggle comment | comment" }) - - map( - "v", - "/", - "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", - { desc = "Toggle comment | comment" } - ) -end - -if vim.g.nvimtree_maps then - map("n", "", "NvimTreeToggle", { desc = "Toggle nvimtree | nvimtree" }) - map("n", "e", "NvimTreeFocus", { desc = "Focus nvimtree | nvimtree" }) -end - -if vim.g.telescope_maps then - map("n", "fw", "Telescope live_grep", { desc = "Live grep | telescope" }) - map("n", "fb", "Telescope buffers", { desc = "Find buffers | telescope" }) - map("n", "fh", "Telescope help_tags", { desc = "Help page | telescope" }) - map("n", "fo", "Telescope oldfiles", { desc = "Find oldfiles | telescope" }) - - map( - "n", - "fz", - "Telescope current_buffer_fuzzy_find", - { desc = "Find in current buffer | telescope" } - ) - - map("n", "cm", "Telescope git_commits", { desc = "Git commits | telescope" }) - map("n", "gt", "Telescope git_status", { desc = "Git status | telescope" }) - map("n", "pt", "Telescope terms", { desc = "Pick hidden term | telescope" }) - map("n", "th", "Telescope themes", { desc = "Nvchad themes | telescope" }) - - map("n", "ff", "Telescope find_files", { desc = "Find files | telescope" }) - map( - "n", - "fa", - "Telescope find_files follow=true no_ignore=true hidden=true", - { desc = "Find all | telescope" } - ) -end - --- Mappings for M.terminal -if vim.g.terminal_maps then - map("n", "h", function() - require("nvchad.term").new { pos = "sp", size = 0.3 } - end, { desc = "New horizontal term | terminal" }) - - map("n", "v", function() - require("nvchad.term").new { pos = "vsp", size = 0.3 } - end, { desc = "New vertical term | terminal" }) - - map({ "n", "t" }, "", function() - require("nvchad.term").toggle { pos = "vsp", id = "vtoggleTerm", size = 0.3 } - end, { desc = "Toggleable vertical term | terminal" }) - - map({ "n", "t" }, "", function() - require("nvchad.term").toggle { pos = "sp", id = "htoggleTerm", size = 0.2 } - end, { desc = "New horizontal term | terminal" }) - - map({ "n", "t" }, "", function() - require("nvchad.term").toggle { pos = "float", id = "floatTerm" } - end, { desc = "Toggleable Floating term | terminal" }) - - map("t", "", function() - local win = vim.api.nvim_get_current_win() - vim.api.nvim_win_close(win, true) - end, { desc = "Close term in terminal mode | terminal" }) -end - -if vim.g.whichkey_maps then - map("n", "wK", ":WhichKey ", { desc = "Which-key all keymaps | whichkey" }) - - map("n", "wk", function() - vim.cmd("WhichKey " .. vim.fn.input "WhichKey: ") - end, { desc = "Which-key query lookup | whichkey" }) -end - -if vim.g.blankline_maps then - map("n", "cc", function() - local config = { scope = {} } - config.scope.exclude = { language = {}, node_type = {} } - config.scope.include = { node_type = {} } - local node = require("ibl.scope").get(vim.api.nvim_get_current_buf(), config) - - if node then - local start_row, _, end_row, _ = node:range() - if start_row ~= end_row then - vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start_row + 1, 0 }) - vim.api.nvim_feedkeys("_", "n", true) - end +-- terminal +map("t", "", "", { desc = "Escape terminal mode | terminal" }) +map("n", "h", function() + require("nvchad.term").new { pos = "sp", size = 0.3 } +end, { desc = "New horizontal term | terminal" }) + +map("n", "v", function() + require("nvchad.term").new { pos = "vsp", size = 0.3 } +end, { desc = "New vertical term | terminal" }) + +map({ "n", "t" }, "", function() + require("nvchad.term").toggle { pos = "vsp", id = "vtoggleTerm", size = 0.3 } +end, { desc = "Toggleable vertical term | terminal" }) + +map({ "n", "t" }, "", function() + require("nvchad.term").toggle { pos = "sp", id = "htoggleTerm", size = 0.2 } +end, { desc = "New horizontal term | terminal" }) + +map({ "n", "t" }, "", function() + require("nvchad.term").toggle { pos = "float", id = "floatTerm" } +end, { desc = "Toggleable Floating term | terminal" }) + +map("t", "", function() + local win = vim.api.nvim_get_current_win() + vim.api.nvim_win_close(win, true) +end, { desc = "Close term in terminal mode | terminal" }) + +-- whichkey +map("n", "wK", "WhichKey ", { desc = "Which-key all keymaps | whichkey" }) +map("n", "wk", function() + vim.cmd("WhichKey " .. vim.fn.input "WhichKey: ") +end, { desc = "Which-key query lookup | whichkey" }) + +map("n", "cc", function() + local config = { scope = {} } + config.scope.exclude = { language = {}, node_type = {} } + config.scope.include = { node_type = {} } + local node = require("ibl.scope").get(vim.api.nvim_get_current_buf(), config) + + if node then + local start_row, _, end_row, _ = node:range() + if start_row ~= end_row then + vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start_row + 1, 0 }) + vim.api.nvim_feedkeys("_", "n", true) end - end, { desc = "Jump to current context | blankline" }) -end + end +end, { desc = "Jump to current context | blankline" }) pcall(require, "custom.mappings") diff --git a/lua/plugins/configs/cmp.lua b/lua/plugins/configs/cmp.lua index 9b669a8..46f8864 100644 --- a/lua/plugins/configs/cmp.lua +++ b/lua/plugins/configs/cmp.lua @@ -75,10 +75,12 @@ local options = { [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Insert, select = true, }, + [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() @@ -87,10 +89,8 @@ local options = { else fallback() end - end, { - "i", - "s", - }), + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() @@ -99,10 +99,7 @@ local options = { else fallback() end - end, { - "i", - "s", - }), + end, { "i", "s" }), }, sources = { { name = "nvim_lsp" }, diff --git a/lua/plugins/configs/lspconfig.lua b/lua/plugins/configs/lspconfig.lua index 5a7d5bd..d260572 100644 --- a/lua/plugins/configs/lspconfig.lua +++ b/lua/plugins/configs/lspconfig.lua @@ -31,7 +31,11 @@ M.on_attach = function(client, bufnr) end, opts "List workspace folders | lsp") map("n", "D", vim.lsp.buf.type_definition, opts "Go to type definition | lsp") - map("n", "rn", vim.lsp.buf.rename, opts "Rename symbol | lsp") + + map("n", "ra", function() + require "nvchad.renamer"() + end, opts "NvRename symbol | lsp") + map({ "n", "v" }, "ca", vim.lsp.buf.code_action, opts "Code action | lsp") map("n", "gr", vim.lsp.buf.references, opts "Show references | lsp") end diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 21f9578..c1ba077 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -81,7 +81,7 @@ local default_plugins = { "lewis6991/gitsigns.nvim", event = "User FilePost", opts = function() - return require("plugins.configs.gitsigns") + return require "plugins.configs.gitsigns" end, config = function(_, opts) dofile(vim.g.base46_cache .. "git")