initial commit

This commit is contained in:
xinyangli 2024-08-20 13:43:03 +08:00
commit 35fb1473db
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
20 changed files with 836 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
result

17
README.md Normal file
View file

@ -0,0 +1,17 @@
# Nixvim template
This template gives you a good starting point for configuring nixvim standalone.
## Configuring
To start configuring, just add or modify the nix files in `./config`.
If you add a new configuration file, remember to add it to the
[`config/default.nix`](./config/default.nix) file
## Testing your new configuration
To test your configuration simply run the following command
```
nix run .
```

5
config/bufferline.nix Normal file
View file

@ -0,0 +1,5 @@
{
plugins.bufferline = {
enable = true;
};
}

18
config/comment.nix Normal file
View file

@ -0,0 +1,18 @@
{
plugins.comment = {
enable = true;
};
keymaps = [
{
mode = [ "n" ];
key = "<C-_>";
action = "gcc";
}
{
mode = [ "v" ];
key = "<C-_>";
action = "gc";
}
];
}

29
config/core.nix Normal file
View file

@ -0,0 +1,29 @@
{
config = {
# Color scheme.
colorschemes.catppuccin = {
enable = true;
settings.flavour = "mocha";
};
# Options.
opts = {
# Indent settings.
tabstop = 2;
shiftwidth = 2;
expandtab = true;
# Line number.
number = true;
relativenumber = true;
signcolumn = "yes";
# Search case sensitivity.
ic = true;
};
# Clipboard.
clipboard = {
register = "unnamedplus";
providers.xclip.enable = true;
};
};
}

18
config/default.nix Normal file
View file

@ -0,0 +1,18 @@
{
# Import all your configuration modules here
imports = [
./bufferline.nix
./comment.nix
./core.nix
./gitsign.nix
./indent-blankline.nix
./keybindings.nix
./lsp
./rainbow-delimiters.nix
./telescope.nix
./toggleterm.nix
./treesitter.nix
./neo-tree.nix
./which-key.nix
];
}

69
config/gitsign.nix Normal file
View file

@ -0,0 +1,69 @@
{ helpers, ... }:
{
plugins.gitsigns = {
enable = true;
};
keymaps = [
# Navigate through hunks
{
mode = [ "n" ];
key = "]c";
action = helpers.mkRaw ''
function()
if vim.wo.diff then
vim.cmd.normal({']c', bang = true})
else
require("gitsigns").nav_hunk('next')
end
end
'';
}
{
mode = [ "n" ];
key = "[c";
action = helpers.mkRaw ''
function()
if vim.wo.diff then
vim.cmd.normal({'[c', bang = true})
else
require("gitsigns").nav_hunk('prev')
end
end
'';
}
{
mode = [ "v" ];
key = "<leader>hs";
action = helpers.mkRaw ''
function()
require("gitsigns").stage_hunk({ vim.fn.line("."), vim.fn.line("v") })
end
'';
options = {
desc = "Stage Hunk";
};
}
{
mode = [ "n" ];
key = "<leader>hu";
action = helpers.mkRaw ''
require("gitsigns").undo_stage_hunk
'';
options = {
desc = "Undo Stage Hunk";
};
}
{
mode = [ "n" ];
key = "<leader>hp";
action = helpers.mkRaw ''
require("gitsigns").preview_hunk
'';
options = {
desc = "Preview Hunk";
};
}
];
}

View file

@ -0,0 +1,7 @@
{
plugins.indent-blankline = {
enable = true;
settings = {
};
};
}

96
config/keybindings.nix Normal file
View file

@ -0,0 +1,96 @@
{ helpers, ... }:
{
keymaps = [
# Window movement.
{
mode = [ "n" ];
key = "<c-h>";
action = "<c-w>h";
options = {
remap = true;
};
}
{
mode = [ "n" ];
key = "<c-h>";
action = helpers.mkRaw ''
function()
local cur_win = vim.api.nvim_get_current_win()
vim.cmd('wincmd h')
if cur_win == vim.api.nvim_get_current_win() then
require('neo-tree.command').execute({ toggle = true })
end
end
'';
options = {
remap = true;
};
}
{
mode = [ "n" ];
key = "<c-j>";
action = helpers.mkRaw ''
function()
local cur_win = vim.api.nvim_get_current_win()
vim.cmd('wincmd j')
if cur_win == vim.api.nvim_get_current_win() then
vim.cmd('ToggleTerm')
end
end
'';
options = {
remap = true;
};
}
{
mode = [ "n" ];
key = "<c-k>";
action = "<c-w>k";
options = {
remap = true;
};
}
{
mode = [ "n" ];
key = "<c-l>";
action = "<c-w>l";
options = {
remap = true;
};
}
# Use ESC to exit terminal mode
{
mode = [ "t" ];
key = "<Esc>";
action = "<C-\\><C-n>";
}
# Buffer movement
{
mode = [ "n" ];
key = "<s-h>";
action = "<cmd>bprevious<cr>";
options = {
desc = "Previous Buffer";
};
}
{
mode = [ "n" ];
key = "<s-l>";
action = "<cmd>bnext<cr>";
options = {
desc = "Next Buffer";
};
}
{
mode = [ "n" "i" ];
key = "<S-Tab>";
action = "<cmd>tabprevious<cr>";
options = {
desc = "Previous Tab";
};
}
];
}

6
config/lsp/default.nix Normal file
View file

@ -0,0 +1,6 @@
{
imports = [
./lsp.nix
./lsp-format.nix
];
}

View file

@ -0,0 +1,5 @@
{
plugins.lsp-format = {
enable = true;
};
}

75
config/lsp/lsp.nix Normal file
View file

@ -0,0 +1,75 @@
{ ... }:
{
plugins.lsp = {
enable = true;
servers = {
cmake = {
enable = true;
};
clangd = {
enable = true;
};
pyright = {
enable = true;
};
nixd = {
enable = true;
};
metals = {
enable = true;
};
};
keymaps = {
silent = true;
lspBuf = {
gd = {
action = "definition";
desc = "Goto Definition";
};
gA = {
action = "references";
desc = "Goto References";
};
gD = {
action = "declaration";
desc = "Goto Declaration";
};
gI = {
action = "implementation";
desc = "Goto Implementation";
};
gT = {
action = "type_definition";
desc = "Type Definition";
};
K = {
action = "hover";
desc = "Hover";
};
"<leader>cw" = {
action = "workspace_symbol";
desc = "Workspace Symbol";
};
"<f2>" = {
action = "rename";
desc = "Rename";
};
};
diagnostic = {
"<leader>cd" = {
action = "open_float";
desc = "Line Diagnostics";
};
"[d" = {
action = "goto_next";
desc = "Next Diagnostic";
};
"]d" = {
action = "goto_prev";
desc = "Previous Diagnostic";
};
};
};
};
}

45
config/neo-tree.nix Normal file
View file

@ -0,0 +1,45 @@
{ helpers, ... }:
{
plugins.neo-tree = {
enable = true;
window.mappings."h".__raw = ''
function(state)
local node = state.tree:get_node()
if node.type == "directory" and node:is_expanded() then
require("neo-tree.sources.filesystem").toggle_directory(state, node)
else
require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id())
end
end
'';
window.mappings."l".__raw = ''
function(state)
local node = state.tree:get_node()
if node.type == "directory" then
if not node:is_expanded() then
require("neo-tree.sources.filesystem").toggle_directory(state, node)
elseif node:has_children() then
require("neo-tree.ui.renderer").focus_node(state, node:get_child_ids()[1])
end
end
end
'';
window.mappings."s" = "";
window.mappings."<space>" = "";
};
keymaps = [
{
mode = [ "n" ];
key = "<leader>e";
action = helpers.mkRaw ''
function()
require("neo-tree.command").execute({ toggle = true })
end
'';
options = {
desc = "Toggle Neo-Tree";
};
}
];
}

View file

@ -0,0 +1,23 @@
{
plugins.rainbow-delimiters = {
enable = true;
highlight = [
"RainbowRed"
"RainbowYellow"
"RainbowBlue"
"RainbowOrange"
"RainbowGreen"
"RainbowViolet"
"RainbowCyan"
];
};
highlight = {
RainbowRed = { fg = "#E06C75"; };
RainbowYellow = { fg = "#E5C07B"; };
RainbowBlue = { fg = "#61AFEF"; };
RainbowOrange = { fg = "#D19A66"; };
RainbowGreen = { fg = "#98C379"; };
RainbowViolet = { fg = "#C678DD"; };
RainbowCyan = { fg = "#56B6C2"; };
};
}

21
config/telescope.nix Normal file
View file

@ -0,0 +1,21 @@
{ helpers, ... }:
{
plugins.telescope = {
enable = true;
};
keymaps = [
{
mode = [ "n" "i" ];
key = "<C-p>";
action = helpers.mkRaw ''
function()
require("telescope.builtin").find_files()
end
'';
options = {
desc = "Find files with telescope";
};
}
];
}

17
config/toggleterm.nix Normal file
View file

@ -0,0 +1,17 @@
{
plugins.toggleterm = {
enable = true;
};
keymaps = [
{
mode = [ "n" ];
key = "<leader>tt";
action = "<cmd>ToggleTerm<cr>";
options = {
desc = "Toggle terminal";
};
}
];
}

5
config/treesitter.nix Normal file
View file

@ -0,0 +1,5 @@
{
plugins.treesitter = {
enable = true;
};
}

5
config/which-key.nix Normal file
View file

@ -0,0 +1,5 @@
{
plugins.which-key = {
enable = true;
};
}

327
flake.lock Normal file
View file

@ -0,0 +1,327 @@
{
"nodes": {
"devshell": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722113426,
"narHash": "sha256-Yo/3loq572A8Su6aY5GP56knpuKYRvM2a1meP9oJZCw=",
"owner": "numtide",
"repo": "devshell",
"rev": "67cce7359e4cd3c45296fb4aaf6a19e2a9c757ae",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"flake-compat": {
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"revCount": 57,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1722555600,
"narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "8471fe90ad337a8074e957b69ca4d0089218391d",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-parts_2": {
"inputs": {
"nixpkgs-lib": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722555600,
"narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "8471fe90ad337a8074e957b69ca4d0089218391d",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"git-hooks": {
"inputs": {
"flake-compat": [
"nixvim",
"flake-compat"
],
"gitignore": "gitignore",
"nixpkgs": [
"nixvim",
"nixpkgs"
],
"nixpkgs-stable": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1723803910,
"narHash": "sha256-yezvUuFiEnCFbGuwj/bQcqg7RykIEqudOy/RBrId0pc=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "bfef0ada09e2c8ac55bbcd0831bd0c9d42e651ba",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"nixvim",
"git-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1723986931,
"narHash": "sha256-Fy+KEvDQ+Hc8lJAV3t6leXhZJ2ncU5/esxkgt3b8DEY=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "2598861031b78aadb4da7269df7ca9ddfc3e1671",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"type": "github"
}
},
"nix-darwin": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1723859949,
"narHash": "sha256-kiaGz4deGYKMjJPOji/JVvSP/eTefrIA3rAjOnOpXl4=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "076b9a905af8a52b866c8db068d6da475839d97b",
"type": "github"
},
"original": {
"owner": "lnl7",
"repo": "nix-darwin",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1723991338,
"narHash": "sha256-Grh5PF0+gootJfOJFenTTxDTYPidA3V28dqJ/WV7iis=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "8a3354191c0d7144db9756a74755672387b702ba",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1722555339,
"narHash": "sha256-uFf2QeW7eAHlYXuDktm9c25OxOyCoUOQmh5SZ9amE5Q=",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1723991338,
"narHash": "sha256-Grh5PF0+gootJfOJFenTTxDTYPidA3V28dqJ/WV7iis=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8a3354191c0d7144db9756a74755672387b702ba",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixvim": {
"inputs": {
"devshell": "devshell",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts_2",
"git-hooks": "git-hooks",
"home-manager": "home-manager",
"nix-darwin": "nix-darwin",
"nixpkgs": "nixpkgs_2",
"nuschtosSearch": "nuschtosSearch",
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1724127528,
"narHash": "sha256-fKtsvNQeLhPuz1O53x6Xxkd/yYecpolNXRq7mfvnXQk=",
"owner": "nix-community",
"repo": "nixvim",
"rev": "cb413995e1e101c76d755b7f131ce60c7ea3985d",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixvim",
"type": "github"
}
},
"nuschtosSearch": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1723969429,
"narHash": "sha256-BuewfNEXEf11MIkJY+uvWsdLu1dIvgJqntWChvNdALg=",
"owner": "NuschtOS",
"repo": "search",
"rev": "a05d1805f2a2bc47d230e5e92aecbf69f784f3d0",
"type": "github"
},
"original": {
"owner": "NuschtOS",
"repo": "search",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"nixvim": "nixvim"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1723808491,
"narHash": "sha256-rhis3qNuGmJmYC/okT7Dkc4M8CeUuRCSvW6kC2f3hBc=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "1d07739554fdc4f8481068f1b11d6ab4c1a4167a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

47
flake.nix Normal file
View file

@ -0,0 +1,47 @@
{
description = "A nixvim configuration";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixvim.url = "github:nix-community/nixvim";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs =
{ nixvim, flake-parts, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
perSystem =
{ pkgs, system, ... }:
let
nixvimLib = nixvim.lib.${system};
nixvim' = nixvim.legacyPackages.${system};
nixvimModule = {
inherit pkgs;
module = import ./config; # import the module directly
# You can use `extraSpecialArgs` to pass additional arguments to your module files
extraSpecialArgs = {
# inherit (inputs) foo;
};
};
nvim = nixvim'.makeNixvimWithModule nixvimModule;
in
{
checks = {
# Run `nix flake check .` to verify that your config is not broken
default = nixvimLib.check.mkTestDerivationFromNixvimModule nixvimModule;
};
packages = {
# Lets you run `nix run .` to start nixvim
default = nvim;
};
};
};
}