nix-conf/home/user/nvf.nix
2025-09-17 15:24:07 +08:00

992 lines
27 KiB
Nix
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
pkgs,
lib,
osConfig,
inputs,
system,
...
}:
let
inherit (lib.generators) mkLuaInline;
suda-nvim = pkgs.vimUtils.buildVimPlugin {
name = "vim-suda";
src = pkgs.fetchFromGitHub {
owner = "lambdalisue";
repo = "vim-suda";
rev = "9adda7d195222d4e2854efb2a88005a120296c47";
hash = "sha256-46sy3rAdOCULVt1RkIoGdweoV3MqQaB33Et9MrxI6Lk=";
};
};
marks-nvim = pkgs.vimUtils.buildVimPlugin {
name = "marks-nvim";
src = inputs.marks-nvim;
};
in
{
programs.nvf = {
enable = true;
settings = {
vim = {
enableLuaLoader = true;
clipboard = {
enable = true;
providers = {
wl-copy.enable = true;
};
registers = "unnamedplus";
};
extraPlugins = with pkgs.vimPlugins; {
transparent = {
package = transparent-nvim;
setup =
# lua
''
require("transparent").setup({
extra_groups = {
"NormalFloat",
"NvimTreeNormal",
"TreesitterContext",
"FloatBorder",
"FoldColumn",
"Folded",
"BlinkCmpMenu",
"BlinkCmpBorder",
"BlinkCmpKind",
"WarningMsg",
"ErrorMsg",
"BlinkCmpMenuBorder",
"FzfLuaBackdrop",
"VertSplit",
"Pmenu",
"PmenuSbar",
"DiffText",
"DiffViewNormal",
"CursorColumn",
"ColorColumn",
"QuickFixLine",
"Error",
"NoiceScrollbar"
},
})
require("transparent").clear_prefix("NeoTree")
require("transparent").clear_prefix("GitGutter")
'';
};
suda = {
package = suda-nvim;
};
marks = {
package = marks-nvim;
setup = ''
require("marks").setup {}
'';
};
};
keymaps = [
# === Files === #
# Explorer
{
key = "<leader>e";
mode = [ "n" ];
action = ":Neotree toggle<CR>";
silent = true;
desc = "Toggle file explorer";
}
# === Fzf lua === #
{
key = "<Leader><Space>";
silent = true;
mode = [ "n" ];
action = ":FzfLua files<CR>";
nowait = true;
unique = true;
desc = "Find file";
}
{
key = "<Leader>/";
mode = [ "n" ];
action = ":FzfLua live_grep<CR>";
nowait = true;
unique = true;
desc = "Live grep";
}
# Lsp symbol document
{
key = "<Leader>ss";
silent = true;
mode = [ "n" ];
action = ":FzfLua lsp_document_symbols<CR>";
nowait = true;
unique = true;
desc = "Find symbols (document)";
}
# Lsp symbol workspace
{
key = "<Leader>sS";
silent = true;
mode = [ "n" ];
action = ":FzfLua lsp_workspace_symbols<CR>";
unique = true;
nowait = true;
desc = "Find symbols (workspace)";
}
# Registers
{
key = ''""'';
mode = [ "n" ];
action = ":FzfLua registers<CR>";
desc = "Registers";
}
# Marks
{
key = "''";
mode = [ "n" ];
action = ":FzfLua marks<CR>";
desc = "Marks";
}
# === Buffer === #
{
key = "<Leader>bo";
mode = [ "n" ];
action = ":BufferLineCloseOther<CR>";
desc = "Close other buffer";
}
{
key = "<Leader>bS";
mode = [ "n" ];
action = ":SudaWrite<CR>";
desc = "Save file as root";
}
# === General Control === #
# Save file
{
key = "<C-s>";
mode = [
"n"
"i"
"v"
];
action = "<C-\\><C-n>:w<CR>";
desc = "Save file";
}
{
key = "<S-Tab>";
mode = [ "i" ];
action = "<C-d>";
desc = "Shift left";
}
{
key = "gd";
mode = [ "n" ];
action = ":FzfLua lsp_definitions<CR>";
nowait = true;
desc = "Go to definition";
}
{
key = "gD";
mode = [ "n" ];
action = ":FzfLua lsp_declarations<CR>";
nowait = true;
desc = "Go to declaration";
}
{
key = "gi";
mode = [ "n" ];
action = ":FzfLua lsp_implementations<CR>";
nowait = true;
desc = "Go to implementation";
}
{
key = "gr";
mode = [ "n" ];
action = ":FzfLua lsp_references<CR>";
nowait = true;
desc = "List references";
}
{
key = "<Leader>n";
mode = [ "n" ];
action = ":NoiceAll<CR>";
nowait = true;
desc = "Notifications";
}
{
key = "<ESC><ESC>";
mode = [ "n" ];
action = ":noh<CR>";
desc = "Clear highlight";
}
# === Tab === #
{
key = ">";
mode = [ "v" ];
action = ">gv";
silent = true;
desc = "Shift right";
}
{
key = "<";
mode = [ "v" ];
action = "<gv";
silent = true;
desc = "Shift left";
}
# === Terminal === #
{
key = "<C-/>";
mode = [ "t" ];
action = "<C-\\><C-n>:ToggleTerm<CR>";
}
{
key = "<C-_>";
mode = [ "t" ];
action = "<C-\\><C-n>:ToggleTerm<CR>";
}
{
key = "<C-_>";
mode = [ "n" ];
action = ":ToggleTerm<CR>";
}
{
key = "<ESC><ESC>";
mode = [ "t" ];
action = "<C-\\><C-n>";
}
{
key = "<C-j>";
mode = [
"n"
"t"
];
action = "<C-\\><C-n><C-w>j";
nowait = true;
}
{
key = "<C-k>";
mode = [
"n"
"t"
];
action = "<C-\\><C-n><C-w>k";
nowait = true;
}
{
key = "<C-l>";
mode = [
"n"
"t"
];
action = "<C-\\><C-n><C-w>l";
nowait = true;
}
{
key = "<C-h>";
mode = [
"n"
"t"
];
action = "<C-\\><C-n><C-w>h";
nowait = true;
}
# New Term
{
key = "<Leader>tn";
mode = [ "n" ];
action = ":TermNew<CR>";
nowait = true;
desc = "Spawn new terminal";
}
# Select Term
{
key = "<Leader>tt";
mode = [ "n" ];
action = ":TermSelect<CR>";
nowait = true;
desc = "Select terminal";
}
# Send current selection to Term
{
key = "<Leader>ts";
mode = [ "v" ];
action = ":ToggleTermSendVisualSelection<CR>";
nowait = true;
desc = "Send current selection to terminal";
}
# === Fold (nvim-ufo) === #
{
key = "zR";
mode = [ "n" ];
action = ''
require("ufo").openAllFolds
'';
lua = true;
}
{
key = "zM";
mode = [ "n" ];
action = ''
require("ufo").closeAllFolds
'';
lua = true;
}
];
autocmds = [
{
event = [ "TextYankPost" ];
callback =
mkLuaInline
# lua
''
function()
vim.highlight.on_yank({ higroup = "IncSearch", timeout = 150 })
end
'';
desc = "Highlight yanked";
}
{
event = [ "BufWritePost" ];
callback =
mkLuaInline
# lua
''
function(args)
local bufname = vim.api.nvim_buf_get_name(args.buf)
local info = string.format("Saved %s", vim.fn.fnamemodify(bufname, ":t"))
require("fidget").notify(info, vim.log.levels.INFO)
end
'';
desc = "Fidget notify file saved";
}
];
globals = {
transparent_enabled = true;
};
vimAlias = true;
options = {
foldcolumn = "0";
foldlevel = 99;
foldlevelstart = 99;
foldenable = true;
spelllang = "en,cjk";
expandtab = true;
tabstop = 2;
softtabstop = 2;
shiftwidth = 2;
autoindent = true;
smartindent = true;
fillchars = "eob: ";
wrap = false;
};
lsp = {
enable = true;
formatOnSave = true;
otter-nvim.enable = true;
nvim-docs-view.enable = true;
lspkind.enable = true;
trouble = {
enable = true;
mappings = {
documentDiagnostics = "<Leader>xx";
};
};
};
debugger = {
nvim-dap = {
enable = true;
ui.enable = true;
};
};
diagnostics = {
enable = true;
config = {
float = {
border = "rounded";
};
virtual_text.format =
mkLuaInline
# lua
''
function(diagnostic)
return string.format("%s (%s)", diagnostic.message, diagnostic.source)
end
'';
};
};
languages = {
enableFormat = true;
enableTreesitter = true;
enableExtraDiagnostics = true;
bash.enable = true;
css.enable = true;
rust = {
enable = true;
lsp = {
enable = true;
package = [
"rust-analyzer"
];
opts = ''
['rust-analyzer'] = {
cargo = {allFeature = true},
checkOnSave = true,
procMacro = {
enable = true,
},
},
'';
};
};
nix = {
enable = true;
extraDiagnostics.enable = false;
format.type = "nixfmt";
lsp = {
server = "nil";
options = {
nix.flake.autoArchive = true;
};
# options = {
# nixos.expr =
# # nix
# ''(builtins.getFlake (builtins.toString ./.)).nixosConfigurations.${osConfig.networking.hostName}.options'';
# home_manager.expr =
# # nix
# ''(builtins.getFlake (builtins.toString ./.)).nixosConfigurations.${osConfig.networking.hostName}.options.home-manager.users.type.getSubOptions []'';
# };
};
};
sql.enable = true;
clang.enable = true;
ts = {
enable = true;
format.type = "prettierd";
extensions = {
ts-error-translator.enable = true;
};
};
python.enable = true;
markdown = {
enable = true;
extensions = {
render-markdown-nvim.enable = true;
};
};
html.enable = true;
lua.enable = true;
};
visuals = {
nvim-web-devicons.enable = true;
nvim-cursorline.enable = true;
cinnamon-nvim = {
enable = true;
setupOpts.keymaps = {
basic = true;
};
};
fidget-nvim = {
enable = true;
setupOpts.notification = {
window = {
border = "none";
winblend = 100;
};
};
};
highlight-undo.enable = true;
indent-blankline.enable = true;
};
statusline = {
lualine = {
enable = true;
activeSection = {
a = lib.mkForce [
''
{
"mode",
icons_enabled = true,
separator = {
left = "",
right = ""
},
}
''
''
{
"",
draw_empty = true,
separator = { left = '', right = '' }
}
''
];
b = lib.mkForce [
''
{
"filetype",
colored = true,
icon_only = true,
icon = { align = 'left' }
}
''
''
{
"filename",
symbols = {modified = ' ', readonly = ' '},
separator = { left = '', right = ''}
}
''
''
{
"",
draw_empty = true,
separator = { left = '', right = '' }
}
''
];
c = lib.mkForce [
''
{
"diff",
colored = false,
diff_color = {
-- Same color values as the general color option can be used here.
added = 'DiffAdd', -- Changes the diff's added color
modified = 'DiffChange', -- Changes the diff's modified color
removed = 'DiffDelete', -- Changes the diff's removed color you
},
symbols = {added = '+', modified = '~', removed = '-'}, -- Changes the diff symbols
separator = {right = ''}
}
''
];
x = lib.mkForce [
''
{
-- Lsp server name
function()
local buf_ft = vim.bo.filetype
local excluded_buf_ft = { toggleterm = true, NvimTree = true, ["neo-tree"] = true, TelescopePrompt = true }
if excluded_buf_ft[buf_ft] then
return ""
end
local bufnr = vim.api.nvim_get_current_buf()
local clients = vim.lsp.get_clients({ bufnr = bufnr })
if vim.tbl_isempty(clients) then
return "No Active LSP"
end
local active_clients = {}
for _, client in ipairs(clients) do
table.insert(active_clients, client.name)
end
return table.concat(active_clients, ", ")
end,
icon = ' ',
separator = {left = ''},
}
''
''
{
"diagnostics",
sources = {'nvim_lsp', 'nvim_diagnostic', 'nvim_diagnostic', 'vim_lsp', 'coc'},
symbols = {error = '󰅙 ', warn = ' ', info = ' ', hint = '󰌵 '},
colored = true,
update_in_insert = false,
always_visible = false,
diagnostics_color = {
color_error = { fg = 'red' },
color_warn = { fg = 'yellow' },
color_info = { fg = 'cyan' },
},
}
''
];
y = lib.mkForce [
''
{
"",
draw_empty = true,
separator = { left = '', right = '' }
}
''
''
{
'searchcount',
maxcount = 999,
timeout = 120,
separator = {left = ''}
}
''
''
{
"branch",
icon = ' ',
separator = {left = ''}
}
''
];
z = lib.mkForce [
''
{
"",
draw_empty = true,
separator = { left = '', right = '' }
}
''
''
{
"progress",
separator = {left = ''}
}
''
''
{"location"}
''
''
{
"fileformat",
color = {fg='black'},
symbols = {
unix = '', -- e843
dos = '', -- e70f
mac = '', -- e711
}
}
''
];
};
componentSeparator = {
left = "";
right = "";
};
sectionSeparator = {
left = "";
right = "";
};
};
};
autopairs.nvim-autopairs.enable = true;
autocomplete = {
blink-cmp = {
enable = true;
setupOpts = {
completion = {
menu.border = "rounded";
documentation.window.border = "rounded";
};
};
};
};
snippets.luasnip = {
enable = true;
providers = [ "blink-cmp" ];
setupOpts.enable_autosnippets = true;
};
git = {
enable = true;
};
filetree = {
neo-tree = {
enable = true;
setupOpts = {
window = {
position = "right";
mappings = {
"l" = "open";
"h" = "close_node";
};
};
};
};
};
tabline = {
nvimBufferline = {
enable = true;
setupOpts = {
options = {
show_close_icon = false;
separator_style = "slope";
numbers = "none";
indicator = {
style = "none";
};
diagnostic = "nvim_lsp";
};
};
mappings = {
closeCurrent = "<Leader>bd";
cycleNext = "L";
cyclePrevious = "H";
};
};
};
binds = {
whichKey.enable = true;
};
fzf-lua = {
enable = true;
setupOpts = {
previewers = {
builtin = {
extensions = {
"jpg" = {
"kitty" = "";
};
};
snacks_image = {
enabled = false;
render_inline = false;
};
};
};
winopts = {
preview = {
hidden = "hidden";
};
border = "rounded";
};
fzf_opts = {
"--no-header" = "";
"--no-scrollbar" = "";
};
files = {
formatter = "path.filename_first";
prompt = ":";
no_header = true;
cwd_header = false;
cwd_prompt = false;
winopts = {
title = " files 📑 ";
title_pos = "center";
title_flags = false;
};
};
buffers = {
formatter = "path.filename_first";
prompt = ":";
no_header = true;
fzf_opts = {
"--delimiter" = " ";
"--with-nth" = "-1..";
};
winopts = {
title = " buffers 📝 ";
title_pos = "center";
};
};
lsp = {
symbols = {
cwd_only = true;
no_header = true;
prompt = ":";
winopts = {
title = " symbols ";
title_pos = "center";
height = 0.6;
preview = {
hidden = "nohidden";
horizontal = "down:40%";
wrap = "wrap";
};
};
};
};
registers = {
prompt = "registers:";
filter = "%a";
winopts = {
title = " registers 🏷 ";
title_pos = "center";
};
};
};
};
dashboard = {
alpha.enable = true;
};
notify = {
nvim-notify = {
enable = true;
setupOpts.background_colour = "#020202";
};
};
projects = {
project-nvim.enable = true;
};
utility = {
diffview-nvim.enable = true;
icon-picker.enable = true;
surround.enable = true;
multicursors.enable = true;
undotree.enable = true;
yazi-nvim = {
enable = true;
};
images = {
image-nvim = {
enable = true;
setupOpts = {
backend = "kitty";
};
};
};
};
notes = {
todo-comments.enable = true;
};
terminal = {
toggleterm = {
enable = true;
lazygit.enable = true;
mappings = {
open = "<C-/>";
};
setupOpts.winbar.name_formatter =
mkLuaInline
# lua
''
function(term)
return " " .. term.id
end
'';
};
};
ui = {
noice = {
enable = true;
setupOpts = {
routes = [
# Hide neo-tree notification
{
filter = {
event = "notify";
kind = "info";
any = [
{ find = "hidden"; }
];
};
}
# Hide Save
{
filter = {
event = "msg_show";
kind = "bufwrite";
};
opts = {
skip = true;
};
}
{
filter = {
event = "msg_show";
any = [
{ find = "written"; }
];
};
}
];
};
};
colorizer.enable = true;
fastaction.enable = true;
nvim-ufo = {
enable = true;
setupOpts = {
fold_virt_text_handler =
mkLuaInline
# lua
''
function(virtText, lnum, endLnum, width, truncate)
local newVirtText = {}
local suffix = (' 󰁂 %d '):format(endLnum - lnum)
local sufWidth = vim.fn.strdisplaywidth(suffix)
local targetWidth = width - sufWidth
local curWidth = 0
for _, chunk in ipairs(virtText) do
local chunkText = chunk[1]
local chunkWidth = vim.fn.strdisplaywidth(chunkText)
if targetWidth > curWidth + chunkWidth then
table.insert(newVirtText, chunk)
else
chunkText = truncate(chunkText, targetWidth - curWidth)
local hlGroup = chunk[2]
table.insert(newVirtText, {chunkText, hlGroup})
chunkWidth = vim.fn.strdisplaywidth(chunkText)
-- str width returned from truncate() may less than 2nd argument, need padding
if curWidth + chunkWidth < targetWidth then
suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth)
end
break
end
curWidth = curWidth + chunkWidth
end
table.insert(newVirtText, {suffix, 'MoreMsg'})
return newVirtText
end
'';
provider_selector =
mkLuaInline
# lua
''
function(bufnr, filetype, buftype)
return {'treesitter', 'indent'}
end
'';
};
};
borders = {
enable = true;
plugins = {
lspsaga.enable = true;
fastaction.enable = true;
lsp-signature.enable = true;
which-key.enable = true;
};
};
};
};
};
};
}