bonfire/lib/preconfiguredModules/bonvim.nix

726 lines
16 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
rustc ? pkgs.rustc,
cargo ? pkgs.cargo,
rust-analyzer ? pkgs.rust-analyzer,
...
}: {
# General
globals.mapleader = " ";
opts = {
# Show line numbers
number = true;
relativenumber = true;
# Tab need 4 spaces please
expandtab = true;
tabstop = 4;
softtabstop = 4;
shiftwidth = 4;
showtabline = 4;
# Hide * markup
conceallevel = 2;
# Confirm on save
confirm = true;
cursorline = true;
# Invisible characters I see you
list = true;
ignorecase = true;
grepprg = "${lib.getExe pkgs.ripgrep} --vimgrep";
termguicolors = true;
# Splits
splitbelow = true;
splitright = true;
splitkeep = "screen";
# U, u, undo
undofile = true;
undolevels = 10000;
updatetime = 200;
# Command line completion mode
wildmode = "longest:full,full";
smoothscroll = true;
autowrite = true;
2024-07-24 11:39:18 +05:00
pumblend = 10;
pumheight = 10;
};
globals = {
bigfile_size = 1024 * 1024 * 1.5;
};
editorconfig.enable = true;
# Clipboard
clipboard = {
register = "unnamedplus";
providers.wl-copy.enable = true;
};
# Copy/paste
plugins.yanky = {
enable = true;
2024-07-24 11:39:18 +05:00
settings.system_clipboard.sync_with_ring = true;
};
extraPlugins = with pkgs.vimPlugins; [nvim-web-devicons];
2024-07-24 11:39:18 +05:00
diagnostics = {
underline = true;
update_in_insert = false;
# lsp diagnostics grouped in the end of file
virtual_text = {
spacing = 4;
source = "if_many";
prefix = "";
};
# lsp diagnostic lines disabled by default, toggle it for pretty lines
virtual_lines = false;
# sort diagnostic messages
severity_sort = true;
# hightlight word under cursor
document_highlight = {
enabled = true;
};
};
# Theme
colorschemes.catppuccin = {
enable = true;
settings = {
flavour = "macchiato";
no_bold = false;
no_italic = false;
no_underline = false;
integrations = {
cmp = true;
notify = true;
gitsigns = true;
neotree = true;
which_key = true;
illuminate = {
enabled = true;
};
treesitter = true;
telescope.enabled = true;
indent_blankline.enabled = true;
mini.enabled = true;
native_lsp = {
enabled = true;
inlay_hints = {
background = true;
};
underlines = {
2024-07-24 11:39:18 +05:00
errors = ["undercurl"];
hints = ["undercurl"];
information = ["undercurl"];
warnings = ["undercurl"];
};
};
};
};
};
# File tree
plugins.neo-tree = {
enable = true;
filesystem = {
useLibuvFileWatcher = true;
filteredItems = {
hideDotfiles = false;
hideGitignored = false;
};
};
defaultComponentConfigs = {
indent = {
withExpanders = true;
expanderCollapsed = "";
expanderExpanded = "";
expanderHighlight = "NeoTreeExpander";
};
};
};
# UI
plugins.noice = {
enable = true;
lsp.override = {
"cmp.entry.get_documentation" = true;
"vim.lsp.util.convert_input_to_markdown_lines" = true;
"vim.lsp.util.stylize_markdown" = true;
};
presets = {
long_message_to_split = true;
};
};
plugins.dressing = {
enable = true;
};
# Status line
plugins.bufferline = {
enable = true;
diagnostics = "nvim_lsp";
mode = "buffers";
offsets = [
{
filetype = "neo-tree";
text = "Neo-tree";
highlight = "Directory";
text_align = "left";
}
];
};
plugins.lualine = {
enable = true;
globalstatus = true;
extensions = ["neo-tree"];
sections = {
lualine_a = [
{
name = "mode";
separator.right = "";
}
];
lualine_b = [
{
name = "branch";
icon = "";
separator.right = "";
}
];
lualine_c = [
{
name = "diagnostics";
separator.right = ">";
extraConfig = {
sources = ["nvim_lsp"];
symbols = {
error = " ";
warn = " ";
info = " ";
hint = "󰝶 ";
};
};
}
{
name = "filetype";
extraConfig = {
icon_only = true;
separator = "";
padding = {
left = 1;
right = 0;
};
};
}
{
name = "filename";
extraConfig = {
path = 1;
};
}
];
lualine_x = [
{
name = "diff";
extraConfig = {
symbols = {
added = " ";
modified = " ";
removed = " ";
};
source.__raw = ''
function()
local gitsings = vim.b.gitsigns_status_dict
if gitsigns then
return {
added = gitigns.added,
modified = gitigns.changed,
removed = gitigns.removed
}
end
end
'';
};
}
];
lualine_y = [
{
separator.left = "";
name = "progress";
padding = {
left = 1;
right = 0;
};
}
{
name = "location";
padding = {
left = 0;
right = 1;
};
}
];
lualine_z = [
{
separator.left = "";
fmt = ''
function(text)
return " " .. os.date("%R")
end
'';
}
];
};
};
plugins.notify.enable = true;
plugins.project-nvim = {
enable = true;
enableTelescope = true;
showHidden = true;
};
# Syntax highlight
plugins.treesitter = {
enable = true;
};
plugins.treesitter-textobjects.enable = true;
# Double trouble of your code
plugins.trouble = {
enable = true;
};
# Multifile search/replace
plugins.spectre = {
enable = true;
findPackage = pkgs.ripgrep;
replacePackage = pkgs.gnused;
};
plugins.which-key = {
enable = true;
icons.group = "+";
registrations = {
"<leader>g" = "+ Git";
"<leader>c" = "+ Code";
"<leader>s" = "+ Search";
"<leader>w" = "+ Window";
"<leader>q" = "+ Quit";
};
};
# LSP
plugins = {
lsp-lines.enable = true;
lsp-format.enable = true;
lsp = {
enable = true;
inlayHints = true;
keymaps = {
# vim.diagnostic.<action>
diagnostic = {
"<leader>cd" = {
action = "open_float";
desc = "Line diagnostics";
};
};
# vim.lsp.buf.<action>
lspBuf = {
"K" = "hover";
"gK" = "signature_help";
"gr" = "references";
"gd" = "definition";
"gi" = "implementation";
"gt" = "type_definition";
"cr" = "rename";
"cf" = "format";
};
extra = [
{
key = "<leader>cf";
action.__raw = "vim.lsp.buf.format";
options.desc = "Format";
}
];
};
servers = {
clangd = {
enable = true;
cmd = [
"${config.plugins.lsp.servers.clangd.package}/bin/clangd"
"--background-index"
"--clang-tidy"
"--header-insertion=iwyu"
"--completion-style=detailed"
"--function-arg-placeholders"
"--fallback-style=llvm"
];
};
cmake.enable = true;
nil-ls.enable = true;
# pylyzer.enable = true; # not working with virtual environments currently :(
pylsp = {
2024-07-24 11:39:18 +05:00
enable = true; # https://github.com/nix-community/nixvim/pull/1893
settings.plugins = {
pyflakes.enabled = true;
black.enabled = true;
};
};
rust-analyzer = {
enable = true;
package = rust-analyzer;
cargoPackage = cargo;
rustcPackage = rustc;
installCargo = true;
installRustc = true;
2024-07-24 11:39:18 +05:00
settings = {
checkOnSave = true;
check.command = "clippy";
inlayHints = {
enable = true;
showParameterNames = true;
};
procMacro.enable = true;
};
};
volar.enable = true;
tailwindcss.enable = true;
marksman.enable = true;
};
};
};
# VCS
plugins.gitsigns = {
enable = true;
settings = {
signs = {
add = {
text = "";
};
change = {
text = "";
};
delete = {
text = "";
};
untracked = {
text = "";
};
topdelete = {
text = "";
};
changedelete = {
text = "";
};
};
};
};
plugins.lazygit.enable = true;
# Formatting
plugins.none-ls = {
enable = true;
# nix
sources.formatting.alejandra.enable = true;
};
# Search, search, search
plugins.telescope = {
enable = true;
extensions.fzf-native.enable = true;
keymaps = {
"<leader>sgf" = {
action = "git_files";
options = {
desc = "Files";
};
};
"<leader>sgc" = {
action = "git_commits";
options = {
desc = "Commits";
};
};
"<leader>sgs" = {
action = "git_status";
options = {
desc = "Status";
};
};
"<leader>sk" = {
action = "keymaps";
options = {
desc = "Key Maps";
};
};
"<leader>sf" = {
action = "live_grep";
options = {
desc = "Grep Root Directory";
};
};
};
};
plugins.todo-comments.enable = true;
# Terminal
plugins.toggleterm = {
enable = true;
settings = {
direction = "float";
open_mapping = "[[<c-/>]]";
};
};
# Completion
plugins = {
cmp = {
enable = true;
settings = {
sources = [
{
name = "nvim_lsp";
}
{
name = "path";
}
{
name = "buffer";
}
];
experimental = {
ghost_text = {
hl_group = "CmpGhostText";
};
};
mapping = {
"<c-space>" = "cmp.mapping.complete()";
"<cr>" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })";
"<tab>" = "cmp.mapping(cmp.mapping.confirm({ select = true }), { 'i', 's', 'c' })";
2024-07-24 11:39:18 +05:00
"<up>" = "cmp.mapping.select_prev_item()";
"<down>" = "cmp.mapping.select_next_item()";
};
2024-07-24 11:39:18 +05:00
formatting.format = ''
function(entry, item)
local icons = {
Array = " ",
Boolean = "󰨙 ",
Class = " ",
Codeium = "󰘦 ",
Color = " ",
Control = " ",
Collapsed = " ",
Constant = "󰏿 ",
Constructor = " ",
Copilot = " ",
Enum = " ",
EnumMember = " ",
Event = " ",
Field = " ",
File = " ",
Folder = " ",
Function = "󰊕 ",
Interface = " ",
Key = " ",
Keyword = " ",
Method = "󰊕 ",
Module = " ",
Namespace = "󰦮 ",
Null = " ",
Number = "󰎠 ",
Object = " ",
Operator = " ",
Package = " ",
Property = " ",
Reference = " ",
Snippet = " ",
String = " ",
Struct = "󰆼 ",
TabNine = "󰏚 ",
Text = " ",
TypeParameter = " ",
Unit = " ",
Value = " ",
Variable = "󰀫 ",
}
if icons[item.kind] then
item.kind = icons[item.kind] .. item.kind
end
local widths = {
abbr = vim.g.cmp_widths and vim.g.cmp_widths.abbr or 40,
menu = vim.g.cmp_widths and vim.g.cmp_widths.menu or 30,
}
for key, width in pairs(widths) do
if item[key] and vim.fn.strdisplaywidth(item[key]) > width then
item[key] = vim.fn.strcharpart(item[key], 0, width - 1) .. ""
end
end
return item
end
'';
};
};
cmp-nvim-lsp.enable = true;
cmp-path.enable = true;
cmp-buffer.enable = true;
};
# Keymaps
keymaps = [
# General
{
mode = "n";
key = "<leader>qq";
action = "<cmd>qa<cr>";
options = {desc = "Quit All";};
}
{
mode = "n";
key = "<leader>ww";
action = "<C-W>p";
options = {desc = "Other Window";};
}
{
mode = "n";
key = "<leader>wd";
action = "<C-W>c";
options = {desc = "Delete Window";};
}
{
mode = "n";
key = "<leader>ws";
action = "<C-W>s";
options = {desc = "Split Below";};
}
{
mode = "n";
key = "<leader>wv";
action = "<C-W>v";
options = {desc = "Split Right";};
}
{
mode = "n";
key = "<C-Left>";
action = "<C-W>h";
options = {desc = "Go To Left Window";};
}
{
mode = "n";
key = "<C-Down>";
action = "<C-W>j";
options = {desc = "Go To Lower Window";};
}
{
mode = "n";
key = "<C-Up>";
action = "<C-W>k";
options = {desc = "Go To Upper Window";};
}
{
mode = "n";
key = "<C-Right>";
action = "<C-W>l";
options = {desc = "Go To Right Window";};
}
{
mode = "v";
key = ">";
action = ">gv";
options = {desc = "Indent right selected text";};
}
{
mode = "v";
key = "<";
action = "<gv";
options = {desc = "Indent left selected text";};
}
# Clipboard
{
mode = ["n" "x"];
key = "y";
action = "<Plug>(YankyYank)";
options = {desc = "Yank Text";};
}
{
mode = ["n" "x"];
key = "p";
action = "<Plug>(YankyPutAfter)";
options = {desc = "Put Yanked Text After Cursor";};
}
{
mode = ["n" "x"];
key = "P";
action = "<Plug>(YankyPutBefore)";
options = {desc = "Put Yanked Text Before Cursor";};
}
{
mode = ["n" "x"];
key = "gp";
action = "<Plug>(YankyGPutAfter)";
options = {desc = "Put Yanked Text After Selection";};
}
{
mode = ["n" "x"];
key = "gP";
action = "<Plug>(YankyGPutBefore)";
options = {desc = "Put Yanked Text Befor Selection";};
}
{
mode = "n";
key = "<leader>cl";
action.__raw = ''require("lsp_lines").toggle'';
options = {desc = "Toggle LSP lines";};
}
# Terminal
{
mode = "t";
key = "<esc><esc>";
action = "<c-\\><c-n>";
options = {desc = "Enter Normal Mode";};
}
# Etc
{
mode = "n";
key = "<leader>e";
action = "<cmd>Neotree toggle<cr>";
options = {desc = "Open/Close Neotree";};
}
{
mode = "n";
key = "<leader>gg";
action = "<cmd>LazyGit<cr>";
options = {
desc = "LazyGit (root dir)";
};
}
];
}