chore: initial commit

Moved from a94642d3e8
This commit is contained in:
Nicolas Goudry 2024-05-27 00:58:58 +02:00
commit 1c12503ebf
No known key found for this signature in database
GPG key ID: 5FC434D9FFD1DF44
15 changed files with 1434 additions and 0 deletions

192
plugins/alpha.nix Normal file
View file

@ -0,0 +1,192 @@
# homepage: https://github.com/goolord/alpha-nvim
# nixvim doc: https://nix-community.github.io/nixvim/plugins/alpha/index.html
{ libn, pkgs, ... }:
let
header = {
type = "text";
# Use color defined by catppuccin
opts = {
hl = "AlphaHeader";
position = "center";
};
# Generated from https://www.asciiart.eu/text-to-ascii-art
# Font used: Graffiti
val = [
" ________ ____ ____.___ _____ "
" / _____/ \\ \\ / /| | / \\ "
"/ \\ ___ \\ Y / | |/ \\ / \\ "
"\\ \\_\\ \\ \\ / | / Y \\"
" \\______ / /\\ \\___/ |___\\____|__ /"
" \\/ \\/ \\/ "
];
};
buttons = {
type = "group";
opts.spacing = 1;
# Use function defined in lua config (see below) to generate buttons
val = [
{ __raw = "alpha_button('LDR n ', ' New File')"; }
{ __raw = "alpha_button('LDR e ', ' Explorer')"; }
{ __raw = "alpha_button('LDR f f', ' Find File')"; }
{ __raw = "alpha_button('LDR f o', '󰈙 Recents')"; }
{ __raw = "alpha_button('LDR f g', '󰈭 Live Grep')"; }
];
};
# Show random fortune as footer
footer = {
type = "text";
# Defined by Alpha
# https://github.com/goolord/alpha-nvim/blob/main/lua/alpha/fortune.lua
val.__raw = "require('alpha.fortune')()";
# Use color defined by catppuccin
opts = {
hl = "AlphaFooter";
position = "center";
};
};
layout = [
# Padding size depending on window height (taken from AstroNvim)
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/alpha.lua#L141
{
type = "padding";
val.__raw = "vim.fn.max { 2, vim.fn.floor(vim.fn.winheight(0) * 0.2) }";
}
header
{ type = "padding"; val = 5; }
buttons
{ type = "padding"; val = 3; }
footer
];
in
{
extra = {
packages = with pkgs.vimPlugins; [
alpha-nvim
nvim-web-devicons
];
# Based on Alpha dashboard theme with tweaks from AstroNvim
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/alpha.lua#L86-L112
# https://github.com/goolord/alpha-nvim/blob/main/lua/alpha/themes/dashboard.lua#L46-L73
config = ''
local alpha_leader = "LDR"
function alpha_button(shortcut, desc, keybind, keybind_opts)
local sc = shortcut:gsub("%s", ""):gsub(alpha_leader, "<leader>")
local real_leader = vim.g.mapleader
if real_leader == " " then real_leader = "SPC" end
local opts = {
position = "center",
shortcut = shortcut:gsub(alpha_leader, real_leader),
cursor = -2,
width = 36,
align_shortcut = "right",
hl = "AlphaButtons",
hl_shortcut = "AlphaShortcut",
}
if keybind then
keybind_opts = if_nil(keybind_opts, { noremap = true, silent = true, nowait = true, desc = desc })
opts.keymap = { "n", sc, keybind, keybind_opts }
end
local function on_press()
local key = vim.api.nvim_replace_termcodes(keybind or sc .. "<ignore>", true, false, true)
vim.api.nvim_feedkeys(key, "t", false)
end
return {
type = "button",
val = desc,
on_press = on_press,
opts = opts,
}
end
require("alpha").setup({
layout = ${libn.helpers.toLuaObject layout},
})
'';
};
rootOpts = {
autoGroups.alpha = { };
# Custom autocommand (taken from AstroNvim)
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/alpha.lua#L19-L43
autoCmd = [
{
desc = "Disable status, tablines and cmdheight for alpha";
event = [ "User" "BufWinEnter" ];
group = "alpha";
callback.__raw = ''
function(event)
if
(
(event.event == "User" and event.file == "AlphaReady")
or (event.event == "BufWinEnter" and vim.bo[event.buf].filetype == "alpha")
) and not vim.g.before_alpha
then
vim.g.before_alpha = {
showtabline = vim.opt.showtabline:get(),
laststatus = vim.opt.laststatus:get(),
cmdheight = vim.opt.cmdheight:get(),
}
vim.opt.showtabline, vim.opt.laststatus, vim.opt.cmdheight = 0, 0, 0
elseif vim.g.before_alpha and event.event == "BufWinEnter" and vim.bo[event.buf].buftype ~= "nofile" then
vim.opt.laststatus, vim.opt.showtabline, vim.opt.cmdheight =
vim.g.before_alpha.laststatus, vim.g.before_alpha.showtabline, vim.g.before_alpha.cmdheight
vim.g.before_alpha = nil
end
end
'';
}
];
colorschemes.catppuccin.settings = {
# Enable catppuccin colors
# https://github.com/catppuccin/nvim/blob/main/lua/catppuccin/groups/integrations/alpha.lua
integrations.alpha = true;
# Override default catppuccin header color
custom_highlights = ''
function(colors)
return {
AlphaHeader = { fg = colors.red },
}
end
'';
};
keymaps = [
{
key = "<leader>h";
options.desc = "Home screen";
# Open alpha in a non neo-tree window (taken from AstroNvim)
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/alpha.lua#L10-L16
action.__raw = ''
function()
local wins = vim.api.nvim_tabpage_list_wins(0)
if #wins > 1 and vim.bo[vim.api.nvim_win_get_buf(wins[1])].filetype == "neo-tree" then
vim.fn.win_gotoid(wins[2])
end
require("alpha").start(false)
end
'';
}
];
};
}

62
plugins/default.nix Normal file
View file

@ -0,0 +1,62 @@
# This file will load all plugins defined in the current directory (plugins)
# and load their content in the 'plugins' nixvim attribute.
# Each plugin file must export a lambda, which is called with an attrset
# containing nixpkgs library as 'lib'. Plugins may or may not use it.
# For plugins natively supported by nixvim, the plugin file must have the same
# name as the plugin attribute name expected by nixvim (ie. 'telescope.nix' for
# 'plugins.telescope'). The plugin lambda must return an attrset with at least
# the 'opts' attribute, this attribute is the plugin options as expected by
# nixvim.
# For plugins not supported by nixvim, the plugin file can have any name. The
# plugin lambda must return an attrset with the 'extra' attribute which is also
# an attrset with two attributes: 'package' and 'config'. The 'package'
# attribute is the plugin package in nixpkgs (ie. vimPlugins.<plugin>). The
# 'config' attribute is the plugin configuration in Lua format.
# Additionally, a 'rootOpts' can be returned alongside other attributes, this
# attribute will be used to set extra options to the root nixvim options. For
# example, this allows to set keymaps for plugins that do not have an internal
# option to set keymaps.
{ lib, ... }@args:
let
# Flag to enable LSP plugin with servers
# Given as an extra special arg when building nixvim module
withLSP = args.withLSP or true;
# Load plugins filenames in list
definitions = lib.attrNames (
lib.filterAttrs
(filename: kind:
filename != "default.nix"
&& (kind == "regular" || kind == "directory")
# If file is an LSP plugin, respect withLSP flag
&& (if filename == "lsp.nix" then withLSP else true)
)
(builtins.readDir ./.)
);
in
lib.mkMerge (
map
(file:
let
pluginName = lib.elemAt (lib.splitString "." file) 0;
plugin = import ./${file} args;
in
lib.mkMerge [
(lib.optionalAttrs (plugin ? opts) {
plugins.${pluginName} = plugin.opts;
})
(lib.optionalAttrs (plugin ? extra) {
extraConfigLua = plugin.extra.config or "";
extraPlugins = plugin.extra.packages;
})
(plugin.rootOpts or { })
]
)
definitions
)

266
plugins/neo-tree.nix Normal file
View file

@ -0,0 +1,266 @@
# homepage: https://github.com/nvim-neo-tree/neo-tree.nvim
# nixvim doc: https://nix-community.github.io/nixvim/plugins/neo-tree/index.html
_:
{
opts = {
enable = true;
# Automatically clean up broken neo-tree buffers saved in sessions
autoCleanAfterSessionRestore = true;
# Close Neo-tree if it is the last window left in the tab
closeIfLastWindow = true;
# Disable fold column (gutter)
eventHandlers = {
neo_tree_buffer_enter = ''
function(_)
vim.opt_local.signcolumn = "auto"
vim.opt_local.foldcolumn = "0"
end
'';
};
# Extra options not exposed by the plugin
extraOptions = {
# Custom functions (taken from AstroNvim)
commands = {
# Focus first directory child item or open directory
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/neo-tree.lua#L120-L135
child_or_open.__raw = ''
function(state)
local node = state.tree:get_node()
if node:has_children() then
if not node:is_expanded() then -- if unexpanded, expand
state.commands.toggle_node(state)
else -- if expanded and has children, select the next child
if node.type == "file" then
state.commands.open(state)
else
require("neo-tree.ui.renderer").focus_node(state, node:get_child_ids()[1])
end
end
else -- if has no children
state.commands.open(state)
end
end
'';
# Copy various path format of currently focused item
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/neo-tree.lua#L136-L168
copy_selector.__raw = ''
function(state)
local node = state.tree:get_node()
local filepath = node:get_id()
local filename = node.name
local modify = vim.fn.fnamemodify
local vals = {
["BASENAME"] = modify(filename, ":r"),
["EXTENSION"] = modify(filename, ":e"),
["FILENAME"] = filename,
["PATH (CWD)"] = modify(filepath, ":."),
["PATH (HOME)"] = modify(filepath, ":~"),
["PATH"] = filepath,
["URI"] = vim.uri_from_fname(filepath),
}
local options = vim.tbl_filter(function(val) return vals[val] ~= "" end, vim.tbl_keys(vals))
if vim.tbl_isempty(options) then
return
end
table.sort(options)
vim.ui.select(options, {
prompt = "Choose to copy to clipboard:",
format_item = function(item) return ("%s: %s"):format(item, vals[item]) end,
}, function(choice)
local result = vals[choice]
if result then
vim.fn.setreg("+", result)
end
end)
end
'';
# Find file in currently focused item if it is a directory, or its closest parent directory
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/neo-tree.lua#L205-L209
find_file_in_dir.__raw = ''
function(state)
local node = state.tree:get_node()
local path = node.type == "file" and node:get_parent_id() or node:get_id()
TelescopeWithTheme('find_files', { cwd = path })
end
'';
# Live grep in currently focused item if it is a directory, or its closest parent directory
grep_in_dir.__raw = ''
function(state)
local node = state.tree:get_node()
local path = node.type == "file" and node:get_parent_id() or node:get_id()
TelescopeWithTheme('live_grep', { cwd = path })
end
'';
# Focus parent directory of currently focused item or close directory
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/neo-tree.lua#L112-L119
parent_or_close.__raw = ''
function(state)
local node = state.tree:get_node()
if node:has_children() and node:is_expanded() then
state.commands.toggle_node(state)
else
require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id())
end
end
'';
};
window = {
# Keymaps for filter popup window in fuzzy finder mode (ie. "/")
fuzzy_finder_mappings = {
"<C-J>" = "move_cursor_down";
"<C-K>" = "move_cursor_up";
};
# Keymaps when neotree window is focused
mappings = {
"[b" = "prev_source";
"]b" = "next_source";
# Disable default behavior to toggle node on Space keypress
"<Space>".__raw = "false";
# See extraOptions.commands for details on following keymaps
h = "parent_or_close";
l = "child_or_open";
F = "find_file_in_dir";
W = "grep_in_dir";
Y = "copy_selector";
};
};
};
defaultComponentConfigs = {
gitStatus.symbols = {
added = "";
conflict = "";
deleted = "";
ignored = "";
modified = "";
renamed = "";
staged = "";
unstaged = "";
untracked = "";
};
};
filesystem = {
# Find and focus file in active buffer
followCurrentFile.enabled = true;
# Open neotree "fullscreen" when opening a directory
hijackNetrwBehavior = "open_current";
};
# Sources tabs
sourceSelector = {
# Label position
contentLayout.__raw = "'center'";
# No tabs separator
separator = "";
# Show tabs on winbar
winbar = true;
# Sources to show and their labels
sources = [
{
displayName = " Files";
source = "filesystem";
}
{
displayName = "󰈙 Bufs";
source = "buffers";
}
{
displayName = "󰊢 Git";
source = "git_status";
}
];
};
};
rootOpts = {
# Enable catppuccin colors
# https://github.com/catppuccin/nvim/blob/main/lua/catppuccin/groups/integrations/neotree.lua
colorschemes.catppuccin.settings.integrations.neotree = true;
autoGroups.neotree = { };
# Custom autocommands (taken from AstroNvim)
autoCmd = [
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/neo-tree.lua#L21-L37
{
desc = "Open explorer on startup with directory";
event = "BufEnter";
group = "neotree";
callback.__raw = ''
function()
if package.loaded["neo-tree"] then
return true
else
local stats = vim.loop.fs_stat(vim.api.nvim_buf_get_name(0))
if stats and stats.type == "directory" then
return true
end
end
end
'';
}
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/neo-tree.lua#L25-L35
{
desc = "Refresh explorer sources when closing lazygit";
event = "TermClose";
group = "neotree";
pattern = "*lazygit*";
callback.__raw = ''
function()
local manager_avail, manager = pcall(require, "neo-tree.sources.manager")
if manager_avail then
for _, source in ipairs { "filesystem", "git_status", "document_symbols" } do
local module = "neo-tree.sources." .. source
if package.loaded[module] then manager.refresh(require(module).name) end
end
end
end
'';
}
];
keymaps = [
{
key = "<leader>e";
action = "<cmd>Neotree toggle<cr>";
options.desc = "Toggle explorer";
}
{
key = "<leader>o";
options.desc = "Toggle explorer focus";
# https://github.com/AstroNvim/AstroNvim/blob/v4.7.7/lua/astronvim/plugins/neo-tree.lua#L12-L18
action.__raw = ''
function()
if vim.bo.filetype == "neo-tree" then
vim.cmd.wincmd "p"
else
vim.cmd.Neotree "focus"
end
end
'';
}
];
};
}

132
plugins/telescope.nix Normal file
View file

@ -0,0 +1,132 @@
# homepage: https://github.com/nvim-telescope/telescope.nvim
# nixvim doc: https://nix-community.github.io/nixvim/plugins/telescope/index.html
{ libn, ... }:
{
opts = {
enable = true;
};
rootOpts = {
# Enable catppuccin colors
# https://github.com/catppuccin/nvim/blob/main/lua/catppuccin/groups/integrations/telescope.lua
colorschemes.catppuccin.settings.integrations.telescope.enabled = true;
# Set custom behavior for dropdown theme:
# - use 80% of window width
# - use all window height
# - display preview at bottom
# ┌──────────────────────────────────────────────────┐
# │ ┌────────────────────────────────────────┐ │
# │ │ Prompt │ │
# │ ├────────────────────────────────────────┤ │
# │ │ Result │ │
# │ │ Result │ │
# │ └────────────────────────────────────────┘ │
# │ ┌────────────────────────────────────────┐ │
# │ │ Preview │ │
# │ │ Preview │ │
# │ │ Preview │ │
# │ │ Preview │ │
# │ │ Preview │ │
# │ │ Preview │ │
# │ └────────────────────────────────────────┘ │
# └──────────────────────────────────────────────────┘
extraConfigLuaPre = ''
local TelescopeWithTheme = function(fn, args)
args.layout_config = {
anchor = "N",
mirror = true,
width = 0.8,
}
if fn == "keymaps" or fn == "registers" then args.layout_config.height = function(_, _, max_lines) return max_lines end end
require("telescope.builtin")[fn](require("telescope.themes").get_dropdown(args))
end
'';
# Use root keymaps to allow usage of custom TelescopeWithTheme function
keymaps =
let
mkTelescopeKeymap =
{ key
, mode ? "n"
, fn
, args ? { __empty = true; }
, desc ? ""
}: {
inherit key mode;
action.__raw = "function() TelescopeWithTheme('${fn}', ${libn.helpers.toLuaObject args}) end";
options = { inherit desc; };
};
in
map mkTelescopeKeymap [
{
desc = "Resume previous search";
key = "<leader>f<cr>";
fn = "resume";
}
{
desc = "Find words in current buffer";
key = "<leader>f/";
fn = "current_buffer_fuzzy_find";
}
{
desc = "Find buffers";
key = "<leader>fb";
fn = "buffers";
}
{
desc = "Find files";
key = "<leader>ff";
fn = "find_files";
}
{
desc = "Find all files";
key = "<leader>fF";
fn = "find_files";
args = {
hidden = true;
no_ignore = true;
};
}
{
desc = "Find words";
key = "<leader>fg";
fn = "live_grep";
}
{
desc = "Find help tags";
key = "<leader>fh";
fn = "help_tags";
}
{
desc = "Find keymaps";
key = "<leader>fk";
fn = "keymaps";
}
{
desc = "Find history";
key = "<leader>fo";
fn = "oldfiles";
}
{
desc = "Find registers";
key = "<leader>fr";
fn = "registers";
}
{
desc = "Find word under cursor";
key = "<leader>fw";
fn = "grep_string";
}
{
desc = "Search references";
key = "gr";
fn = "lsp_references";
}
];
};
}

142
plugins/treesitter.nix Normal file
View file

@ -0,0 +1,142 @@
# homepage: https://github.com/nvim-treesitter/nvim-treesitter
# nixvim doc: https://nix-community.github.io/nixvim/plugins/treesitter/index.html
_:
{
opts = {
# Enable treesitter syntax highlighting
enable = true;
# Enable treesitter based indentation (use '=' to auto-indent)
indent = true;
# Enable incremental selection
# Keymaps are defined as global nixvim keymaps
incrementalSelection.enable = true;
};
rootOpts = {
# Enable catppuccin colors
# https://github.com/catppuccin/nvim/blob/main/lua/catppuccin/groups/integrations/treesitter.lua
colorschemes.catppuccin.settings.integrations.treesitter = true;
keymaps = [
{
mode = [ "n" "x" "o" ];
key = ",";
action.__raw = "function() require('nvim-treesitter.textobjects.repeatable_move').repeat_last_move() end";
options.desc = "Repeat last move";
}
{
mode = [ "n" "x" "o" ];
key = ";";
action.__raw = "function() require('nvim-treesitter.textobjects.repeatable_move').repeat_last_move_opposite() end";
options.desc = "Repeat last move in the opposite direction";
}
# Workaround for setting descriptions to treesitter incremental selection keymaps
# See https://github.com/nix-community/nixvim/issues/1506
{
mode = "n";
key = "<leader>ss";
action.__raw = "function() require('nvim-treesitter.incremental_selection').init_selection() end";
options.desc = "Start incremental selection";
}
{
mode = "v";
key = "<leader>sd";
action.__raw = "function() require('nvim-treesitter.incremental_selection').node_decremental() end";
options.desc = "Decrement selection";
}
{
mode = "v";
key = "<leader>si";
action.__raw = "function() require('nvim-treesitter.incremental_selection').node_incremental() end";
options.desc = "Increment selection by node";
}
{
mode = "v";
key = "<leader>sc";
action.__raw = "function() require('nvim-treesitter.incremental_selection').scope_incremental() end";
options.desc = "Increment selection by scope";
}
];
# Treesitter textobjects configuration
plugins.treesitter-textobjects = {
enable = true;
# Jump across text objects
move = {
enable = true;
setJumps = true;
gotoNextStart = {
"]k" = { query = "@block.outer"; desc = "Next block start"; };
"]f" = { query = "@function.outer"; desc = "Next function start"; };
"]a" = { query = "@parameter.inner"; desc = "Next argument start"; };
};
gotoNextEnd = {
"]K" = { query = "@block.outer"; desc = "Next block end"; };
"]F" = { query = "@function.outer"; desc = "Next function end"; };
"]A" = { query = "@parameter.inner"; desc = "Next argument end"; };
};
gotoPreviousStart = {
"[k" = { query = "@block.outer"; desc = "Previous block start"; };
"[f" = { query = "@function.outer"; desc = "Previous function start"; };
"[a" = { query = "@parameter.inner"; desc = "Previous argument start"; };
};
gotoPreviousEnd = {
"[K" = { query = "@block.outer"; desc = "Previous block end"; };
"[F" = { query = "@function.outer"; desc = "Previous function end"; };
"[A" = { query = "@parameter.inner"; desc = "Previous argument end"; };
};
};
# Select text objects
select = {
enable = true;
# Automatically jump to next textobjects, ie. if a keymap is pressed
# while the cursor is not under a textobject, the next relevant
# textobject will be used as "source", similar to the default nvim
# behavior
lookahead = true;
keymaps = {
ak = { query = "@block.outer"; desc = "around block"; };
ik = { query = "@block.inner"; desc = "inside block"; };
ac = { query = "@class.outer"; desc = "around class"; };
ic = { query = "@class.inner"; desc = "inside class"; };
"a?" = { query = "@conditional.outer"; desc = "around conditional"; };
"i?" = { query = "@conditional.inner"; desc = "inside conditional"; };
af = { query = "@function.outer"; desc = "around function"; };
"if" = { query = "@function.inner"; desc = "inside function"; };
ao = { query = "@loop.outer"; desc = "around loop"; };
io = { query = "@loop.inner"; desc = "inside loop"; };
aa = { query = "@parameter.outer"; desc = "around argument"; };
ia = { query = "@parameter.inner"; desc = "inside argument"; };
};
};
# Swap nodes with next/previous one
swap = {
enable = true;
swapNext = {
">K" = { query = "@block.outer"; desc = "Swap next block"; };
">F" = { query = "@function.outer"; desc = "Swap next function"; };
">A" = { query = "@parameter.inner"; desc = "Swap next argument"; };
};
swapPrevious = {
"<K" = { query = "@block.outer"; desc = "Swap previous block"; };
"<F" = { query = "@function.outer"; desc = "Swap previous function"; };
"<A" = { query = "@parameter.inner"; desc = "Swap previous argument"; };
};
};
};
};
}

21
plugins/which-key.nix Normal file
View file

@ -0,0 +1,21 @@
# homepage: https://github.com/folke/which-key.nvim
# nixvim doc: https://nix-community.github.io/nixvim/plugins/which-key/index.html
_:
{
opts = {
enable = true;
window.border = "single";
# Disable which-key when in neo-tree or telescope
disable.filetypes = [
"TelescopePrompt"
"neo-tree"
"neo-tree-popup"
];
};
# Enable catppuccin colors
# https://github.com/catppuccin/nvim/blob/main/lua/catppuccin/groups/integrations/which_key.lua
rootOpts.colorschemes.catppuccin.settings.integrations.which_key = true;
}