initial commit for native-only neovim plugin configuration

This commit is contained in:
2026-06-24 03:14:04 +02:00
parent 6d7373aab4
commit 5929cd53d7
19 changed files with 266 additions and 898 deletions
+56 -37
View File
@@ -1,5 +1,6 @@
--[[
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣷⣦⣄⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄⡀
@@ -25,30 +26,33 @@
| _/ /_____\__ \ || (_| | (__| <
|_|/___| |___/\__\__,_|\___|_|\_\
Neovim 0.12 configuration
(c) Frank Zechert 2026
Neovim v0.12 configuration
(C) Frank Zechert 2026
]]
local create_group = vim.api.nvim_create_augroup
local create_cmd = vim.api.nvim_create_autocmd
local function contains(tbl, value)
for _, v in ipairs(tbl) do
if v == value then
return true
end
end
return false
end
-- briefly highlithg text that is yanked
-- briefly highlight text that is yanked
create_cmd("TextYankPost", {
desc = "Highlight yanked text",
group = create_group("cmd-highlight-yank", { clear = true }),
callback = function()
vim.highlight.on_yank()
end,
end
})
-- recognize all scripts with bash shebang as bash filetype
-- disable list chars in specific file types, e.g. netrw
create_cmd("FileType", {
desc = "Disable list characters for some filetypes",
group = create_group("cmd-disable-listchars", { clear = true }),
pattern = { "netrw" },
callback = function(args)
vim.opt_local.list = false
end
})
-- when recognizing a bash shebang, switch filetype to bash
create_cmd({"BufRead", "BufNewFile"}, {
desc = "Recognize bash shebang as bash filetype",
group = create_group("cmd-recognize-bash-filetype", { clear = true }),
@@ -59,38 +63,53 @@ create_cmd({"BufRead", "BufNewFile"}, {
if first_line:match("^#!.*/bash") then
vim.bo[buf].filetype = "bash"
end
end,
end
})
-- disable list chars in specific filetypes, e.g. netrw
create_cmd({"FileType"}, {
desc = "Disable list chars for some filetypes",
pattern = { "netrw" },
callback = function(args)
vim.opt_local.list = false
end,
})
-- automatically remove trailing whitespace on save file
create_cmd({"BufWritePre"}, {
desc = "Remove trailing whitespace when saving",
-- when saving a file, remove trailing whitespace
create_cmd("BufWritePre", {
desc = "Remove trailing whitespace before saving a file",
group = create_group("cmd-remove-trailing-whitespace", { clear = true }),
pattern = "*",
callback = function(args)
vim.api.nvim_buf_call(args.buf, function()
vim.cmd([[%s/\s\+$//e]])
local cursor = vim.api.nvim_win_get_cursor(0)
vim.cmd([[keepjumps keeppatterns silent! %s/\s\+$//e]])
vim.api.nvim_win_set_cursor(0, cursor)
end)
end,
end
})
-- automatically set textwidth if not set otherwise
create_cmd({"FileType"}, {
desc = "Automatically set textwidth",
pattern = "*",
callback = function(args)
local buf = args.buf
if vim.bo[buf].textwidth == 0 then
vim.bo[buf].textwidth = vim.g.ui.textwidth[vim.bo[buf].filetype] or vim.g.ui.textwidth.default
-- highlight trailing whitespace when in normal mode
local trailing_hl_group = create_group("cmd-highlight-trailing-whitespace", { clear = true })
local trailing_hl_match_ids = {}
-- Remove highlight in all non-normal modes
create_cmd({"InsertEnter", "CmdlineEnter", "TermEnter" }, {
desc = "Remove trailing whitespace highlight in non-normal mode",
group = trailing_hl_group,
callback = function()
local window = vim.api.nvim_get_current_win()
local id = trailing_hl_match_ids[window]
if id then
pcall(vim.fn.matchdelete, id)
trailing_hl_match_ids[window] = nil
end
end,
end
})
-- Apply highlight in normal mode
create_cmd({"InsertLeave", "CmdlineLeave", "TermLeave", "BufEnter", "WinEnter" }, {
desc = "Add trailing whitespace highlight in normal mode",
group = trailing_hl_group,
callback = function()
if vim.fn.mode() ~= "n" then
return
end
local window = vim.api.nvim_get_current_win()
local id = trailing_hl_match_ids[window]
if id then
pcall(vim.fn.matchdelete, id)
end
trailing_hl_match_ids[window] = vim.fn.matchadd("TrailingWhitespace", [[\s\+$]])
end
})