with keybinds

This commit is contained in:
Kasper Juul Hermansen 2022-10-12 17:55:25 +02:00
parent f7b6dd262d
commit 642266466c
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
8 changed files with 231 additions and 5 deletions

View File

@ -42,6 +42,7 @@ vim.opt.undofile = true
vim.opt.undolevels = 10000 vim.opt.undolevels = 10000
vim.opt.updatetime = 200 -- save swap file and trigger CursorHold vim.opt.updatetime = 200 -- save swap file and trigger CursorHold
vim.opt.wildmode = "longest:full,full" -- Command-line completion mode vim.opt.wildmode = "longest:full,full" -- Command-line completion mode
vim.opt.completeopt = "menu,menuone,noselect"
vim.opt.wrap = false -- Disable line wrap vim.opt.wrap = false -- Disable line wrap
vim.opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" } vim.opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" }
vim.opt.fillchars = { vim.opt.fillchars = {

View File

@ -102,6 +102,8 @@ local function plugins(use, plugin)
module = "mason-lspconfig", module = "mason-lspconfig",
}) })
plugin("simrat39/rust-tools.nvim")
-- Autocomplete -- Autocomplete
plugin("hrsh7th/nvim-cmp") plugin("hrsh7th/nvim-cmp")
@ -121,6 +123,10 @@ local function plugins(use, plugin)
-- Utility -- Utility
plugin("windwp/nvim-autopairs") plugin("windwp/nvim-autopairs")
-- Terminal
plugin("s1n7ax/nvim-terminal")
plugin("akinsho/toggleterm.nvim")
-- Yanking -- Yanking
use({ use({
"AckslD/nvim-neoclip.lua", "AckslD/nvim-neoclip.lua",
@ -177,6 +183,7 @@ local function plugins(use, plugin)
use({ use({
"folke/which-key.nvim", "folke/which-key.nvim",
branch = "mapping_dsl",
module = "which-key", module = "which-key",
}) })

View File

@ -6,8 +6,8 @@ function M.config()
local indent = require("indent_blankline") local indent = require("indent_blankline")
--- PERF: debounce indent-blankline refresh --- PERF: debounce indent-blankline refresh
local refresh = indent.refresh --local refresh = indent.refresh
indent.refresh = require("util").debounce(100, refresh) --indent.refresh = require("util").debounce(100, refresh)
indent.setup({ indent.setup({
buftype_exclude = { "terminal", "nofile" }, buftype_exclude = { "terminal", "nofile" },

View File

@ -14,7 +14,7 @@ function M.config()
local function on_attach(client, bufnr) local function on_attach(client, bufnr)
require("nvim-navic").attach(client, bufnr) require("nvim-navic").attach(client, bufnr)
require("plugins.lsp.formatting").setup(client, bufnr) require("plugins.lsp.formatting").setup(client, bufnr)
--require("plugins.lsp.keys").setup(client, bufnr) require("plugins.lsp.keys").setup(client, bufnr)
end end
---@type lspconfig.options ---@type lspconfig.options
@ -87,10 +87,9 @@ function M.config()
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities, capabilities = capabilities,
flags = { flags = {
debounce_text_change = 150, debounce_text_changes = 150,
}, },
} }
for server, opts in pairs(servers) do for server, opts in pairs(servers) do
opts = vim.tbl_deep_extend("force", {}, options, opts or {}) opts = vim.tbl_deep_extend("force", {}, options, opts or {})
require("lspconfig")[server].setup(opts) require("lspconfig")[server].setup(opts)

70
lua/plugins/lsp/keys.lua Normal file
View File

@ -0,0 +1,70 @@
local wk = require("which-key")
local M = {}
function M.setup(client, buffer)
local cap = client.server_capabilities
local keymap = {
buffer = buffer,
["<leader>"] = {
c = {
name = "+code",
r = {
vim.lsp.buf.rename,
"Rename",
cond = cap.renameProvider,
},
a = {
{ vim.lsp.buf.code_action, "Code Action" },
{ "<cmd>lua vim.lsp.buf.code_action()<cr>", "Code Action", mode = "v" },
},
f = {
{
require("plugins.lsp.formatting").format,
"Format Document",
cond = cap.documentFormatting,
},
{
require("plugins.lsp.formatting").format,
"Format Range",
cond = cap.documentRangeFormatting,
mode = "v",
},
},
d = { vim.diagnostic.open_float, "Line Diagnostics" },
l = {
name = "+lsp",
i = { "<cmd>LspInfo<cr>", "Lsp Info" },
a = { "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", "Add Folder" },
r = { "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", "Remove Folder" },
l = { "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", "List Folders" },
},
},
x = {
d = { "<cmd>Telescope diagnostics<cr>", "Search Diagnostics" },
},
},
g = {
name = "+goto",
d = { "<cmd>Telescope lsp_definitions<cr>", "Goto Definition" },
r = { "<cmd>Telescope lsp_references<cr>", "References" },
R = { "<cmd>Trouble lsp_references<cr>", "Trouble References" },
D = { "<cmd>Telescope lsp_declarations<CR>", "Goto Declaration" },
s = { "<cmd>lua vim.lsp.buf.signature_help()<CR>", "Signature Help" },
I = { "<cmd>Telescope lsp_implementations<CR>", "Goto Implementation" },
t = { "<cmd>Telescope lsp_type_definitions<cr>", "Goto Type Definition" },
},
["K"] = { "<cmd>lua vim.lsp.buf.hover()<CR>", "Hover" },
["[d"] = { "<cmd>lua vim.diagnostic.goto_prev()<CR>", "Next Diagnostic" },
["]d"] = { "<cmd>lua vim.diagnostic.goto_next()<CR>", "Prev Diagnostic" },
["[e"] = { "<cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.ERROR})<CR>", "Next Error" },
["]e"] = { "<cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.ERROR})<CR>", "Prev Error" },
["[w"] = { "<cmd>lua vim.diagnostic.goto_prev({severity = vim.diagnostic.severity.WARNING})<CR>", "Next Warning" },
["]w"] = { "<cmd>lua vim.diagnostic.goto_next({severity = vim.diagnostic.severity.WARNING})<CR>", "Prev Warning" },
}
wk.register(keymap)
end
return M

125
lua/plugins/rust-tools.lua Normal file
View File

@ -0,0 +1,125 @@
local M = {
module = "rust-tools",
}
function M.setup(options)
local opts = {
tools = { -- rust-tools options
-- -- Automatically set inlay hints (type hints)
-- autoSetHints = true,
-- -- Whether to show hover actions inside the hover window
-- -- This overrides the default hover handler
-- hover_with_actions = true,
-- -- how to execute terminal commands
-- -- options right now: termopen / quickfix
-- executor = require("rust-tools/executors").termopen,
-- runnables = {
-- -- whether to use telescope for selection menu or not
-- use_telescope = true,
-- -- rest of the opts are forwarded to telescope
-- },
-- debuggables = {
-- -- whether to use telescope for selection menu or not
-- use_telescope = true,
-- -- rest of the opts are forwarded to telescope
-- },
-- -- These apply to the default RustSetInlayHints command
inlay_hints = {
-- -- Only show inlay hints for the current line
-- only_current_line = false,
-- -- Event which triggers a refersh of the inlay hints.
-- -- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but
-- -- not that this may cause higher CPU usage.
-- -- This option is only respected when only_current_line and
-- -- autoSetHints both are true.
-- only_current_line_autocmd = "CursorHold",
-- -- wheter to show parameter hints with the inlay hints or not
-- show_parameter_hints = true,
-- -- prefix for parameter hints
parameter_hints_prefix = " <- ",
-- -- prefix for all the other hints (type, chaining)
other_hints_prefix = " => ",
-- -- whether to align to the length of the longest line in the file
-- max_len_align = true,
-- -- padding from the left if max_len_align is true
-- max_len_align_padding = 10,
-- -- whether to align to the extreme right or not
-- right_align = false,
-- -- padding from the right if right_align is true
-- right_align_padding = 7,
-- -- The color of the hints
highlight = "LspCodeLens",
},
-- hover_actions = {
-- -- the border that is used for the hover window
-- -- see vim.api.nvim_open_win()
-- border = {
-- { "\u256d", "FloatBorder" },
-- { "\u2500", "FloatBorder" },
-- { "\u256e", "FloatBorder" },
-- { "\u2502", "FloatBorder" },
-- { "\u256f", "FloatBorder" },
-- { "\u2500", "FloatBorder" },
-- { "\u2570", "FloatBorder" },
-- { "\u2502", "FloatBorder" },
-- },
-- -- whether the hover action window gets automatically focused
-- auto_focus = false,
-- },
-- -- settings for showing the crate graph based on graphviz and the dot
-- -- command
-- crate_graph = {
-- -- Backend used for displaying the graph
-- -- see: https://graphviz.org/docs/outputs/
-- -- default: x11
-- backend = "x11",
-- -- where to store the output, nil for no output stored (relative
-- -- path from pwd)
-- -- default: nil
-- output = nil,
-- -- true for all crates.io and external crates, false only the local
-- -- crates
-- -- default: true
-- full = true,
-- },
},
-- -- all the opts to send to nvim-lspconfig
-- -- these override the defaults set by rust-tools.nvim
-- -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
server = options, -- rust-analyer options
-- -- debugging stuff
-- dap = {
-- adapter = {
-- type = "executable",
-- command = "lldb-vscode",
-- name = "rt_lldb",
-- },
-- },
}
require("rust-tools").setup(opts)
end
return M

7
lua/plugins/terminal.lua Normal file
View File

@ -0,0 +1,7 @@
return {
ft = "terminal",
module = "nvim-terminal",
config = function()
require("terminal").setup()
end,
}

View File

@ -0,0 +1,17 @@
return {
keys = "<C-/>",
module = "nvim-toggleterm",
config = function()
require("toggleterm").setup({
size = 20,
hide_numbers = true,
open_mapping = [[<C-/>]],
shade_filetypes = {},
shade_terminals = false,
shading_factor = 0.3, -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light
start_in_insert = true,
persist_size = true,
direction = "horizontal",
})
end,
}