Large rewrite, simplify keymapping, utilize as much keys from Lazy as
possible. Reduce manually setup plugins and utilize opts instead.
This commit is contained in:
parent
72eb62b9cb
commit
43020a4d12
17 changed files with 408 additions and 780 deletions
|
|
@ -26,18 +26,10 @@ function M.setup()
|
||||||
vim.api.nvim_command("command! " .. cmd[1] .. " " .. cmd[2])
|
vim.api.nvim_command("command! " .. cmd[1] .. " " .. cmd[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
utils.add_keymaps({
|
utils.set_keymap_list({
|
||||||
n = {
|
{ "<leader>ff", function() M.format() end },
|
||||||
["<leader>ff"] = {
|
{ "<leader>fe", function() M.format_enable() end },
|
||||||
cmd = function() M.format(true) end
|
{ "<leader>fd", function() M.format_disable() end },
|
||||||
},
|
|
||||||
["<leader>fe"] = {
|
|
||||||
cmd = M.format_enable,
|
|
||||||
},
|
|
||||||
["<leader>fd"] = {
|
|
||||||
cmd = M.format_disable,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,151 +1,98 @@
|
||||||
|
local utils = require("utils")
|
||||||
local g = vim.g
|
local g = vim.g
|
||||||
|
|
||||||
g.mapleader = " "
|
g.mapleader = " "
|
||||||
g.maplocalleader = " "
|
g.maplocalleader = " "
|
||||||
|
|
||||||
local move_up = {
|
local move_up = { "v:count || mode(1)[0:1] == \"no\" ? \"k\" : \"gk\"", { expr = true } }
|
||||||
cmd = "v:count || mode(1)[0:1] == \"no\" ? \"k\" : \"gk\"",
|
local move_down = { "v:count || mode(1)[0:1] == \"no\" ? \"j\" : \"gj\"", { expr = true } }
|
||||||
opts = {
|
|
||||||
expr = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
local move_down = {
|
utils.foreach({
|
||||||
cmd = "v:count || mode(1)[0:1] == \"no\" ? \"j\" : \"gj\"",
|
{
|
||||||
opts = {
|
"n",
|
||||||
expr = true
|
{
|
||||||
}
|
-- Using lspsaga for hover doc
|
||||||
}
|
{ "K", "<Nop>", },
|
||||||
|
-- Using lspsaga finder with gr which does references
|
||||||
|
{ "grr", "<Nop>", },
|
||||||
|
{ "gra", "<Nop>", },
|
||||||
|
{ "grn", "<Nop>", },
|
||||||
|
{ "gri", "<Nop>", },
|
||||||
|
-- Navigation
|
||||||
|
{ "<C-Left>", "<C-w>h", },
|
||||||
|
{ "<C-Down>", "<C-w>j", },
|
||||||
|
{ "<C-Up>", "<C-w>k", },
|
||||||
|
{ "<C-Right>", "<C-w>l", },
|
||||||
|
{ "<C-h>", "<C-w>h", },
|
||||||
|
{ "<C-j>", "<C-w>j", },
|
||||||
|
{ "<C-k>", "<C-w>k", },
|
||||||
|
{ "<C-l>", "<C-w>l", },
|
||||||
|
|
||||||
|
-- Window
|
||||||
|
{ "<C-q>", "<C-w>q", },
|
||||||
|
|
||||||
local utils = require("utils")
|
-- Disable current highlights
|
||||||
|
{ "<Esc>", "<cmd> noh <CR>", },
|
||||||
|
|
||||||
utils.add_keymaps({
|
-- Copies the entire file
|
||||||
n = {
|
{ "<C-c>", ":%y+<CR>", { silent = true } },
|
||||||
-- Using lspsaga for hover doc
|
|
||||||
["K"] = {
|
|
||||||
cmd = "<Nop>",
|
|
||||||
},
|
|
||||||
-- Using lspsaga finder with gr which does references
|
|
||||||
["grr"] = {
|
|
||||||
cmd = "<Nop>",
|
|
||||||
},
|
|
||||||
["gra"] = {
|
|
||||||
cmd = "<Nop>",
|
|
||||||
},
|
|
||||||
["grn"] = {
|
|
||||||
cmd = "<Nop>",
|
|
||||||
},
|
|
||||||
["gri"] = {
|
|
||||||
cmd = "<Nop>",
|
|
||||||
},
|
|
||||||
-- Navigation
|
|
||||||
["<C-Left>"] = {
|
|
||||||
cmd = "<C-w>h",
|
|
||||||
},
|
|
||||||
["<C-Down>"] = {
|
|
||||||
cmd = "<C-w>j",
|
|
||||||
},
|
|
||||||
["<C-Up>"] = {
|
|
||||||
cmd = "<C-w>k",
|
|
||||||
},
|
|
||||||
["<C-Right>"] = {
|
|
||||||
cmd = "<C-w>l",
|
|
||||||
},
|
|
||||||
["<C-h>"] = {
|
|
||||||
cmd = "<C-w>h",
|
|
||||||
},
|
|
||||||
["<C-j>"] = {
|
|
||||||
cmd = "<C-w>j",
|
|
||||||
},
|
|
||||||
["<C-k>"] = {
|
|
||||||
cmd = "<C-w>k",
|
|
||||||
},
|
|
||||||
["<C-l>"] = {
|
|
||||||
cmd = "<C-w>l",
|
|
||||||
},
|
|
||||||
|
|
||||||
-- Window
|
-- Allow moving the cursor through wrapped lines with <Up> and <Down>
|
||||||
["<C-q>"] = {
|
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
|
||||||
cmd = "<C-w>q",
|
-- 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
|
||||||
|
{ "<Up>", move_up[1], move_up[2], },
|
||||||
|
{ "<Down>", move_down[1], move_down[2], },
|
||||||
|
{ "j", move_down[1], move_down[2], },
|
||||||
|
{ "k", move_up[1], move_up[2], },
|
||||||
|
-- Maps to remove
|
||||||
|
{ "<C-z>", "<Nop>", },
|
||||||
|
|
||||||
-- Disable current highlights
|
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
|
||||||
["<Esc>"] = {
|
-- Prioritize regular m for leaping, and <leader>m for setting marks.
|
||||||
cmd = "<cmd> noh <CR>",
|
{ "<leader>m", "m", },
|
||||||
},
|
{ "[d", function()
|
||||||
|
|
||||||
-- Copies the entire file
|
|
||||||
["<C-c>"] = {
|
|
||||||
cmd = ":%y+<CR>",
|
|
||||||
opts = {
|
|
||||||
silent = true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
-- Allow moving the cursor through wrapped lines with <Up> and <Down>
|
|
||||||
-- http://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
|
|
||||||
["<Up>"] = move_up,
|
|
||||||
["<Down>"] = move_down,
|
|
||||||
["j"] = move_down,
|
|
||||||
["k"] = move_up,
|
|
||||||
-- Maps to remove
|
|
||||||
["<C-z>"] = {
|
|
||||||
cmd = "<Nop>",
|
|
||||||
},
|
|
||||||
|
|
||||||
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
|
|
||||||
-- Prioritize regular m for leaping, and <leader>m for setting marks.
|
|
||||||
["<leader>m"] = {
|
|
||||||
cmd = "m",
|
|
||||||
},
|
|
||||||
["[d"] = {
|
|
||||||
cmd = function()
|
|
||||||
vim.diagnostic.jump({ count = -1, float = false })
|
vim.diagnostic.jump({ count = -1, float = false })
|
||||||
end
|
end },
|
||||||
},
|
{ "]d", function()
|
||||||
["]d"] = {
|
|
||||||
cmd = function()
|
|
||||||
vim.diagnostic.jump({ count = 1, float = false })
|
vim.diagnostic.jump({ count = 1, float = false })
|
||||||
end
|
end },
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
i = {},
|
{
|
||||||
v = {
|
"v",
|
||||||
["<Up>"] = move_up,
|
{
|
||||||
["<Down>"] = move_down,
|
{ "<Up>", move_up[1], move_up[2], },
|
||||||
["j"] = move_down,
|
{ "<Down>", move_down[1], move_down[2], },
|
||||||
["k"] = move_up,
|
{ "j", move_down[1], move_down[2], },
|
||||||
["<tab>"] = {
|
{ "k", move_up[1], move_up[2], },
|
||||||
cmd = ">gv",
|
{ "<tab>", ">gv", },
|
||||||
},
|
{ "<S-tab>", "<gv", },
|
||||||
["<S-tab>"] = {
|
|
||||||
cmd = "<gv",
|
|
||||||
},
|
|
||||||
|
|
||||||
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
|
-- Marks are less frequently used than leaping, also, less relevant with arrow and fzf navigation.
|
||||||
-- Prioritize regular m for leaping, and <leader>m for setting marks.
|
-- Prioritize regular m for leaping, and <leader>m for setting marks.
|
||||||
["<leader>m"] = {
|
{ "<leader>m", "m", },
|
||||||
cmd = "m",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
x = {
|
{
|
||||||
["<Up>"] = move_up,
|
"x",
|
||||||
["<Down>"] = move_down,
|
{
|
||||||
["j"] = move_down,
|
{ "<Up>", move_up[1], move_up[2], },
|
||||||
["k"] = move_up,
|
{ "<Down>", move_down[1], move_down[2], },
|
||||||
["p"] = {
|
{ "j", move_down[1], move_down[2], },
|
||||||
cmd = "p:let @+=@0<CR>:let @\"=@0<CR>",
|
{ "k", move_up[1], move_up[2], },
|
||||||
opts = {
|
{ "p", "p:let @+=@0<CR>:let @\"=@0<CR>", { silent = true }, },
|
||||||
silent = true
|
}
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
t = {
|
{
|
||||||
["<C-q>"] = {
|
"t",
|
||||||
cmd = "<C-\\><C-N>",
|
{
|
||||||
},
|
{ "<C-q>", "<C-\\><C-N>", },
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
}, function(mode_mapping)
|
||||||
|
local mode = mode_mapping[1]
|
||||||
|
local mappings = mode_mapping[2]
|
||||||
|
utils.set_keymap_list(mappings, mode)
|
||||||
|
end)
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,23 @@
|
||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
|
||||||
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
|
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
|
||||||
local function switch_source_header(bufnr)
|
local function switch_source_header()
|
||||||
bufnr = utils.validate_bufnr(bufnr)
|
local bufnr = utils.validate_bufnr(0)
|
||||||
local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1]
|
local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1]
|
||||||
local params = { uri = vim.uri_from_bufnr(bufnr) }
|
|
||||||
if clangd_client then
|
if clangd_client then
|
||||||
clangd_client.request("textDocument/switchSourceHeader", params, function(err, result)
|
clangd_client.request(
|
||||||
if err then
|
"textDocument/switchSourceHeader",
|
||||||
error(tostring(err))
|
{ uri = vim.uri_from_bufnr(bufnr) },
|
||||||
end
|
function(err, result)
|
||||||
if not result then
|
if err then
|
||||||
print "Corresponding file cannot be determined"
|
error(tostring(err))
|
||||||
return
|
end
|
||||||
end
|
if not result then
|
||||||
vim.api.nvim_command("drop " .. vim.uri_to_fname(result))
|
print "Corresponding file cannot be determined"
|
||||||
end, bufnr)
|
return
|
||||||
|
end
|
||||||
|
vim.api.nvim_command("drop " .. vim.uri_to_fname(result))
|
||||||
|
end, bufnr)
|
||||||
else
|
else
|
||||||
print "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer"
|
print "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer"
|
||||||
end
|
end
|
||||||
|
|
@ -44,19 +46,9 @@ return {
|
||||||
"compile_flags.txt",
|
"compile_flags.txt",
|
||||||
"configure.ac",
|
"configure.ac",
|
||||||
},
|
},
|
||||||
on_attach = function(_, bufnr)
|
on_attach = function()
|
||||||
local lsp_maps = {
|
utils.set_keymap_list({
|
||||||
{
|
{ "<leader>ko", switch_source_header, },
|
||||||
"<leader>ko",
|
})
|
||||||
function() switch_source_header(0) end,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local keymaps = { n = {} }
|
|
||||||
for i, _ in ipairs(lsp_maps) do
|
|
||||||
local binding, cmd = unpack(lsp_maps[i])
|
|
||||||
keymaps.n[binding] = { cmd = cmd, opts = { buffer = bufnr } }
|
|
||||||
end
|
|
||||||
utils.add_keymaps(keymaps)
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,34 +24,9 @@ local function global_on_attach(client, bufnr)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
utils.add_keymaps({
|
utils.set_keymap_list({
|
||||||
n = {
|
{ "gd", function() vim.lsp.buf.definition({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } },
|
||||||
|
{ "gD", function() vim.lsp.buf.declaration({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } },
|
||||||
["gd"] = {
|
|
||||||
cmd = function()
|
|
||||||
vim.lsp.buf.definition({
|
|
||||||
reuse_win = true,
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
opts = {
|
|
||||||
noremap = true,
|
|
||||||
silent = true,
|
|
||||||
buffer = bufnr
|
|
||||||
}
|
|
||||||
},
|
|
||||||
["gD"] = {
|
|
||||||
cmd = function()
|
|
||||||
vim.lsp.buf.declaration({
|
|
||||||
reuse_win = true,
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
opts = {
|
|
||||||
noremap = true,
|
|
||||||
silent = true,
|
|
||||||
buffer = bufnr
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,53 +3,37 @@ return {
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"nvim-lua/plenary.nvim",
|
"nvim-lua/plenary.nvim",
|
||||||
"nvim-treesitter/nvim-treesitter",
|
"nvim-treesitter/nvim-treesitter",
|
||||||
{ 'echasnovski/mini.diff', version = false },
|
|
||||||
{ "stevearc/dressing.nvim", opts = {} },
|
|
||||||
},
|
},
|
||||||
config = function()
|
opts = {
|
||||||
require("codecompanion").setup({
|
strategies = {
|
||||||
strategies = {
|
chat = {
|
||||||
chat = {
|
adapter = "copilot",
|
||||||
adapter = "copilot",
|
|
||||||
},
|
|
||||||
inline = {
|
|
||||||
adapter = "copilot",
|
|
||||||
},
|
|
||||||
agent = {
|
|
||||||
adapter = "copilot",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
adapters = {
|
inline = {
|
||||||
copilot = function() return require("codecompanion.adapters").extend("copilot", {}) end,
|
adapter = "copilot",
|
||||||
},
|
},
|
||||||
display = {
|
agent = {
|
||||||
diff = {
|
adapter = "copilot",
|
||||||
provider = "mini_diff",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
opts = {
|
},
|
||||||
log_level = "DEBUG",
|
adapters = {
|
||||||
|
copilot = function() return require("codecompanion.adapters").extend("copilot", {}) end,
|
||||||
|
},
|
||||||
|
display = {
|
||||||
|
diff = {
|
||||||
|
provider = "mini_diff",
|
||||||
},
|
},
|
||||||
})
|
},
|
||||||
|
opts = {
|
||||||
local keymaps = {
|
log_level = "DEBUG",
|
||||||
n = {
|
},
|
||||||
["<Leader>ci"] = { cmd = "<cmd>CodeCompanion<cr>" },
|
},
|
||||||
["<Leader>cc"] = { cmd = "<cmd>CodeCompanionChat toggle<cr>" },
|
keys = {
|
||||||
["<Leader>cm"] = { cmd = "<cmd>CodeCompanion /commit<cr>" },
|
{ "<Leader>ci", "<cmd>CodeCompanion<cr>" },
|
||||||
},
|
{ "<Leader>cc", "<cmd>CodeCompanionChat toggle<cr>" },
|
||||||
v = {
|
{ "<Leader>ce", "<cmd>CodeCompanion /explain<cr>", mode = "v" },
|
||||||
["<Leader>ci"] = { cmd = "<cmd>CodeCompanion<cr>" },
|
},
|
||||||
["ga"] = { cmd = "<cmd>CodeCompanionAdd<cr>" },
|
init = function()
|
||||||
["<Leader>ce"] = { cmd = "<cmd>CodeCompanion /explain<cr>" },
|
|
||||||
["<Leader>cf"] = { cmd = "<cmd>CodeCompanion /fix<cr>" },
|
|
||||||
["<Leader>ct"] = { cmd = "<cmd>CodeCompanion /tests<cr>" },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
local utils = require("utils")
|
|
||||||
utils.add_opts_to_all_mappings(keymaps, { silent = true })
|
|
||||||
utils.add_keymaps(keymaps)
|
|
||||||
|
|
||||||
vim.cmd([[cab cc CodeCompanion]])
|
vim.cmd([[cab cc CodeCompanion]])
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,24 +3,16 @@ return {
|
||||||
build = "make",
|
build = "make",
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
lazy = true,
|
lazy = true,
|
||||||
config = function()
|
opts = {
|
||||||
require("codesnap").setup({
|
mac_window_bar = true,
|
||||||
mac_window_bar = true,
|
title = "codesnap.nvim",
|
||||||
title = "codesnap.nvim",
|
code_font_family = "JetBrainsMono Nerd Font",
|
||||||
code_font_family = "JetBrainsMono Nerd Font",
|
breadcrumbs_separator = "/",
|
||||||
breadcrumbs_separator = "/",
|
has_breadcrumbs = true,
|
||||||
has_breadcrumbs = true,
|
bg_theme = "grape",
|
||||||
bg_theme = "grape",
|
watermark = "",
|
||||||
watermark = "",
|
},
|
||||||
})
|
keys = {
|
||||||
|
{ "<leader>cs", ":CodeSnap<CR>", mode = "v", silent = true, noremap = true },
|
||||||
require("utils").add_keymaps({
|
},
|
||||||
v = {
|
|
||||||
["<leader>cs"] = {
|
|
||||||
cmd = ":CodeSnap<CR>",
|
|
||||||
opts = { silent = true },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
return {
|
return {
|
||||||
"github/copilot.vim",
|
"github/copilot.vim",
|
||||||
config = function()
|
event = "InsertEnter",
|
||||||
|
init = function()
|
||||||
vim.g.copilot_no_tab_map = true
|
vim.g.copilot_no_tab_map = true
|
||||||
require("utils").add_keymaps({
|
end,
|
||||||
i = {
|
keys = {
|
||||||
["<Right>"] = {
|
{
|
||||||
cmd = 'copilot#Accept("\\<Right>")',
|
"<Right>",
|
||||||
opts = {
|
'copilot#Accept("\\<Right>")',
|
||||||
expr = true,
|
mode = "i",
|
||||||
replace_keycodes = false,
|
expr = true,
|
||||||
silent = true,
|
replace_keycodes = false,
|
||||||
}
|
silent = true,
|
||||||
}
|
desc = "Copilot Accept with <Right>",
|
||||||
}
|
},
|
||||||
})
|
},
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,95 +1,86 @@
|
||||||
return {
|
return {
|
||||||
"b0o/incline.nvim",
|
"b0o/incline.nvim",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"lewis6991/gitsigns.nvim"
|
{
|
||||||
|
"lewis6991/gitsigns.nvim",
|
||||||
|
opts = {},
|
||||||
|
keys = {
|
||||||
|
{ "[g", function() require("gitsigns").nav_hunk("prev") end, },
|
||||||
|
{ "]g", function() require("gitsigns").nav_hunk("next") end, },
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
lazy = true,
|
lazy = true,
|
||||||
config = function()
|
opts = {
|
||||||
local gitsigns = require("gitsigns")
|
window = {
|
||||||
gitsigns.setup({})
|
padding = 0,
|
||||||
local devicons = require("nvim-web-devicons")
|
},
|
||||||
require("incline").setup({
|
hide = {
|
||||||
window = {
|
cursorline = true,
|
||||||
padding = 0,
|
},
|
||||||
},
|
render = function(props)
|
||||||
hide = {
|
local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t")
|
||||||
cursorline = true,
|
if filename == "" then
|
||||||
},
|
filename = "[No Name]"
|
||||||
render = function(props)
|
end
|
||||||
local filename = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(props.buf), ":t")
|
local ft_icon, ft_color = require("nvim-web-devicons").get_icon_color(filename)
|
||||||
if filename == "" then
|
|
||||||
filename = "[No Name]"
|
|
||||||
end
|
|
||||||
local ft_icon, ft_color = devicons.get_icon_color(filename)
|
|
||||||
|
|
||||||
local function get_git_diff()
|
local function get_git_diff()
|
||||||
local icons = { removed = "", changed = "", added = "" }
|
local icons = { removed = "", changed = "", added = "" }
|
||||||
local signs = vim.b[props.buf].gitsigns_status_dict
|
local signs = vim.b[props.buf].gitsigns_status_dict
|
||||||
local labels = {}
|
local labels = {}
|
||||||
if signs == nil then
|
if signs == nil then
|
||||||
return labels
|
|
||||||
end
|
|
||||||
for name, icon in pairs(icons) do
|
|
||||||
if tonumber(signs[name]) and signs[name] > 0 then
|
|
||||||
table.insert(labels, { icon .. " " .. signs[name] .. " ", group = "Diff" .. name })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if #labels > 0 then
|
|
||||||
table.insert(labels, { "┊ " })
|
|
||||||
end
|
|
||||||
return labels
|
return labels
|
||||||
end
|
end
|
||||||
|
for name, icon in pairs(icons) do
|
||||||
local function get_diagnostic_label()
|
if tonumber(signs[name]) and signs[name] > 0 then
|
||||||
local icons = { error = "", warn = "", info = "", hint = "" }
|
table.insert(labels, { icon .. " " .. signs[name] .. " ", group = "Diff" .. name })
|
||||||
local label = {}
|
|
||||||
|
|
||||||
for severity, icon in pairs(icons) do
|
|
||||||
local n = #vim.diagnostic.get(props.buf,
|
|
||||||
{ severity = vim.diagnostic.severity[string.upper(severity)] })
|
|
||||||
if n > 0 then
|
|
||||||
table.insert(label, { icon .. " " .. n .. " ", group = "DiagnosticSign" .. severity })
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
if #label > 0 then
|
end
|
||||||
table.insert(label, { "┊ " })
|
if #labels > 0 then
|
||||||
|
table.insert(labels, { "┊ " })
|
||||||
|
end
|
||||||
|
return labels
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_diagnostic_label()
|
||||||
|
local icons = { error = "", warn = "", info = "", hint = "" }
|
||||||
|
local label = {}
|
||||||
|
|
||||||
|
for severity, icon in pairs(icons) do
|
||||||
|
local n = #vim.diagnostic.get(props.buf,
|
||||||
|
{ severity = vim.diagnostic.severity[string.upper(severity)] })
|
||||||
|
if n > 0 then
|
||||||
|
table.insert(label, { icon .. " " .. n .. " ", group = "DiagnosticSign" .. severity })
|
||||||
end
|
end
|
||||||
return label
|
end
|
||||||
|
if #label > 0 then
|
||||||
|
table.insert(label, { "┊ " })
|
||||||
|
end
|
||||||
|
return label
|
||||||
|
end
|
||||||
|
|
||||||
|
local function get_arrow_label()
|
||||||
|
local statusline = require("arrow.statusline")
|
||||||
|
if statusline.is_on_arrow_file(props.buf) == nil then
|
||||||
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_arrow_label()
|
return " " .. statusline.text_for_statusline_with_icons(props.buf)
|
||||||
local statusline = require("arrow.statusline")
|
end
|
||||||
if statusline.is_on_arrow_file(props.buf) == nil then
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
return " " .. statusline.text_for_statusline_with_icons(props.buf)
|
return {
|
||||||
end
|
guibg = "#1e2030",
|
||||||
|
guifg = "#cad3f5",
|
||||||
return {
|
{ " " },
|
||||||
guibg = "#1e2030",
|
{ get_diagnostic_label() },
|
||||||
guifg = "#cad3f5",
|
{ get_git_diff() },
|
||||||
{ " " },
|
{ (ft_icon or "") .. " ", guifg = ft_color, guibg = "none" },
|
||||||
{ get_diagnostic_label() },
|
{ filename .. " ┊", gui = vim.bo[props.buf].modified and "bold,italic" or "bold" },
|
||||||
{ get_git_diff() },
|
{ get_arrow_label() .. " " .. vim.api.nvim_win_get_number(props.win), group = "DevIconWindows" },
|
||||||
{ (ft_icon or "") .. " ", guifg = ft_color, guibg = "none" },
|
{ " " }
|
||||||
{ filename .. " ┊", gui = vim.bo[props.buf].modified and "bold,italic" or "bold" },
|
}
|
||||||
{ get_arrow_label() .. " " .. vim.api.nvim_win_get_number(props.win), group = "DevIconWindows" },
|
end,
|
||||||
{ " " }
|
},
|
||||||
}
|
|
||||||
end,
|
|
||||||
|
|
||||||
require("utils").add_keymaps({
|
|
||||||
n = {
|
|
||||||
["[g"] = {
|
|
||||||
cmd = function() gitsigns.nav_hunk("prev") end
|
|
||||||
},
|
|
||||||
["]g"] = {
|
|
||||||
cmd = function() gitsigns.nav_hunk("next") end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,15 @@
|
||||||
|
local function leap_across_windows()
|
||||||
|
require("leap").leap({
|
||||||
|
target_windows = require("leap.user").get_focusable_windows()
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function leap_in_current_buffer()
|
||||||
|
require("leap").leap({
|
||||||
|
target_windows = { vim.api.nvim_get_current_win() }
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
local saved_hlsearch = false
|
local saved_hlsearch = false
|
||||||
local saved_highlights = {}
|
local saved_highlights = {}
|
||||||
local colors = require("ayu.colors")
|
local colors = require("ayu.colors")
|
||||||
|
|
@ -19,7 +31,13 @@ return {
|
||||||
},
|
},
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
lazy = true,
|
lazy = true,
|
||||||
config = function()
|
opts = {},
|
||||||
|
keys = {
|
||||||
|
{ "m", function() leap_across_windows() end, mode = "n" },
|
||||||
|
{ "m", function() leap_in_current_buffer() end, mode = "v" },
|
||||||
|
{ "m", function() leap_in_current_buffer() end, mode = "o" },
|
||||||
|
},
|
||||||
|
init = function()
|
||||||
local leap = require("leap")
|
local leap = require("leap")
|
||||||
|
|
||||||
-- Disable auto jumping to the first match
|
-- Disable auto jumping to the first match
|
||||||
|
|
@ -53,42 +71,5 @@ return {
|
||||||
for _, cmd in ipairs(autocmds) do
|
for _, cmd in ipairs(autocmds) do
|
||||||
utils.create_user_event_cb(cmd.event_name, cmd.cb, leap_augroup_name)
|
utils.create_user_event_cb(cmd.event_name, cmd.cb, leap_augroup_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
local leap_user = require("leap.user")
|
|
||||||
local function leap_across_windows()
|
|
||||||
leap.leap({
|
|
||||||
target_windows = leap_user.get_focusable_windows()
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local function leap_in_current_buffer()
|
|
||||||
leap.leap({
|
|
||||||
target_windows = { vim.api.nvim_get_current_win() }
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
utils.add_keymaps({
|
|
||||||
n = {
|
|
||||||
["m"] = {
|
|
||||||
cmd = function()
|
|
||||||
leap_across_windows()
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
v = {
|
|
||||||
["m"] = {
|
|
||||||
cmd = function()
|
|
||||||
leap_in_current_buffer()
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
o = {
|
|
||||||
["m"] = {
|
|
||||||
cmd = function()
|
|
||||||
leap_in_current_buffer()
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,59 +7,36 @@ return {
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"nvim-tree/nvim-web-devicons",
|
"nvim-tree/nvim-web-devicons",
|
||||||
},
|
},
|
||||||
after = "nvim-lspconfig",
|
opts = {
|
||||||
config = function()
|
request_timeout = 750,
|
||||||
require("lspsaga").setup({
|
symbol_in_winbar = {
|
||||||
request_timeout = 750,
|
enable = false,
|
||||||
symbol_in_winbar = {
|
},
|
||||||
enable = false,
|
implement = {
|
||||||
},
|
enable = false,
|
||||||
implement = {
|
},
|
||||||
enable = false,
|
outline = {
|
||||||
},
|
enable = false,
|
||||||
outline = {
|
win_width = 52,
|
||||||
enable = false,
|
},
|
||||||
win_width = 52,
|
ui = {
|
||||||
},
|
border = "rounded",
|
||||||
ui = {
|
title = false,
|
||||||
border = "rounded",
|
},
|
||||||
title = false,
|
code_action = {
|
||||||
},
|
extend_gitsigns = true
|
||||||
code_action = {
|
},
|
||||||
extend_gitsigns = true
|
hover = {
|
||||||
},
|
jump_on_first_press = true
|
||||||
hover = {
|
},
|
||||||
jump_on_first_press = true
|
},
|
||||||
},
|
keys = {
|
||||||
})
|
{ "K", ":Lspsaga hover_doc<CR>", silent = true, },
|
||||||
|
{ "<leader>rn", ":Lspsaga rename<CR>", silent = true, },
|
||||||
local keymaps = {
|
{ "gr", ":Lspsaga finder<CR>", silent = true, },
|
||||||
n = {
|
{ "<leader>lt", ":Lspsaga peek_type_definition<CR>", silent = true, },
|
||||||
["K"] = {
|
{ "<leader>ld", ":Lspsaga peek_definition<CR>", silent = true, },
|
||||||
cmd = ":Lspsaga hover_doc<CR>"
|
{ "<leader>ca", ":Lspsaga code_action<CR>", silent = true, },
|
||||||
},
|
{ "<leader>lc", ":Lspsaga incoming_calls<CR>", silent = true, },
|
||||||
["<leader>rn"] = {
|
},
|
||||||
cmd = ":Lspsaga rename<CR>"
|
|
||||||
},
|
|
||||||
["gr"] = {
|
|
||||||
cmd = ":Lspsaga finder<CR>"
|
|
||||||
},
|
|
||||||
["<leader>lt"] = {
|
|
||||||
cmd = ":Lspsaga peek_type_definition<CR>"
|
|
||||||
},
|
|
||||||
["<leader>ld"] = {
|
|
||||||
cmd = ":Lspsaga peek_definition<CR>"
|
|
||||||
},
|
|
||||||
["<leader>ca"] = {
|
|
||||||
cmd = ":Lspsaga code_action<CR>"
|
|
||||||
},
|
|
||||||
["<leader>lc"] = {
|
|
||||||
cmd = ":Lspsaga incoming_calls<CR>"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
local utils = require("utils")
|
|
||||||
utils.add_opts_to_all_mappings(keymaps, { silent = true })
|
|
||||||
utils.add_keymaps(keymaps)
|
|
||||||
end,
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
local wm = require("window_management")
|
|
||||||
|
|
||||||
local function resize_mode()
|
local function resize_mode()
|
||||||
if wm.is_in_resizing_mode() then
|
if require("window_management").is_in_resizing_mode() then
|
||||||
return "▲ Resizing ▼"
|
return "▲ Resizing ▼"
|
||||||
else
|
else
|
||||||
return ""
|
return ""
|
||||||
|
|
@ -15,46 +13,44 @@ return {
|
||||||
},
|
},
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
lazy = true,
|
lazy = true,
|
||||||
config = function()
|
opts = {
|
||||||
require("lualine").setup {
|
options = {
|
||||||
options = {
|
theme = "ayu",
|
||||||
theme = "ayu",
|
section_separators = {
|
||||||
section_separators = {
|
left = "",
|
||||||
left = "",
|
right = "",
|
||||||
right = "",
|
|
||||||
},
|
|
||||||
component_separators = {
|
|
||||||
left = "",
|
|
||||||
right = ""
|
|
||||||
},
|
|
||||||
icons_enabled = true,
|
|
||||||
},
|
},
|
||||||
sections = {
|
component_separators = {
|
||||||
lualine_a = { "mode" },
|
left = "",
|
||||||
lualine_b = {
|
right = ""
|
||||||
"branch",
|
},
|
||||||
{
|
icons_enabled = true,
|
||||||
"diagnostics",
|
},
|
||||||
sources = { "nvim_lsp" },
|
sections = {
|
||||||
sections = { "error", "warn", "info", "hint" },
|
lualine_a = { "mode" },
|
||||||
update_in_insert = false,
|
lualine_b = {
|
||||||
},
|
"branch",
|
||||||
resize_mode,
|
{
|
||||||
|
"diagnostics",
|
||||||
|
sources = { "nvim_lsp" },
|
||||||
|
sections = { "error", "warn", "info", "hint" },
|
||||||
|
update_in_insert = false,
|
||||||
},
|
},
|
||||||
lualine_c = { "buffers" },
|
resize_mode,
|
||||||
lualine_x = { "encoding", "fileformat", "filetype" },
|
|
||||||
lualine_y = { "progress" },
|
|
||||||
lualine_z = { "location" }
|
|
||||||
},
|
},
|
||||||
inactive_sections = {
|
lualine_c = { "buffers" },
|
||||||
lualine_a = {},
|
lualine_x = { "encoding", "fileformat", "filetype" },
|
||||||
lualine_b = {},
|
lualine_y = { "progress" },
|
||||||
lualine_c = {},
|
lualine_z = { "location" }
|
||||||
lualine_x = {},
|
},
|
||||||
lualine_y = {},
|
inactive_sections = {
|
||||||
lualine_z = {}
|
lualine_a = {},
|
||||||
},
|
lualine_b = {},
|
||||||
tabline = {},
|
lualine_c = {},
|
||||||
}
|
lualine_x = {},
|
||||||
end
|
lualine_y = {},
|
||||||
|
lualine_z = {}
|
||||||
|
},
|
||||||
|
tabline = {},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,8 @@ return {
|
||||||
},
|
},
|
||||||
event = "VeryLazy",
|
event = "VeryLazy",
|
||||||
lazy = true,
|
lazy = true,
|
||||||
config = function()
|
opts = {},
|
||||||
local neogit = require("neogit")
|
keys = {
|
||||||
neogit.setup()
|
{ "<leader>g", function() require("neogit").open({ kind = "vsplit" }) end }
|
||||||
|
},
|
||||||
require("utils").add_keymaps({
|
|
||||||
n = {
|
|
||||||
["<leader>g"] = {
|
|
||||||
cmd = function() neogit.open({ kind = "vsplit" }) end,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,81 +5,57 @@ local are_stepping_keymaps_active = false
|
||||||
return {
|
return {
|
||||||
"mfussenegger/nvim-dap",
|
"mfussenegger/nvim-dap",
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"rcarriga/nvim-dap-ui",
|
{
|
||||||
|
"rcarriga/nvim-dap-ui",
|
||||||
|
opts = {
|
||||||
|
controls = {
|
||||||
|
enabled = false,
|
||||||
|
},
|
||||||
|
layouts = {
|
||||||
|
{
|
||||||
|
elements = {
|
||||||
|
{
|
||||||
|
id = "watches",
|
||||||
|
size = 0.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id = "stacks",
|
||||||
|
size = 0.5
|
||||||
|
}
|
||||||
|
},
|
||||||
|
position = "bottom",
|
||||||
|
size = 15
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
-- Special adapters
|
-- Special adapters
|
||||||
"leoluz/nvim-dap-go",
|
{ "leoluz/nvim-dap-go", opts = {} },
|
||||||
"mfussenegger/nvim-dap-python",
|
{ "mfussenegger/nvim-dap-python", },
|
||||||
|
|
||||||
{ "nvim-neotest/nvim-nio", lazy = true },
|
{ "nvim-neotest/nvim-nio", lazy = true },
|
||||||
"LiadOz/nvim-dap-repl-highlights",
|
{ "LiadOz/nvim-dap-repl-highlights", opts = {} },
|
||||||
"theHamsta/nvim-dap-virtual-text",
|
{ "theHamsta/nvim-dap-virtual-text", opts = {} },
|
||||||
"Weissle/persistent-breakpoints.nvim",
|
{ "Weissle/persistent-breakpoints.nvim", opts = { load_breakpoints_event = { "BufReadPost" } } },
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local dap = require("dap")
|
local dap = require("dap")
|
||||||
local dapui = require("dapui")
|
|
||||||
-- Special adapters
|
|
||||||
require("dap-go").setup()
|
|
||||||
require("dap-python").setup("python3")
|
require("dap-python").setup("python3")
|
||||||
-- Special adapters
|
|
||||||
|
|
||||||
require("dap.ext.vscode").load_launchjs()
|
require("dap.ext.vscode").load_launchjs()
|
||||||
require("persistent-breakpoints").setup {
|
|
||||||
load_breakpoints_event = { "BufReadPost" }
|
|
||||||
}
|
|
||||||
|
|
||||||
require("nvim-dap-repl-highlights").setup()
|
|
||||||
require("nvim-dap-virtual-text").setup()
|
|
||||||
local virtual_text = require("nvim-dap-virtual-text/virtual_text")
|
local virtual_text = require("nvim-dap-virtual-text/virtual_text")
|
||||||
local breakpoint_api = require("persistent-breakpoints.api")
|
local breakpoint_api = require("persistent-breakpoints.api")
|
||||||
|
|
||||||
dapui.setup({
|
|
||||||
controls = {
|
|
||||||
enabled = false,
|
|
||||||
},
|
|
||||||
layouts = {
|
|
||||||
{
|
|
||||||
elements = {
|
|
||||||
{
|
|
||||||
id = "watches",
|
|
||||||
size = 0.5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id = "stacks",
|
|
||||||
size = 0.5
|
|
||||||
}
|
|
||||||
},
|
|
||||||
position = "bottom",
|
|
||||||
size = 15
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
local stepping_keymaps = {
|
local stepping_keymaps = {
|
||||||
n = {
|
{ "m", function() dap.step_out() end },
|
||||||
["m"] = {
|
{ "n", function() dap.step_over() end },
|
||||||
cmd = function()
|
{ "i", function() dap.step_into() end },
|
||||||
dap.step_out()
|
|
||||||
end
|
|
||||||
},
|
|
||||||
["n"] = {
|
|
||||||
cmd = function()
|
|
||||||
dap.step_over()
|
|
||||||
end
|
|
||||||
},
|
|
||||||
["i"] = {
|
|
||||||
cmd = function()
|
|
||||||
dap.step_into()
|
|
||||||
end
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local function enter_debug_mode()
|
local function enter_debug_mode()
|
||||||
dapui.open()
|
require("dapui").open()
|
||||||
if not are_stepping_keymaps_active then
|
if not are_stepping_keymaps_active then
|
||||||
utils.add_temporary_keymaps(stepping_keymaps)
|
utils.set_keymap_list(stepping_keymaps)
|
||||||
are_stepping_keymaps_active = true
|
are_stepping_keymaps_active = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -87,9 +63,9 @@ return {
|
||||||
end
|
end
|
||||||
|
|
||||||
local function exit_debug_mode()
|
local function exit_debug_mode()
|
||||||
dapui.close()
|
require("dapui").close()
|
||||||
if are_stepping_keymaps_active then
|
if are_stepping_keymaps_active then
|
||||||
utils.remove_keymaps(stepping_keymaps)
|
utils.del_keymap_list(stepping_keymaps)
|
||||||
are_stepping_keymaps_active = false
|
are_stepping_keymaps_active = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -117,36 +93,17 @@ return {
|
||||||
exit_debug_mode()
|
exit_debug_mode()
|
||||||
end
|
end
|
||||||
|
|
||||||
utils.add_keymaps({
|
local function dap_stop()
|
||||||
n = {
|
dap.disconnect({ terminateDebuggee = true })
|
||||||
["<leader>dr"] = {
|
dap.close()
|
||||||
cmd = function()
|
exit_debug_mode()
|
||||||
dap.continue()
|
end
|
||||||
end
|
utils.set_keymap_list({
|
||||||
},
|
{ "<leader>dr", dap.continue },
|
||||||
["<leader>bt"] = {
|
{ "<leader>bt", breakpoint_api.toggle_breakpoint },
|
||||||
cmd = function()
|
{ "<leader>bc", breakpoint_api.set_conditional_breakpoint },
|
||||||
breakpoint_api.toggle_breakpoint()
|
{ "<leader>br", breakpoint_api.clear_all_breakpoints },
|
||||||
end
|
{ "<leader>ds", dap_stop },
|
||||||
},
|
|
||||||
["<leader>bc"] = {
|
|
||||||
cmd = function()
|
|
||||||
breakpoint_api.set_conditional_breakpoint()
|
|
||||||
end
|
|
||||||
},
|
|
||||||
["<leader>br"] = { -- breakpoint remove
|
|
||||||
cmd = function()
|
|
||||||
breakpoint_api.clear_all_breakpoints()
|
|
||||||
end
|
|
||||||
},
|
|
||||||
["<leader>ds"] = {
|
|
||||||
cmd = function()
|
|
||||||
dap.disconnect({ terminateDebuggee = true })
|
|
||||||
dap.close()
|
|
||||||
exit_debug_mode()
|
|
||||||
end
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,29 +30,9 @@ return {
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
utils.add_keymaps({
|
utils.set_keymap_list({
|
||||||
n = {
|
{ "gd", function() vim.lsp.buf.definition({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } },
|
||||||
["gd"] = {
|
{ "gD", function() vim.lsp.buf.declaration({ reuse_win = true, }) end, { noremap = true, buffer = bufnr } },
|
||||||
cmd = function()
|
|
||||||
vim.lsp.buf.definition()
|
|
||||||
end,
|
|
||||||
opts = {
|
|
||||||
noremap = true,
|
|
||||||
silent = true,
|
|
||||||
buffer = bufnr,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
["gD"] = {
|
|
||||||
cmd = function()
|
|
||||||
vim.lsp.buf.declaration()
|
|
||||||
end,
|
|
||||||
opts = {
|
|
||||||
noremap = true,
|
|
||||||
silent = true,
|
|
||||||
buffer = bufnr,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
local utils = require("utils")
|
|
||||||
local wm = require("window_management")
|
|
||||||
|
|
||||||
local terminal_window = nil
|
local terminal_window = nil
|
||||||
local terminal_bufnr = nil
|
local terminal_bufnr = nil
|
||||||
|
|
||||||
local function open_terminal_window()
|
local function open_terminal_window()
|
||||||
|
local utils = require("utils")
|
||||||
if terminal_bufnr and vim.api.nvim_buf_is_valid(terminal_bufnr) and utils.is_buf_buftype(terminal_bufnr, "terminal") then
|
if terminal_bufnr and vim.api.nvim_buf_is_valid(terminal_bufnr) and utils.is_buf_buftype(terminal_bufnr, "terminal") then
|
||||||
vim.cmd("botright split")
|
vim.cmd("botright split")
|
||||||
terminal_window = vim.api.nvim_get_current_win()
|
terminal_window = vim.api.nvim_get_current_win()
|
||||||
|
|
@ -23,6 +21,7 @@ local function toggle_terminal()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local utils = require("utils")
|
||||||
open_terminal_window()
|
open_terminal_window()
|
||||||
|
|
||||||
local term_height = vim.api.nvim_get_option("lines")
|
local term_height = vim.api.nvim_get_option("lines")
|
||||||
|
|
@ -37,13 +36,7 @@ local function toggle_terminal()
|
||||||
vim.api.nvim_command("startinsert")
|
vim.api.nvim_command("startinsert")
|
||||||
end
|
end
|
||||||
|
|
||||||
utils.add_keymaps({
|
vim.keymap.set("n", "<leader>h", function()
|
||||||
n = {
|
toggle_terminal()
|
||||||
["<leader>h"] = {
|
require("window_management").autosize_windows()
|
||||||
cmd = function()
|
end)
|
||||||
toggle_terminal()
|
|
||||||
wm.autosize_windows()
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,17 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local overridden_default_keymaps = {}
|
function M.set_keymap_list(keymap_list, mode)
|
||||||
|
mode = mode or "n"
|
||||||
|
M.foreach(keymap_list, function(mapping)
|
||||||
|
vim.keymap.set(mode, mapping[1], mapping[2], mapping[3] or {})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
local function is_single_keymap_table(map_table)
|
function M.del_keymap_list(keymap_list, mode)
|
||||||
assert(map_table)
|
mode = mode or "n"
|
||||||
return map_table.n or map_table.t or map_table.i or map_table.v or map_table.x or map_table.o
|
M.foreach(keymap_list, function(mapping)
|
||||||
|
vim.keymap.del(mode, mapping[1])
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_file_names_in_dir(dir, expr, strip_extension)
|
function M.get_file_names_in_dir(dir, expr, strip_extension)
|
||||||
|
|
@ -75,94 +82,6 @@ function M.add_opts_to_all_mappings(mappings, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function pass_keymap_tbl_to_fn(maps, fn)
|
|
||||||
if is_single_keymap_table(maps) then
|
|
||||||
fn(maps)
|
|
||||||
else
|
|
||||||
for _, map_table in pairs(maps) do
|
|
||||||
fn(map_table)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_keymaps(mode, buffer)
|
|
||||||
if buffer then
|
|
||||||
return vim.api.nvim_buf_get_keymap(buffer, mode)
|
|
||||||
end
|
|
||||||
|
|
||||||
return vim.api.nvim_get_keymap(mode)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.add_temporary_keymaps(maps)
|
|
||||||
assert(maps)
|
|
||||||
|
|
||||||
pass_keymap_tbl_to_fn(maps, function(map_table)
|
|
||||||
for mode, entries in pairs(map_table) do
|
|
||||||
-- We make an assumptino here which is that all the entries are buffers, or not buffers.
|
|
||||||
-- Meaning, we only check the first entry and trust that the rest are the same.
|
|
||||||
local result = get_keymaps(mode, (function()
|
|
||||||
for _, entry in pairs(entries) do
|
|
||||||
-- nil buffer is treated as a global keymap
|
|
||||||
return entry.buffer
|
|
||||||
end
|
|
||||||
end)())
|
|
||||||
|
|
||||||
for code, _ in pairs(entries) do
|
|
||||||
for _, map in ipairs(result) do
|
|
||||||
if map.lhs == code then
|
|
||||||
if not overridden_default_keymaps[mode] then
|
|
||||||
overridden_default_keymaps[mode] = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
overridden_default_keymaps[mode][code] = {
|
|
||||||
cmd = map.callback or map.rhs,
|
|
||||||
opts = {
|
|
||||||
noremap = map.noremap == 1,
|
|
||||||
expr = map.expr == 1,
|
|
||||||
silent = map.silent == 1,
|
|
||||||
nowait = map.nowait == 1,
|
|
||||||
script = map.script == 1,
|
|
||||||
buffer = type(map.buffer) == "number" and map.buffer or nil,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
M.add_keymaps(maps)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.add_keymaps(maps)
|
|
||||||
assert(maps)
|
|
||||||
|
|
||||||
pass_keymap_tbl_to_fn(maps, function(map_table)
|
|
||||||
for mode, entries in pairs(map_table) do
|
|
||||||
for code, info in pairs(entries) do
|
|
||||||
vim.keymap.set(mode, code, info.cmd, info.opts)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.remove_keymaps(maps)
|
|
||||||
assert(maps)
|
|
||||||
|
|
||||||
pass_keymap_tbl_to_fn(maps, function(map_table)
|
|
||||||
for mode, entries in pairs(map_table) do
|
|
||||||
local overriden_mode = overridden_default_keymaps[mode]
|
|
||||||
for code, _ in pairs(entries) do
|
|
||||||
vim.keymap.del(mode, code)
|
|
||||||
|
|
||||||
if overriden_mode and overriden_mode[code] then
|
|
||||||
vim.keymap.set(mode, code, overriden_mode[code].cmd, overriden_mode[code].opts)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.is_buf_filetype(bufnr, filetype)
|
function M.is_buf_filetype(bufnr, filetype)
|
||||||
return vim.api.nvim_buf_get_option(bufnr, "filetype") == filetype
|
return vim.api.nvim_buf_get_option(bufnr, "filetype") == filetype
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -189,75 +189,35 @@ end
|
||||||
|
|
||||||
function M.setup()
|
function M.setup()
|
||||||
local resizing_mode_keymaps = {
|
local resizing_mode_keymaps = {
|
||||||
n = {
|
{ "<Left>", function() resize_window(vim.api.nvim_get_current_win(), "h") end },
|
||||||
["<Left>"] = {
|
{ "<Down>", function() resize_window(vim.api.nvim_get_current_win(), "j") end },
|
||||||
cmd = function() resize_window(vim.api.nvim_get_current_win(), "h") end
|
{ "<Up>", function() resize_window(vim.api.nvim_get_current_win(), "k") end },
|
||||||
},
|
{ "<Right>", function() resize_window(vim.api.nvim_get_current_win(), "l") end },
|
||||||
["<Down>"] = {
|
{ "<Esc>", function() exit_resizing_mode() end },
|
||||||
cmd = function() resize_window(vim.api.nvim_get_current_win(), "j") end
|
{ "<Enter>", function() exit_resizing_mode() end },
|
||||||
},
|
{ "=", function() M.autosize_windows() end },
|
||||||
["<Up>"] = {
|
|
||||||
cmd = function() resize_window(vim.api.nvim_get_current_win(), "k") end
|
|
||||||
},
|
|
||||||
["<Right>"] = {
|
|
||||||
cmd = function() resize_window(vim.api.nvim_get_current_win(), "l") end
|
|
||||||
},
|
|
||||||
["<Esc>"] = {
|
|
||||||
cmd = function() exit_resizing_mode() end
|
|
||||||
},
|
|
||||||
["<Enter>"] = {
|
|
||||||
cmd = function() exit_resizing_mode() end
|
|
||||||
},
|
|
||||||
["="] = {
|
|
||||||
cmd = function() M.autosize_windows() end
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
local enter_resizing_mode_keymaps = {
|
local enter_resizing_mode_keymaps = {
|
||||||
n = {
|
{ "<C- >", function() enter_resizing_mode() end }
|
||||||
["<C- >"] = {
|
|
||||||
cmd = function() enter_resizing_mode() end
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
local window_shifting_keymaps = {
|
local window_shifting_keymaps = {
|
||||||
n = {
|
{ "<C-S-Left>", function() swap_window("h") end },
|
||||||
["<C-S-Left>"] = {
|
{ "<C-S-Down>", function() swap_window("j") end },
|
||||||
cmd = function()
|
{ "<C-S-Up>", function() swap_window("k") end },
|
||||||
swap_window("h")
|
{ "<C-S-Right>", function() swap_window("l") end },
|
||||||
end
|
|
||||||
},
|
|
||||||
["<C-S-Down>"] = {
|
|
||||||
cmd = function()
|
|
||||||
swap_window("j")
|
|
||||||
end
|
|
||||||
},
|
|
||||||
["<C-S-Up>"] = {
|
|
||||||
cmd = function()
|
|
||||||
swap_window("k")
|
|
||||||
end
|
|
||||||
},
|
|
||||||
["<C-S-Right>"] = {
|
|
||||||
cmd = function()
|
|
||||||
swap_window("l")
|
|
||||||
end
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.add_keymaps({
|
utils.set_keymap_list(window_shifting_keymaps)
|
||||||
window_shifting_keymaps,
|
utils.set_keymap_list(enter_resizing_mode_keymaps)
|
||||||
enter_resizing_mode_keymaps
|
|
||||||
})
|
|
||||||
|
|
||||||
local function on_resize_mode_enter()
|
local function on_resize_mode_enter()
|
||||||
utils.remove_keymaps(enter_resizing_mode_keymaps)
|
M.del_keymap_list(enter_resizing_mode_keymaps)
|
||||||
utils.add_keymaps(resizing_mode_keymaps)
|
M.set_keymap_list(resizing_mode_keymaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_resize_mode_exit()
|
local function on_resize_mode_exit()
|
||||||
utils.remove_keymaps(resizing_mode_keymaps)
|
M.del_keymap_list(resizing_mode_keymaps)
|
||||||
utils.add_keymaps(enter_resizing_mode_keymaps)
|
M.set_keymap_list(enter_resizing_mode_keymaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
local window_management_augroup = "WindowManagementEvents"
|
local window_management_augroup = "WindowManagementEvents"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue