Compare commits

47 Commits

Author SHA1 Message Date
baddfeecf0 chore: bump plugins 2025-12-15 09:56:14 +01:00
7a71256f95 chore: bump plugins 2025-12-08 19:15:16 +01:00
4b43236756 chore: bump plugins 2025-12-01 20:45:47 +01:00
5c952912c9 chore: bump plugins 2025-11-24 16:01:43 +01:00
7f9ce1be31 feat: replace nvim-mini/mini.notify with j-hui/fidget.nvim 2025-11-19 11:45:03 -03:00
bcc26b4728 chore: bump plugins 2025-11-19 11:37:08 -03:00
c7be652d62 chore: bump plugins 2025-11-10 13:46:34 +01:00
e801fd9864 chore: bump plugins 2025-11-03 16:51:42 +01:00
2228e08a7d chore: use mini.deps depends instead of multi add 2025-10-29 11:17:27 +01:00
e52cd237a3 feat: add count of dependencies and updating from stdpath("config") 2025-10-28 08:55:41 +01:00
886b010ce9 chore: run formatter 2025-10-27 18:25:46 +01:00
a8fca163a5 chore: bump plugins 2025-10-27 10:23:16 +01:00
df31db15d9 feat: add helptags and jumps fzf keymaps 2025-10-25 14:03:18 +02:00
ceca94e5db feat: replace nvim-mini/mini.pairs with windwp/nvim-autopairs 2025-10-22 00:42:15 +02:00
7ed9fb4e40 chore: bump plugins 2025-10-20 16:23:43 +02:00
f34ddbac36 chore: update to client:supports_method 2025-10-18 03:31:43 +02:00
b3495ef161 feat: close pumenu on copilot-suggest 2025-10-18 03:27:46 +02:00
e7aaee0dd6 feat: add nvim-mini/mini.cursorword 2025-10-18 02:57:20 +02:00
513f2e3e20 feat: use vim.tbl_contains api where possible 2025-10-18 02:56:49 +02:00
ad93476190 chore: add year to LICENSE 2025-10-18 02:44:59 +02:00
620dd92101 feat: add DepsClean to mini.starter 2025-10-18 02:43:51 +02:00
0904b788b1 feat: replace f-person/git-blame.nvim with lewis6991/gitsigns.nvim 2025-10-18 02:42:56 +02:00
cdf15743c3 feat: disable mini.indentscope for fzf and term 2025-10-17 16:52:38 +02:00
29eb480ac0 feat: enable vim.g.gruvbox_material_diagnostic_text_highlight 2025-10-17 16:51:24 +02:00
3148fa47c2 feat: add semantic highlighting via lsp.textDocument_documentHighlight 2025-10-16 14:36:13 +02:00
67b668bf60 feat: enable virtual_text for diagnostic and add swap_diagnostic keymap 2025-10-14 00:12:05 +02:00
e3394bb65c chore: bump plugins 2025-10-13 12:41:19 +02:00
4b1128f820 fix: setup ocs52 copy for * register 2025-10-13 00:12:44 +02:00
a6285798bf feat: add debug section to mini.starter 2025-10-11 22:29:04 +02:00
c3ae8bbe1e feat: add custom mini.starter sections 2025-10-11 21:26:21 +02:00
6dfaad2127 chore: bump plugins 2025-10-11 21:26:03 +02:00
300cd3b567 feat: add github/copilot.vim 2025-10-11 20:39:27 +02:00
d076dcf093 fix: create new terminal if old isn't valid anymore 2025-10-11 20:35:04 +02:00
5149c12b9a feat: add docker_language_server 2025-10-11 18:55:13 +02:00
1917c81067 feat: add nil_ls and nixd language servers 2025-10-11 18:54:34 +02:00
7b7df6a343 feat: add simple script for managing terminals 2025-10-11 18:53:22 +02:00
f36177b126 feat: add system clipboard copy via osc52 codes 2025-10-11 18:51:17 +02:00
b03e50f630 chore: update mini.deps lockfile 2025-10-08 01:45:20 +02:00
53e4801eeb feat: mini.starter remove - from query_updaters 2025-10-08 01:44:38 +02:00
7b270234fa feat: add folke/todo-comments.nvim 2025-10-08 01:41:01 +02:00
9c12937992 feat: git_blame disabled on start 2025-10-08 01:40:35 +02:00
a70a379170 feat: add yank highlight 2025-10-08 01:37:46 +02:00
9685200278 feat: add qf and visual move keybinds 2025-10-08 01:37:15 +02:00
279be9ce33 feat: add after/ftplugin for lua, python, rust 2025-10-08 01:37:02 +02:00
62699be903 chore: don't reasign MiniDeps.* in plugin definitions 2025-10-08 01:24:49 +02:00
a9488e8751 feat: add nvim-mini/mini.starter 2025-10-08 01:20:56 +02:00
6417e12234 feat: remove broken DepsUpdateSnapSave 2025-10-08 00:59:09 +02:00
27 changed files with 335 additions and 87 deletions

View File

@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) Matej Janežič Copyright (c) 2025 Matej Janežič
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

5
after/ftplugin/lua.lua Normal file
View File

@@ -0,0 +1,5 @@
vim.keymap.set("n", "<leader><leader>x", "<cmd>source %<CR>")
vim.keymap.set("n", "<leader>x", ":.lua<CR>")
vim.keymap.set("v", "<leader>x", ":lua<CR>")
vim.opt_local.colorcolumn = { 81 }

View File

@@ -0,0 +1 @@
vim.opt_local.colorcolumn = { 80, 81, 89 }

1
after/ftplugin/rust.lua Normal file
View File

@@ -0,0 +1 @@
vim.opt_local.colorcolumn = { 80, 100 }

View File

@@ -0,0 +1,7 @@
return {
settings = {
initializationOptions = {
telemetry = "off",
},
},
}

View File

@@ -5,6 +5,12 @@ vim.keymap.set("n", "N", "Nzz", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float) vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float)
vim.keymap.set("n", "<M-j>", "<cmd>cnext<CR>")
vim.keymap.set("n", "<M-k>", "<cmd>cprev<CR>")
vim.keymap.set("v", "<M-k>", ":m '<-2<cr>gv=gv")
vim.keymap.set("v", "<M-j>", ":m '>+1<cr>gv=gv")
vim.keymap.set( vim.keymap.set(
"t", "t",
"<C-x>", "<C-x>",

View File

@@ -13,6 +13,9 @@ vim.o.mouse = ""
vim.o.mousescroll = "ver:0,hor:0" vim.o.mousescroll = "ver:0,hor:0"
vim.o.writebackup = false vim.o.writebackup = false
vim.o.undofile = true vim.o.undofile = true
vim.o.updatetime = 250
vim.o.timeout = true
vim.o.timeoutlen = 300
-- ui -- ui
vim.o.breakindent = true vim.o.breakindent = true
@@ -32,7 +35,39 @@ vim.o.expandtab = true
vim.o.ignorecase = true vim.o.ignorecase = true
vim.o.smartcase = true vim.o.smartcase = true
-- diagnostic show virtual text
vim.diagnostic.config({ virtual_text = true })
local function swap_diagnostic()
local virtext = vim.diagnostic.config().virtual_text
local virlines = vim.diagnostic.config().virtual_lines
vim.diagnostic.config({ virtual_text = not virtext, virtual_lines = not virlines })
end
vim.keymap.set("n", "<leader>dt", swap_diagnostic)
-- osc52 escape codes copy
local function ocs52_paste_fail()
vim.notify("can't paste via osc52", vim.log.levels.WARN)
return {}
end
vim.g.clipboard = {
name = "osc52-writeonly",
copy = {
["+"] = require("vim.ui.clipboard.osc52").copy("+"),
["*"] = require("vim.ui.clipboard.osc52").copy("*"),
},
paste = {
["+"] = ocs52_paste_fail,
["*"] = ocs52_paste_fail,
},
}
vim.o.completeopt = "menuone,noselect,fuzzy,nosort" vim.o.completeopt = "menuone,noselect,fuzzy,nosort"
-- default plus added dash -- default plus added dash
vim.o.iskeyword = "@,48-57,_,192-255,-" vim.o.iskeyword = "@,48-57,_,192-255,-"
vim.api.nvim_create_autocmd("TextYankPost", {
desc = "highlight when yanking text",
group = vim.api.nvim_create_augroup("CustomHighlightYank", { clear = true }),
callback = function() vim.highlight.on_yank() end,
})

View File

@@ -17,26 +17,6 @@ end
-- set up 'mini.deps' immediately to have its `now()` and `later()` helpers -- set up 'mini.deps' immediately to have its `now()` and `later()` helpers
require("mini.deps").setup() require("mini.deps").setup()
-- also setup this user command to always save a new lockfile after update
vim.api.nvim_create_user_command("DepsUpdateSnapSave", function(opts)
local name = opts.args ~= "" and opts.args or nil
MiniDeps.update(name)
MiniDeps.snap_save()
end, {
desc = "Update MiniDeps plugins and save snapshot",
nargs = "?",
complete = function(arg, _, _)
local session_names = vim.tbl_map(
function(s) return s.name end,
MiniDeps.get_session()
)
return vim.tbl_filter(
function(n) return vim.startswith(n, arg) end,
session_names
)
end,
})
-- define main config table to be able to use it in scripts -- define main config table to be able to use it in scripts
_G.Config = {} _G.Config = {}

View File

@@ -1,12 +1,11 @@
add, now, later = MiniDeps.add, MiniDeps.now, MiniDeps.later MiniDeps.now(function()
MiniDeps.add("sainnhe/gruvbox-material")
now(function()
add("sainnhe/gruvbox-material")
vim.o.background = "dark" vim.o.background = "dark"
vim.g.gruvbox_material_background = "light" vim.g.gruvbox_material_background = "light"
vim.g.gruvbox_material_better_performance = 1 vim.g.gruvbox_material_better_performance = 1
vim.g.gruvbox_material_diagnostic_line_highlight = 1 vim.g.gruvbox_material_diagnostic_line_highlight = 1
vim.g.gruvbox_material_diagnostic_text_highlight = 1
vim.g.gruvbox_material_diagnostic_virtual_text = "colored" vim.g.gruvbox_material_diagnostic_virtual_text = "colored"
vim.g.gruvbox_material_enable_bold = 1 vim.g.gruvbox_material_enable_bold = 1
vim.g.gruvbox_material_enable_italic = 1 vim.g.gruvbox_material_enable_italic = 1

29
lua/plugins/copilot.lua Normal file
View File

@@ -0,0 +1,29 @@
local now_if_args = vim.fn.argc(-1) > 0 and MiniDeps.now or MiniDeps.later
now_if_args(function()
MiniDeps.add("github/copilot.vim")
vim.g.copilot_filetypes = {
-- disable all and only allow specific filetyps
["*"] = false,
--
c = true,
cpp = true,
dockerfile = true,
go = true,
javascript = true,
lua = true,
nix = true,
python = true,
rust = true,
sh = true,
typescript = true,
}
-- remap default <M-\> to first close pumenu if open
local function suggest()
if vim.fn.pumvisible() == 1 then vim.fn.complete(vim.fn.col("."), {}) end
return vim.fn["copilot#Suggest"]()
end
vim.keymap.set("i", "<M-\\>", suggest)
end)

11
lua/plugins/fidget.lua Normal file
View File

@@ -0,0 +1,11 @@
MiniDeps.now(function()
MiniDeps.add("j-hui/fidget.nvim")
local opts = {
notification = {
override_vim_notify = true,
},
}
require("fidget").setup(opts)
end)

View File

@@ -1,10 +1,8 @@
add, now, later = MiniDeps.add, MiniDeps.now, MiniDeps.later MiniDeps.later(function()
MiniDeps.add("ibhagwan/fzf-lua")
later(function() local fzf_lua = require("fzf-lua")
add("ibhagwan/fzf-lua") fzf_lua.setup({
local fzf = require("fzf-lua")
fzf.setup({
files = { files = {
no_ignore = true, no_ignore = true,
toggle_ignore_flag = "--no-ignore-vcs", toggle_ignore_flag = "--no-ignore-vcs",
@@ -15,11 +13,12 @@ later(function()
}, },
}) })
vim.keymap.set("n", "<leader>sf", fzf.files) vim.keymap.set("n", "<leader>sf", fzf_lua.files)
vim.keymap.set("n", "<leader>sg", fzf.live_grep) vim.keymap.set("n", "<leader>sg", fzf_lua.live_grep)
vim.keymap.set("n", "<leader>sw", fzf.grep_cword) vim.keymap.set("n", "<leader>sw", fzf_lua.grep_cword)
vim.keymap.set("v", "<leader>sg", fzf.grep_visual) vim.keymap.set("v", "<leader>sg", fzf_lua.grep_visual)
vim.keymap.set("n", "<leader>sj", fzf_lua.jumps)
vim.keymap.set("n", "<leader>sr", fzf.resume) vim.keymap.set("n", "<leader>sh", fzf_lua.helptags)
vim.keymap.set("n", "<leader>sb", fzf.builtin) vim.keymap.set("n", "<leader>sr", fzf_lua.resume)
vim.keymap.set("n", "<leader>sb", fzf_lua.builtin)
end) end)

View File

@@ -1,11 +0,0 @@
MiniDeps.later(function()
MiniDeps.add("f-person/git-blame.nvim")
require("gitblame").setup({
enabled = true,
message_template = " <sha>: <author> <date> <summary>",
date_format = "%Y-%m-%d",
})
vim.keymap.set("n", "<leader>gt", ":GitBlameToggle<CR>")
vim.keymap.set("n", "<leader>gs", ":GitBlameCopySHA<CR>")
end)

View File

@@ -1,6 +1,8 @@
MiniDeps.later(function() MiniDeps.later(function()
MiniDeps.add("nvim-lua/plenary.nvim") MiniDeps.add({
MiniDeps.add("ruifm/gitlinker.nvim") source = "ruifm/gitlinker.nvim",
depends = { "nvim-lua/plenary.nvim" },
})
require("gitlinker").setup({ require("gitlinker").setup({
callbacks = { callbacks = {
["git.aflabs.org"] = require("gitlinker.hosts").get_gitlab_type_url, ["git.aflabs.org"] = require("gitlinker.hosts").get_gitlab_type_url,

View File

@@ -9,4 +9,12 @@ MiniDeps.later(function()
changedelete = { text = "~" }, changedelete = { text = "~" },
}, },
}) })
-- blame
vim.keymap.set({ "n", "v" }, "<leader>gb", ":Gitsigns blame<CR>")
vim.keymap.set({ "n", "v" }, "<leader>gt", ":Gitsigns blame_line<CR>")
-- hunks
vim.keymap.set({ "n", "v" }, "<leader>ga", ":Gitsigns stage_hunk<CR>")
vim.keymap.set({ "n", "v" }, "<leader>gr", ":Gitsigns reset_hunk<CR>")
end) end)

View File

@@ -1,7 +1,5 @@
add, now, later = MiniDeps.add, MiniDeps.now, MiniDeps.later MiniDeps.later(function()
MiniDeps.add("neovim/nvim-lspconfig")
later(function()
add("neovim/nvim-lspconfig")
vim.lsp.enable({ vim.lsp.enable({
"pyright", "pyright",
@@ -12,6 +10,9 @@ later(function()
"ruff", "ruff",
"stylua", "stylua",
"lua_ls", "lua_ls",
"nixd",
"nil_ls",
"docker_language_server",
}) })
vim.api.nvim_create_autocmd("LspAttach", { vim.api.nvim_create_autocmd("LspAttach", {
@@ -57,6 +58,36 @@ later(function()
"format" "format"
) )
local tD_dH = vim.lsp.protocol.Methods.textDocument_documentHighlight
if client and client:supports_method(tD_dH) then
local ag = vim.api.nvim_create_augroup
local ac = vim.api.nvim_create_autocmd
local g = ag("custom-lsp-tD_dH-highlight", { clear = false })
ac({ "CursorHold", "CursorHoldI" }, {
buffer = bufnr,
group = g,
callback = vim.lsp.buf.document_highlight,
})
ac({ "CursorMoved", "CursorMovedI" }, {
buffer = bufnr,
group = g,
callback = vim.lsp.buf.clear_references,
})
ac("LspDetach", {
group = ag("custom-lsp-detach", { clear = true }),
callback = function(e)
vim.lsp.buf.clear_references()
vim.api.nvim_clear_autocmds({
group = "custom-lsp-tD_dH-highlight",
buffer = e.buf,
})
end,
})
end
-- inlay hints -- inlay hints
if client and client.server_capabilities.inlayHintProvider then if client and client.server_capabilities.inlayHintProvider then
vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })

View File

@@ -0,0 +1,12 @@
MiniDeps.later(function()
require("mini.cursorword").setup()
local function disable(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
local tD_dH = vim.lsp.protocol.Methods.textDocument_documentHighlight
if client and not client:supports_method(tD_dH) then return end
vim.b[args.buf].minicursorword_disable = true
end
vim.api.nvim_create_autocmd("LspAttach", { callback = disable })
end)

View File

@@ -1,10 +1,24 @@
MiniDeps.later( MiniDeps.later(function()
function() require("mini.indentscope").setup({
require("mini.indentscope").setup({ draw = {
draw = { delay = 0,
delay = 0, animation = require("mini.indentscope").gen_animation.none(),
animation = require("mini.indentscope").gen_animation.none(), },
}, })
})
local disable = {
"fzf",
"fzflua_backdrop",
"qf",
}
local function term_disable(args) vim.b[args.buf].miniindentscope_disable = true end
local function ft_disable(args)
local ft = vim.bo[args.buf].filetype
if not vim.tbl_contains(disable, ft) then return end
vim.b[args.buf].miniindentscope_disable = true
end end
)
vim.api.nvim_create_autocmd("TermOpen", { callback = term_disable })
vim.api.nvim_create_autocmd("Filetype", { callback = ft_disable })
end)

View File

@@ -1,6 +0,0 @@
add, now, later = MiniDeps.add, MiniDeps.now, MiniDeps.later
now(function()
require("mini.notify").setup()
vim.notify = MiniNotify.make_notify()
end)

View File

@@ -1 +0,0 @@
MiniDeps.later(function() require("mini.pairs").setup() end)

View File

@@ -0,0 +1,71 @@
local function default_header()
local hour = tonumber(vim.fn.strftime("%H"))
local part_id = math.floor((hour + 4) / 8) + 1
local day_part = ({ "evening", "morning", "afternoon", "evening" })[part_id]
local username = vim.loop.os_get_passwd()["username"] or "USERNAME"
return ("good %s, %s"):format(day_part, username)
end
local function reinstall_treesitter()
local ts = require("nvim-treesitter")
ts.install(ts.get_installed(), { force = true })
end
local function deps_section()
local mini_deps = require("mini.deps")
local nr_deps = #vim.iter(mini_deps):enumerate():totable()
local items = {
{
name = "number of dependencies " .. nr_deps,
action = "",
section = "dependencies",
},
}
local function mk_dep_item(name, action)
return { name = name, action = action, section = "dependencies" }
end
local deps_actions = {
mk_dep_item("update dependencies", "DepsUpdate"),
mk_dep_item("snap dependencies", "DepsSnapSave"),
mk_dep_item("load dependencies", "DepsSnapLoad"),
mk_dep_item("clean dependencies", "DepsClean"),
}
if vim.fn.getcwd() == vim.fn.stdpath("config") then
for _, item in ipairs(deps_actions) do
table.insert(items, item)
end
end
return items
end
MiniDeps.now(function()
local builtins = {
{ name = "edit new buffer", action = "enew", section = "builtin actions" },
{ name = "quit neovim", action = "qall", section = "builtin actions" },
}
require("mini.starter").setup({
query_updaters = "abcdefghijklmnopqrstuvwxyz0123456789_.",
evaluate_single = true,
header = default_header,
footer = "",
items = {
-- builtins
builtins,
-- dependencies
deps_section,
-- debug
{
name = "reinstall treesitter parsers",
action = reinstall_treesitter,
section = "debug",
},
},
})
end)

View File

@@ -0,0 +1,4 @@
MiniDeps.later(function()
MiniDeps.add("windwp/nvim-autopairs")
require("nvim-autopairs").setup()
end)

View File

@@ -1,7 +1,5 @@
add, now, later = MiniDeps.add, MiniDeps.now, MiniDeps.later MiniDeps.later(function()
MiniDeps.add("stevearc/oil.nvim")
later(function()
add("stevearc/oil.nvim")
require("oil").setup({ view_options = { show_hidden = true } }) require("oil").setup({ view_options = { show_hidden = true } })
vim.keymap.set("n", "-", require("oil").open, { desc = "Open parent directory" }) vim.keymap.set("n", "-", require("oil").open, { desc = "Open parent directory" })
end) end)

View File

@@ -0,0 +1,7 @@
MiniDeps.now(function()
MiniDeps.add({
source = "folke/todo-comments.nvim",
depends = { "nvim-lua/plenary.nvim" },
})
require("todo-comments").setup()
end)

View File

@@ -1,8 +1,7 @@
local add, now, later = MiniDeps.add, MiniDeps.now, MiniDeps.later local now_if_args = vim.fn.argc(-1) > 0 and MiniDeps.now or MiniDeps.later
local now_if_args = vim.fn.argc(-1) > 0 and now or later
now_if_args(function() now_if_args(function()
add({ MiniDeps.add({
source = "nvim-treesitter/nvim-treesitter", source = "nvim-treesitter/nvim-treesitter",
checkout = "main", checkout = "main",
hooks = { post_checkout = function() vim.cmd("TSUpdate") end }, hooks = { post_checkout = function() vim.cmd("TSUpdate") end },

View File

@@ -1,14 +1,17 @@
return { return {
["fzf-lua"] = "c0c0926eee09f2e7868e5b72cb66decc0cb13aca", ["copilot.vim"] = "f89e977c87180519ba3b942200e3d05b17b1e2fc",
["git-blame.nvim"] = "9874ec1ec8bc53beb33b7cd82c092b85271a578b", ["fidget.nvim"] = "e32b672d8fd343f9d6a76944fedb8c61d7d8111a",
["fzf-lua"] = "e9c8828f216e419d3b7fa1292d18378b14368492",
["gitlinker.nvim"] = "cc59f732f3d043b626c8702cb725c82e54d35c25", ["gitlinker.nvim"] = "cc59f732f3d043b626c8702cb725c82e54d35c25",
["gitsigns.nvim"] = "1ee5c1fd068c81f9dd06483e639c2aa4587dc197", ["gitsigns.nvim"] = "5813e4878748805f1518cee7abb50fd7205a3a48",
["gruvbox-material"] = "834dbf21836862300ced7444db4262b796330ab7", ["gruvbox-material"] = "cc47341018320a2c82262958a1af889e5eeacd6e",
["guess-indent.nvim"] = "84a4987ff36798c2fc1169cbaff67960aed9776f", ["guess-indent.nvim"] = "84a4987ff36798c2fc1169cbaff67960aed9776f",
["mini.nvim"] = "fbb6ad02871d296fc7d3ebd453e1be89b1210f68", ["mini.nvim"] = "6bd3a01aaf7d248aea1b78aacdd5d44bffa002c1",
["nvim-lspconfig"] = "e688b486fe9291f151eae7e5c0b5a5c4ef980847", ["nvim-autopairs"] = "d9e44e54384e5b0f3536339c65484f2e41b528e3",
["nvim-treesitter"] = "3ab4f2d2d20be55874e2eb575145c6928d7d7d0e", ["nvim-lspconfig"] = "f3979663c9c8cd9ad258344b9cfb5ad83cff61c1",
["oil.nvim"] = "919e155fdf38e9148cdb5304faaaf53c20d703ea", ["nvim-treesitter"] = "d3218d988f72ed34414959c9ccd802d393432d6e",
["oil.nvim"] = "cbcb3f997f6f261c577b943ec94e4ef55108dd95",
["plenary.nvim"] = "b9fd5226c2f76c951fc8ed5923d85e4de065e509", ["plenary.nvim"] = "b9fd5226c2f76c951fc8ed5923d85e4de065e509",
["rainbow-delimiters.nvim"] = "3277ad5f96eb03c9d618c88e24f683e4364e578c" ["rainbow-delimiters.nvim"] = "8aafe2cbd89cd4090f573a98cab6b20366576fde",
["todo-comments.nvim"] = "31e3c38ce9b29781e4422fc0322eb0a21f4e8668"
} }

44
plugin/geterm.lua Normal file
View File

@@ -0,0 +1,44 @@
---@class TermBuf
---@field buf_id integer
---@field term_id integer
---@type table<number, TermBuf>
local state = {}
---@param n integer
local function get_from_state(n)
local term_buf = state[n]
if term_buf ~= nil and vim.api.nvim_buf_is_valid(term_buf.buf_id) then
return term_buf
end
state[n] = nil
return nil
end
---@param n integer
local function get_or_create_term(n)
if get_from_state(n) ~= nil then
vim.api.nvim_win_set_buf(0, state[n].buf_id)
return
end
vim.cmd.terminal()
local buf_id = vim.api.nvim_get_current_buf()
local term_id = vim.b.terminal_job_id
vim.cmd.startinsert()
state[n] = { buf_id = buf_id, term_id = term_id }
end
---@param f function
local function count_fn(f)
local function wrap(...)
local count = vim.v.count
return f(count, arg)
end
return wrap
end
vim.keymap.set("n", "<leader>tn", count_fn(get_or_create_term))