feat: Add better terminal

This commit is contained in:
Fabio Lenherr / DashieTM 2023-10-22 16:12:38 +02:00
parent 7cacef1705
commit 8633e56645
11 changed files with 107 additions and 95 deletions

View file

@ -50,10 +50,10 @@ end, opts)
-- toggle terminal
local lazyterm = function()
Util.float_term(nil, { cwd = Util.get_root() })
Util.terminal(nil, { cwd = Util.root(), esc_esc = false, ctrl_hjkl = false })
end
map("n", "<c-t>", lazyterm, { desc = "Terminal (root dir)" })
map("t", "<C-t>", "<cmd>close<cr>", { desc = "Hide Terminal" })
map("t", "<c-t>", "<cmd>close<cr>", { desc = "Hide Terminal" })
-- semicolon thing
-- map("i","<C-m>" ,"<C-o>A;<CR>", {desc = "add semi and newline"})
@ -133,6 +133,12 @@ map("n", "<leader>z", function()
require("telescope").extensions.zoxide.list({})
end, { desc = "Zoxide" })
-- neoscroll
local t = {}
t["<A-l>"] = { "scroll", { "-vim.wo.scroll", "true", "250" } }
t["<A-k>"] = { "scroll", { "vim.wo.scroll", "true", "250" } }
require("neoscroll.config").set_mappings(t)
-- trouble
map("n", "<leader>t", "<cmd>TroubleToggle<CR>", term_opts)

View file

@ -11,6 +11,7 @@ require("lazy").setup({
spec = {
-- add LazyVim and import its plugins
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
{ import = "lazyvim.plugins.extras.ui.alpha" },
{ import = "plugins.plugins" },
{ import = "plugins" },
-- import any extras modules here
@ -47,4 +48,3 @@ require("lazy").setup({
},
},
})

View file

@ -6,7 +6,7 @@ M._keys = nil
---@return (LazyKeys|{has?:string})[]
function M.get()
local format = function()
require("lazyvim.plugins.lsp.format").format({ force = true })
require("lazyvim.util").format({ force = true })
end
if not M._keys then
---@class PluginLspKeys
@ -89,7 +89,7 @@ end
---@param method string
function M.has(buffer, method)
method = method:find("/") and method or "textDocument/" .. method
local clients = vim.lsp.get_active_clients({ bufnr = buffer })
local clients = require("lazyvim.util").lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do
if client.supports_method(method) then
return true
@ -98,45 +98,33 @@ function M.has(buffer, method)
return false
end
---@return (LazyKeys|{has?:string})[]
function M.resolve(buffer)
local Keys = require("lazy.core.handler.keys")
local keymaps = {} ---@type table<string,LazyKeys|{has?:string}>
local function add(keymap)
local keys = Keys.parse(keymap)
if keys[2] == false then
keymaps[keys.id] = nil
else
keymaps[keys.id] = keys
end
if not Keys.resolve then
return {}
end
for _, keymap in ipairs(M.get()) do
add(keymap)
end
local spec = M.get()
local opts = require("lazyvim.util").opts("nvim-lspconfig")
local clients = vim.lsp.get_active_clients({ bufnr = buffer })
local clients = require("lazyvim.util").lsp.get_clients({ bufnr = buffer })
for _, client in ipairs(clients) do
local maps = opts.servers[client.name] and opts.servers[client.name].keys or {}
for _, keymap in ipairs(maps) do
add(keymap)
end
vim.list_extend(spec, maps)
end
return keymaps
return Keys.resolve(spec)
end
function M.on_attach(client, buffer)
function M.on_attach(_, buffer)
local Keys = require("lazy.core.handler.keys")
local keymaps = M.resolve(buffer)
for _, keys in pairs(keymaps) do
if not keys.has or M.has(buffer, keys.has) then
local opts = Keys.opts(keys)
---@diagnostic disable-next-line: no-unknown
opts.has = nil
opts.silent = opts.silent ~= false
opts.buffer = buffer
vim.keymap.set(keys.mode or "n", keys[1], keys[2], opts)
vim.keymap.set(keys.mode or "n", keys.lhs, keys.rhs, opts)
end
end
end