mirror of
https://github.com/ViViDboarder/vim-settings.git
synced 2024-11-17 18:26:26 +00:00
Lightly tested: Finish up refactor
This commit is contained in:
parent
02c5301379
commit
2710af9160
@ -40,20 +40,15 @@ utils.keymap_set("i", "``", "<esc>", { desc = "Escape insert" })
|
||||
utils.keymap_set("v", "``", "<esc>", { desc = "Escape visual" })
|
||||
|
||||
-- C-Space completion
|
||||
function _G.complete_space()
|
||||
utils.keymap_set("i", "<C-Space>", function()
|
||||
if vim.fn.pumvisible() == 1 then
|
||||
return utils.t("<C-n>")
|
||||
elseif utils.is_plugin_loaded("completion-nvim") then
|
||||
return utils.t("<Plug>(completion_trigger)")
|
||||
elseif utils.is_plugin_loaded("nvim-compe") then
|
||||
return vim.fn["compe#complete"]()
|
||||
elseif utils.is_plugin_loaded("nvim-cmp") then
|
||||
return utils.t("<Plug>(cmp_complete)")
|
||||
else
|
||||
return utils.t("<C-x><C-o>")
|
||||
end
|
||||
end
|
||||
utils.keymap_set("i", "<C-Space>", "v:lua.complete_space()", { expr = true })
|
||||
end, { expr = true })
|
||||
|
||||
vim.api.nvim_create_user_command("TagsUpdate", "!ctags -R .", { desc = "Update ctags" })
|
||||
vim.api.nvim_create_user_command("Todo", "grep TODO", { desc = "Search for TODO tags" })
|
||||
|
@ -16,7 +16,7 @@ function M.setup()
|
||||
|
||||
local utils = require("utils")
|
||||
if utils.try_require("telescope") ~= nil then
|
||||
local cc_keymap = utils.curry_keymap("n", "<leader>cc")
|
||||
local cc_keymap = utils.curry_keymap("n", "<leader>cc", { group_desc = "CopilotChat" })
|
||||
|
||||
cc_keymap("h", function()
|
||||
local actions = require("CopilotChat.actions")
|
||||
|
@ -90,7 +90,7 @@ local function get_default_attach(override_capabilities)
|
||||
end
|
||||
|
||||
-- Mappings
|
||||
local lsp_keymap = utils.curry_keymap("n", "<leader>l", { buffer = bufnr })
|
||||
local lsp_keymap = utils.curry_keymap("n", "<leader>l", { buffer = bufnr, group_desc = "LSP" })
|
||||
lsp_keymap("h", vim.lsp.buf.hover, { desc = "Display hover" })
|
||||
lsp_keymap("rn", vim.lsp.buf.rename, { desc = "Refactor rename" })
|
||||
lsp_keymap("e", vim.diagnostic.open_float, { desc = "Open float dialog" })
|
||||
@ -123,28 +123,18 @@ local function get_default_attach(override_capabilities)
|
||||
utils.keymap_set("n", "[d", vim.diagnostic.goto_prev, { buffer = bufnr, desc = "Previous diagnostic" })
|
||||
utils.keymap_set("n", "]d", vim.diagnostic.goto_next, { buffer = bufnr, desc = "Next diagnostic" })
|
||||
|
||||
-- Older keymaps
|
||||
--[[
|
||||
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
|
||||
buf_set_keymap("n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
|
||||
buf_set_keymap("n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
|
||||
buf_set_keymap("n", "<leader>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
|
||||
buf_set_keymap("n", "<leader>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
|
||||
buf_set_keymap("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
||||
buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
|
||||
buf_set_keymap("n", "<leader>e", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
|
||||
buf_set_keymap("n", "<leader>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
|
||||
--]]
|
||||
|
||||
-- Open diagnostic on hold
|
||||
if vim["diagnostic"] ~= nil then
|
||||
-- TODO: When dropping 0.6, use lua aucommand api
|
||||
vim.cmd([[autocmd CursorHold * lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})]])
|
||||
end
|
||||
vim.api.nvim_create_autocmd({ "CursorHold" }, {
|
||||
pattern = "<buffer>",
|
||||
callback = function()
|
||||
vim.diagnostic.open_float(nil, { focus = false, scope = "cursor" })
|
||||
end,
|
||||
group = vim.api.nvim_create_augroup("diagnostic_float", { clear = true }),
|
||||
desc = "Open float dialog on hold",
|
||||
})
|
||||
|
||||
-- Use IncRename if available
|
||||
if utils.try_require("inc_rename") ~= nil then
|
||||
-- TODO: Should I be using this for calling lua functions from keymaps?
|
||||
vim.keymap.set("n", "<leader>rn", function()
|
||||
return ":IncRename " .. vim.fn.expand("<cword>")
|
||||
end, { expr = true, buffer = true, desc = "Rename current symbol" })
|
||||
@ -169,7 +159,7 @@ local function get_default_attach(override_capabilities)
|
||||
})
|
||||
end
|
||||
else
|
||||
-- HACK: Support for <0.8
|
||||
-- HACK: Support for <0.8 with older formatting
|
||||
lsp_keymap("f", vim.lsp.buf.formatting, { desc = "Format code" })
|
||||
lsp_keymap("f", vim.lsp.buf.range_formatting, { mode = "v", desc = "Format selected code" })
|
||||
if server_capabilities.documentFormattingProvider then
|
||||
@ -201,25 +191,25 @@ local function get_default_attach(override_capabilities)
|
||||
end
|
||||
|
||||
-- Some override some fuzzy finder bindings to use lsp sources
|
||||
utils.try_require("telescope.builtin", function(builtin)
|
||||
utils.try_require("telescope.builtin", function(telescope_builtin)
|
||||
-- Replace some Telescope bindings with LSP versions
|
||||
local telescope_keymap = utils.curry_keymap("n", "<leader>f", { buffer = bufnr })
|
||||
local telescope_keymap = utils.curry_keymap("n", "<leader>f", { buffer = bufnr, group_desc = "Finder" })
|
||||
if server_capabilities.documentSymbolProvider then
|
||||
telescope_keymap("t", builtin.lsp_document_symbols, { desc = "Find buffer tags" })
|
||||
telescope_keymap("t", telescope_builtin.lsp_document_symbols, { desc = "Find buffer tags" })
|
||||
end
|
||||
if server_capabilities.workspaceSymbolProvider then
|
||||
telescope_keymap("T", builtin.lsp_dynamic_workspace_symbols, { desc = "Find tags" })
|
||||
telescope_keymap("T", telescope_builtin.lsp_dynamic_workspace_symbols, { desc = "Find tags" })
|
||||
end
|
||||
|
||||
-- Replace some LSP bindings with Telescope ones
|
||||
if server_capabilities.definitionProvider then
|
||||
lsp_keymap("d", builtin.lsp_definitions, { desc = "Find definition" })
|
||||
lsp_keymap("d", telescope_builtin.lsp_definitions, { desc = "Find definition" })
|
||||
end
|
||||
if server_capabilities.typeDefinitionProvider then
|
||||
lsp_keymap("t", builtin.lsp_type_definition, { desc = "Find type definition" })
|
||||
lsp_keymap("t", telescope_builtin.lsp_type_definitions, { desc = "Find type definition" })
|
||||
end
|
||||
lsp_keymap("i", builtin.lsp_implementations, { desc = "Find implementations" })
|
||||
lsp_keymap("r", builtin.lsp_references, { desc = "Find references" })
|
||||
lsp_keymap("i", telescope_builtin.lsp_implementations, { desc = "Find implementations" })
|
||||
lsp_keymap("r", telescope_builtin.lsp_references, { desc = "Find references" })
|
||||
end)
|
||||
|
||||
-- Attach navic for statusline location
|
||||
|
@ -56,22 +56,8 @@ function M.config_lualine(theme_name)
|
||||
theme_name = "wombat"
|
||||
end
|
||||
|
||||
-- gps / navic
|
||||
-- navic
|
||||
local code_loc = {}
|
||||
|
||||
utils.try_require("nvim-gps", function(gps)
|
||||
gps.setup({
|
||||
icons = {
|
||||
["class-name"] = "(c) ",
|
||||
["function-name"] = "(ƒ) ",
|
||||
["method-name"] = "(m) ",
|
||||
["container-name"] = "",
|
||||
["tag-name"] = "(t) ",
|
||||
},
|
||||
})
|
||||
code_loc = { gps.get_location, cond = gps.is_available }
|
||||
end)
|
||||
|
||||
utils.try_require("nvim-navic", function(navic)
|
||||
navic.setup({
|
||||
icons = {
|
||||
@ -89,12 +75,6 @@ function M.config_lualine(theme_name)
|
||||
code_loc = { "navic" }
|
||||
end)
|
||||
|
||||
local diagnostic_plugin = "nvim_diagnostic"
|
||||
-- HACK: Support for <0.6
|
||||
if vim.fn.has("nvim-0.6.0") ~= 1 then
|
||||
diagnostic_plugin = "nvim_lsp"
|
||||
end
|
||||
|
||||
require("lualine").setup({
|
||||
options = {
|
||||
theme = theme_name,
|
||||
@ -116,7 +96,7 @@ function M.config_lualine(theme_name)
|
||||
lualine_x = { M.custom_ffenc, "filetype" },
|
||||
lualine_y = { "progress", "location" },
|
||||
lualine_z = {
|
||||
{ "diagnostics", sources = { diagnostic_plugin } },
|
||||
{ "diagnostics", sources = { "nvim_diagnostic" } },
|
||||
{ M.mixed_indent, color = { bg = "#de4f1f" } },
|
||||
{ M.trailing_whitespace, color = { bg = "#de4f1f" } },
|
||||
},
|
||||
|
@ -22,43 +22,27 @@ local function config_telescope()
|
||||
})
|
||||
|
||||
local utils = require("utils")
|
||||
utils.keymap_set("n", "<C-t>", "<cmd>lua require('telescope.builtin').find_files()<CR>", { desc = "Find files" })
|
||||
utils.keymap_set("n", "<leader>b", "<cmd>lua require('telescope.builtin').buffers()<CR>", { desc = "Find buffers" })
|
||||
utils.keymap_set(
|
||||
"n",
|
||||
"<leader>t",
|
||||
"<cmd>lua require('telescope.builtin').current_buffer_tags()<CR>",
|
||||
{ desc = "Find buffer tags" }
|
||||
)
|
||||
utils.keymap_set(
|
||||
"n",
|
||||
"<leader>*",
|
||||
"<cmd>lua require('telescope.builtin').grep_string()<CR>",
|
||||
{ desc = "Find string under cursor" }
|
||||
)
|
||||
-- Better spelling replacement for word under cursor
|
||||
utils.keymap_set(
|
||||
"n",
|
||||
"<leader>s",
|
||||
"<cmd>lua require('telescope.builtin').spell_suggest(require('telescope.themes').get_cursor())<CR>",
|
||||
{ desc = "Spell check" }
|
||||
)
|
||||
local telescope_builtin = require("telescope.builtin")
|
||||
|
||||
local finder_keymap = utils.curry_keymap("n", "<leader>f")
|
||||
finder_keymap("b", "<cmd>lua require('telescope.builtin').buffers()<CR>", { desc = "Find buffers" })
|
||||
finder_keymap("f", "<cmd>lua require('telescope.builtin').find_files()<CR>", { desc = "Find file" })
|
||||
finder_keymap("g", "<cmd>lua require('telescope.builtin').live_grep()<CR>", { desc = "Live grep" })
|
||||
finder_keymap("h", "<cmd>lua require('telescope.builtin').help_tags()<CR>", { desc = "Find help tags" })
|
||||
finder_keymap("l", "<cmd>lua require('telescope.builtin').resume()<CR>", { desc = "Resume finding" })
|
||||
finder_keymap("t", "<cmd>lua require('telescope.builtin').current_buffer_tags()<CR>", { desc = "Find buffer tags" })
|
||||
finder_keymap("T", "<cmd>lua require('telescope.builtin').tags()<CR>", { desc = "Find tags" })
|
||||
utils.keymap_set("n", "<C-t>", telescope_builtin.find_files, { desc = "Find files" })
|
||||
utils.keymap_set("n", "<leader>b", telescope_builtin.buffers, { desc = "Find buffers" })
|
||||
utils.keymap_set("n", "<leader>t", telescope_builtin.current_buffer_tags, { desc = "Find buffer tags" })
|
||||
utils.keymap_set("n", "<leader>*", telescope_builtin.grep_string, { desc = "Find string under cursor" })
|
||||
utils.keymap_set("n", "<leader>s", function()
|
||||
require("telescope.builtin").spell_suggest(require("telescope.themes").get_cursor())
|
||||
end, { desc = "Spell check" })
|
||||
|
||||
local finder_keymap = utils.curry_keymap("n", "<leader>f", { group_desc = "Finder" })
|
||||
finder_keymap("b", telescope_builtin.buffers, { desc = "Find buffers" })
|
||||
finder_keymap("f", telescope_builtin.find_files, { desc = "Find file" })
|
||||
finder_keymap("g", telescope_builtin.live_grep, { desc = "Live grep" })
|
||||
finder_keymap("h", telescope_builtin.help_tags, { desc = "Find help tags" })
|
||||
finder_keymap("l", telescope_builtin.resume, { desc = "Resume finding" })
|
||||
finder_keymap("t", telescope_builtin.current_buffer_tags, { desc = "Find buffer tags" })
|
||||
finder_keymap("T", telescope_builtin.tags, { desc = "Find tags" })
|
||||
|
||||
if utils.can_require("sg.telescope") then
|
||||
finder_keymap(
|
||||
"G",
|
||||
"<cmd>lua require('sg.telescope').fuzzy_search_results()<CR>",
|
||||
{ desc = "Search Sourcegraph" }
|
||||
)
|
||||
finder_keymap("G", require("sg.telescope").fuzzy_search_results, { desc = "Search Sourcegraph" })
|
||||
end
|
||||
|
||||
load_extensions()
|
||||
|
@ -184,6 +184,14 @@ end
|
||||
-- Returns a curried function for passing data into vim.keymap.set
|
||||
function M.curry_keymap(mode, prefix, default_opts)
|
||||
default_opts = vim.tbl_extend("keep", default_opts or {}, { noremap = true, silent = true })
|
||||
local group_desc = M.tbl_pop(default_opts, "group_desc")
|
||||
if group_desc ~= nil then
|
||||
M.try_require("which-key", function(wk)
|
||||
wk.register({
|
||||
[prefix] = "+" .. group_desc,
|
||||
}, default_opts)
|
||||
end)
|
||||
end
|
||||
|
||||
return function(lhs, rhs, opts)
|
||||
opts = vim.tbl_extend("keep", opts or {}, default_opts)
|
||||
@ -192,18 +200,6 @@ function M.curry_keymap(mode, prefix, default_opts)
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns a function used to create keymaps with consistent prefixes
|
||||
function M.keymap_group(mode, prefix, default_opts)
|
||||
return function(lhs, rhs, opts)
|
||||
opts = opts or default_opts
|
||||
if opts ~= nil and default_opts ~= nil and opts ~= default_opts then
|
||||
opts = vim.tbl_extend("keep", opts, default_opts)
|
||||
end
|
||||
local opt_mode = M.tbl_pop(opts, "mode")
|
||||
M.keymap_set(opt_mode or mode, prefix .. lhs, rhs, opts)
|
||||
end
|
||||
end
|
||||
|
||||
-- Diagnostics signs
|
||||
M.diagnostic_signs = {
|
||||
Error = "🔥",
|
||||
|
Loading…
Reference in New Issue
Block a user