module resyntaxing

This commit is contained in:
cnst
2024-08-31 20:24:08 +02:00
parent b721c5cc25
commit 1beecf1d99
34 changed files with 1567 additions and 438 deletions

View File

@@ -0,0 +1,61 @@
-- Faster completion
vim.opt.updatetime = 100
-- Line numbers
vim.opt.relativenumber = false -- Relative line numbers
vim.opt.number = true -- Display the absolute line number of the current line
-- Buffer and window options
vim.opt.hidden = true -- Keep closed buffer open in the background
vim.opt.showmode = false -- Do not show the mode in the command line
vim.opt.mouse = "a" -- Enable mouse control
vim.opt.mousemodel = "popup" -- Mouse right-click extends the current selection
vim.opt.splitbelow = true -- A new window is put below the current one
vim.opt.splitright = true -- A new window is put right of the current one
-- List options
vim.opt.list = true
vim.opt.listchars = {
tab = "",
trail = "·",
nbsp = "",
extends = "",
precedes = "",
}
-- Swap and undo files
vim.opt.swapfile = false -- Disable the swap file
vim.opt.modeline = true -- Tags such as 'vim:ft=sh'
vim.opt.modelines = 100 -- Sets the type of modelines
vim.opt.undofile = true -- Automatically save and restore undo history
-- Search options
vim.opt.incsearch = true -- Incremental search: show match for partly typed search command
vim.opt.inccommand = "split" -- Search and replace: preview changes in quickfix list
vim.opt.ignorecase = true -- When the search query is lower-case, match both lower and upper-case patterns
vim.opt.smartcase = true -- Override the 'ignorecase' option if the search pattern contains upper case characters
-- Scrolling and cursor options
vim.opt.scrolloff = 4 -- Number of screen lines to show around the cursor
vim.opt.cursorline = true -- Highlight the screen line of the cursor
vim.opt.cursorcolumn = false -- Highlight the screen column of the cursor
vim.opt.signcolumn = "yes" -- Whether to show the signcolumn
-- Display options
vim.opt.colorcolumn = "" -- Columns to highlight
vim.opt.laststatus = 3 -- When to use a status line for the last window
vim.opt.fileencoding = "utf-8" -- File-content encoding for the current buffer
vim.opt.spell = false -- Highlight spelling mistakes (local to window)
vim.opt.wrap = false -- Prevent text from wrapping
-- Tab options
vim.opt.tabstop = 4 -- Number of spaces a <Tab> in the text stands for (local to buffer)
vim.opt.shiftwidth = 4 -- Number of spaces used for each step of (auto)indent (local to buffer)
vim.opt.expandtab = true -- Expand <Tab> to spaces in Insert mode (local to buffer)
vim.opt.autoindent = true -- Do clever autoindenting
-- Text width
vim.opt.textwidth = 0 -- Maximum width of text that is being inserted
-- Folding
vim.opt.foldlevel = 99 -- Folds with a level higher than this number will be closed

View File

@@ -0,0 +1,39 @@
local lspc = require'lspconfig'
-- Setup for LSP servers
lspc.tsserver.setup({
on_attach = function(client, bufnr)
client.resolved_capabilities.document_formatting = false
client.resolved_capabilities.document_range_formatting = false
local ts_utils = require("nvim-lsp-ts-utils")
ts_utils.setup({})
ts_utils.setup_client(client)
local buf_map = function(bufnr, mode, lhs, rhs, opts)
vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, opts or { silent = true })
end
buf_map(bufnr, "n", "gs", ":TSLspOrganize<CR>")
buf_map(bufnr, "n", "gi", ":TSLspRenameFile<CR>")
buf_map(bufnr, "n", "go", ":TSLspImportAll<CR>")
-- Custom on_attach functionality
on_attach(client, bufnr)
end,
})
lspc.cssls.setup{}
lspc.clangd.setup{}
lspc.tailwindcss.setup{}
lspc.html.setup{}
lspc.astro.setup{}
lspc.phpactor.setup{}
lspc.pyright.setup{}
lspc.marksman.setup{}
lspc.nixd.setup{}
lspc.dockerls.setup{}
lspc.bashls.setup{}
lspc.csharp_ls.setup{}
lspc.yamlls.setup{}
lspc.lua_ls.setup({
})

View File

@@ -0,0 +1,73 @@
local has_words_before = function()
local line, col = table.unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
local cmp = require("cmp")
local lspkind = require("lspkind")
cmp.setup({
sources = {
{ name = "nvim_lsp" },
{ name = "cmp_tabnine" },
{ name = "treesitter" },
{ name = "buffer" },
{ name = "path" },
{ name = "vsnip" },
-- { name = "copilot" },
},
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
formatting = {
format = lspkind.cmp_format({
with_text = true,
menu = {
buffer = "[Buf]",
nvim_lsp = "[LSP]",
nvim_lua = "[Lua]",
latex_symbols = "[Latex]",
treesitter = "[TS]",
cmp_tabnine = "[TN]",
vsnip = "[Snip]",
},
}),
},
mapping = {
["<CR>"] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, {
"i",
"s",
}),
},
})

View File

@@ -0,0 +1,20 @@
-- Set colorscheme
vim.cmd("set termguicolors")
-- Configure gruvbox-material
vim.g.gruvbox_material_background = "medium" -- Options: 'hard', 'medium', 'soft'
vim.g.gruvbox_material_palette = "material" -- Options: 'material', 'original', 'palenight'
-- Load the gruvbox-material colorscheme
vim.cmd([[colorscheme gruvbox-material]])
-- Enable colorizer
require("colorizer").setup()
-- set sign
vim.cmd("sign define DiagnosticSignError text= linehl= texthl=DiagnosticSignError numhl=")
vim.cmd("sign define DiagnosticSignHint text= linehl= texthl=DiagnosticSignHint numhl=")
vim.cmd("sign define DiagnosticSignInfo text= linehl= texthl=DiagnosticSignInfo numhl=")
vim.cmd("sign define DiagnosticSignWarn text= linehl= texthl=DiagnosticSignWarn numhl=")
-- set lightline theme to horizon
vim.g.lightline = { colorscheme = "apprentice" }

View File

@@ -0,0 +1,14 @@
require'nvim-treesitter.configs'.setup {
textobjects = {
select = {
enable = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
},
},
},
}

View File

@@ -0,0 +1,25 @@
require("nvim-treesitter.configs").setup({
highlight = {
enable = true,
disable = {},
},
rainbow = {
enable = true,
extended_mode = true,
},
autotag = {
enable = true,
},
context_commentstring = {
enable = true,
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
})

View File

@@ -0,0 +1,39 @@
-- telescope
require("telescope").load_extension("fzy_native")
-- null-ls
local nb = require("null-ls").builtins
require("null-ls").setup({
sources = {
nb.formatting.alejandra,
nb.code_actions.statix,
nb.diagnostics.cppcheck,
nb.diagnostics.deadnix,
nb.diagnostics.statix,
nb.diagnostics.eslint,
nb.completion.spell,
},
})
require("gitsigns").setup()
-- autopairs
require("nvim-autopairs").setup({})
-- copy to system clipboard
vim.api.nvim_set_keymap("v", "<Leader>y", '"+y', { noremap = true })
vim.api.nvim_set_keymap("n", "<Leader>y", ":%+y<CR>", { noremap = true })
-- paste from system clipboard
vim.api.nvim_set_keymap("n", "<Leader>p", '"+p', { noremap = true })
-- textyankpost autocmd
vim.api.nvim_create_augroup("highlight_yank", { clear = true })
vim.api.nvim_create_autocmd("TextYankPost", {
group = "highlight_yank",
desc = "Highlight when yanking (copying) text",
callback = function()
vim.highlight.on_yank()
end,
})

View File

@@ -0,0 +1,52 @@
-- Updated Which-Key Spec
local wk = require("which-key")
wk.setup {}
wk.register({
["<leader>"] = {
["/"] = { "<cmd>Telescope live_grep<cr>", "Live Grep" },
P = { '"+P', "Paste from clipboard before cursor" },
a = { "<cmd>lua require('telescope.builtin').lsp_code_actions()<cr>", "Code Actions" },
ac = { "<cmd>CopilotChatToggle<CR>", "Toggle Copilot chat" },
b = { "<cmd>Telescope buffers<cr>", "Buffers" },
d = { "<cmd>lua require('telescope.builtin').lsp_document_diagnostics()<cr>", "LSP Diagnostics" },
f = { "<cmd>Telescope find_files<cr>", "Find File" },
g = {
b = { "<cmd>ToggleBlameLine<cr>", "Toggle BlameLine" },
c = { "<cmd>Neogit commit<cr>", "Commit" },
i = { "<cmd>lua require('telescope').extensions.gh.issues()<cr>", "Github Issues" },
name = "Git / VCS",
p = { "<cmd>lua require('telescope').extensions.gh.pull_request()<cr>", "Github PRs" },
s = { "<cmd>Neogit kind=split<cr>", "Staging" }
},
k = { "<cmd>lua vim.lsp.buf.signature_help()<cr>", "Signature Help" },
l = {
e = { "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<cr>", "Show Line Diagnostics" },
f = { "<cmd>lua vim.lsp.buf.formatting_sync()<cr>", "Format file" },
name = "LSP",
q = { "<cmd>lua vim.lsp.diagnostic.set_loclist()<cr>", "Set Loclist" }
},
p = { '"+p', "Paste from clipboard" },
qc = { "<cmd>lua local input = vim.fn.input('Quick Chat: '); if input ~= '' then require('CopilotChat').ask(input, { selection = require('CopilotChat.select').buffer }) end<CR>", "CopilotChat - Quick chat" },
y = { '"+y', "Yank to clipboard" }
},
g = {
e = { "G", "Bottom" },
h = { "0", "Line start" },
l = { "$", "Line end" },
s = { "^", "First non-blank in line" }
},
i = {
["<C-v>"] = { "<esc>p", "Paste in Insert Mode" }
},
v = {
["<"] = { "<gv", "Indent Left" },
["<C-c>"] = { "y", "Yank Selection" },
["<S-TAB>"] = { "<gv", "Indent Left" },
["<TAB>"] = { ">gv", "Indent Right" },
[">"] = { ">gv", "Indent Right" },
J = { ":m '>+1<CR>gv=gv", "Move Down" },
K = { ":m '<-2<CR>gv=gv", "Move Up" }
}
}, { prefix = "" })

View File

@@ -0,0 +1,81 @@
{
pkgs,
lib,
config,
...
}: let
inherit (lib) mkIf mkEnableOption;
cfg = config.modules.devtools.neovim;
in {
options = {
modules.devtools.neovim.enable = mkEnableOption "Enables neovim";
};
config = mkIf cfg.enable {
programs.neovim = {
enable = true;
vimAlias = true;
viAlias = true;
vimdiffAlias = true;
plugins = with pkgs.vimPlugins; [
gruvbox-material-nvim
nvim-web-devicons
comment-nvim
cmp-buffer
cmp-nvim-lsp
cmp-path
cmp-spell
cmp-treesitter
cmp-vsnip
friendly-snippets
gitsigns-nvim
lightline-vim
lspkind-nvim
neogit
null-ls-nvim
nvim-autopairs
nvim-cmp
nvim-colorizer-lua
nvim-lspconfig
nvim-tree-lua
(nvim-treesitter.withPlugins (_: pkgs.tree-sitter.allGrammars))
plenary-nvim
rainbow-delimiters-nvim
telescope-fzy-native-nvim
telescope-nvim
vim-floaterm
vim-sneak
vim-vsnip
which-key-nvim
copilot-lua
copilot-cmp
statix
phpactor
];
extraPackages = with pkgs; [nixd gcc ripgrep fd deadnix lua-language-server yaml-language-server bash-language-server];
extraConfig = let
luaRequire = module:
builtins.readFile (builtins.toString
./config
+ "/${module}.lua");
luaConfig = builtins.concatStringsSep "\n" (map luaRequire [
"init"
"lspconfig"
"nvim-cmp"
"theming"
"treesitter"
"treesitter-textobjects"
"utils"
"which-key"
]);
in ''
lua << 
${luaConfig}

'';
};
};
}