bunch of neovim stuff

This commit is contained in:
cswimr 2025-02-04 08:26:49 -06:00
parent 3bfc56bf2a
commit 184afebce1
Signed by: cswimr
GPG key ID: 0EC431A8DA8F8087
16 changed files with 730 additions and 164 deletions

View file

@ -3,6 +3,7 @@
./keymaps.nix
./settings.nix
./plugins/autoclose.nix
./plugins/cmp.nix
./plugins/conform.nix
./plugins/dashboard.nix
@ -10,9 +11,11 @@
./plugins/lazygit.nix
./plugins/lsp.nix
./plugins/lualine.nix
./plugins/neo-tree.nix
#./plugins/rooter.nix
./plugins/oil.nix
./plugins/profile.nix
./plugins/rooter.nix
./plugins/snacks.nix
./plugins/telescope.nix
./plugins/treesitter.nix
];
}

View file

@ -1,5 +1,9 @@
{
programs.nixvim = {
globals = {
mapleader = " ";
maplocalleader = " ";
};
keymaps = [
{
mode = "n"; # Normal mode
@ -7,6 +11,42 @@
action = "<Nop>";
options.silent = true;
}
{
mode = "n";
key = "<A-Left>";
action = "<C-w>h";
options = {
desc = "Move Left";
silent = true;
};
}
{
mode = "n";
key = "<A-Down>";
action = "<C-w>j";
options = {
desc = "Move Down";
silent = true;
};
}
{
mode = "n";
key = "<A-Up>";
action = "<C-w>k";
options = {
desc = "Move Up";
silent = true;
};
}
{
mode = "n";
key = "<A-Right>";
action = "<C-w>l";
options = {
desc = "Move Right";
silent = true;
};
}
{
mode = "n";
key = "<Tab>";
@ -31,22 +71,45 @@
action = ":w<CR>";
options = {
desc = "Save Buffer to File";
silent = true;
silent = false;
};
}
{
mode = "n";
key = "<leader>q";
action = ":bd<CR>";
options = {
desc = "Close Buffer";
silent = false;
};
}
{
mode = "n";
key = "<leader>Q";
action = ":bd!<CR>";
options = {
desc = "Force Close Buffer";
silent = false;
};
}
{
mode = "n";
key = "<leader>`";
action = ":qa<CR>";
options = {
desc = "Quit All";
silent = false;
};
}
{
mode = "t";
key = "<C-Esc>";
action = "<C-\\><C-n>";
options = {
desc = "Exit Terminal Mode"; # why does Neovim not have this by default??? wtf???
silent = true;
};
}
];
globals = {
mapleader = " ";
maplocalleader = " ";
};
};
}

View file

@ -0,0 +1,10 @@
{
programs.nixvim = {
plugins = {
nvim-autopairs = {
enable = true;
settings = { };
};
};
};
}

View file

@ -14,7 +14,7 @@
"<C-d>" = "cmp.mapping.scroll_docs(-4)";
"<C-e>" = "cmp.mapping.close()";
"<C-f>" = "cmp.mapping.scroll_docs(4)";
"<CR>" = "cmp.mapping.confirm({ select = true })";
"<CR>" = "cmp.mapping.confirm({ select = false })";
"<S-Tab>" = "cmp.mapping(cmp.mapping.select_prev_item(), {'i', 's'})";
"<Tab>" = "cmp.mapping(cmp.mapping.select_next_item(), {'i', 's'})";
};

View file

@ -47,94 +47,121 @@
"trim_whitespace"
"trim_newlines"
];
format_on_save = # Lua
''
function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
if slow_format_filetypes[vim.bo[bufnr].filetype] then
return
end
local function on_format(err)
if err and err:match("timeout$") then
slow_format_filetypes[vim.bo[bufnr].filetype] = true
end
end
return { timeout_ms = 200, lsp_fallback = true }, on_format
end
'';
format_after_save = # Lua
''
function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
if not slow_format_filetypes[vim.bo[bufnr].filetype] then
return
end
return { lsp_fallback = true }
end
'';
log_level = "warn";
notify_on_error = true;
notify_no_formatters = true;
default_format_opts = {
lsp_format = "fallback";
timeout_ms = 300;
};
log_level = "warn";
notify_on_error = true;
notify_no_formatters = true;
default_format_opts = {
lsp_format = "fallback";
timeout_ms = 300;
};
formatters = {
shellcheck = {
command = lib.getExe pkgs.shellcheck;
};
formatters = {
shellcheck = {
command = lib.getExe pkgs.shellcheck;
};
shfmt = {
command = lib.getExe pkgs.shfmt;
};
shellharden = {
command = lib.getExe pkgs.shellharden;
};
nixfmt = {
command = lib.getExe pkgs.nixfmt-rfc-style;
};
stylua = {
command = lib.getExe pkgs.stylua;
};
clang-format = {
command = "${pkgs.clang-tools}/bin/clang-format";
};
csharpier = {
command = lib.getExe pkgs.csharpier;
};
ruff_fix = {
command = lib.getExe pkgs.ruff;
};
ruff_format = {
command = lib.getExe pkgs.ruff;
};
ruff_organize_imports = {
command = lib.getExe pkgs.ruff;
};
shfmt = {
command = lib.getExe pkgs.shfmt;
};
shellharden = {
command = lib.getExe pkgs.shellharden;
};
nixfmt = {
command = lib.getExe pkgs.nixfmt-rfc-style;
};
stylua = {
command = lib.getExe pkgs.stylua;
};
clang-format = {
command = "${pkgs.clang-tools}/bin/clang-format";
};
csharpier = {
command = lib.getExe pkgs.csharpier;
};
ruff_fix = {
command = lib.getExe pkgs.ruff;
};
ruff_format = {
command = lib.getExe pkgs.ruff;
};
ruff_organize_imports = {
command = lib.getExe pkgs.ruff;
};
};
format_on_save = # lua
''
function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
if slow_format_filetypes[vim.bo[bufnr].filetype] then
return
end
local function on_format(err)
if err and err:match("timeout$") then
slow_format_filetypes[vim.bo[bufnr].filetype] = true
end
end
return { timeout_ms = 200, lsp_fallback = true }, on_format
end
'';
format_after_save = # lua
''
function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
if not slow_format_filetypes[vim.bo[bufnr].filetype] then
return
end
return { lsp_fallback = true }
end
'';
};
luaConfig.post = ''
vim.api.nvim_create_user_command("Format", function(args)
local range = nil
if args.count ~= -1 then
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
range = {
start = { args.line1, 0 },
["end"] = { args.line2, end_line:len() },
}
end
require("conform").format({ async = true, lsp_format = "fallback", range = range })
end, { range = true })
'';
luaConfig.post = # lua
''
slow_format_filetypes = {} -- Filetypes that are slow to format, and should be formatted after saving a buffer instead of before
require("conform").formatters.injected = {
options = {
lang_to_ext = {
c = "c",
cpp = "cpp",
cs = "cs",
csharp = "cs",
lua = "lua",
nix = "nix",
python = "py",
bash = "sh",
javascript = "js",
javascriptreact = "jsx",
typescript = "ts",
typescriptreact = "tsx",
markdown = "md",
yaml = "yaml",
json = "json",
svelte = "svelte",
html = "html",
css = "css",
graphql = "graphql",
},
},
}
vim.api.nvim_create_user_command("Format", function(args)
local range = nil
if args.count ~= -1 then
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
range = {
start = { args.line1, 0 },
["end"] = { args.line2, end_line:len() },
}
end
require("conform").format({ async = true, lsp_format = "fallback", range = range })
end, { range = true })
'';
};
};
keymaps = [

View file

@ -5,7 +5,7 @@
extraPlugins = [
(pkgs.vimUtils.buildVimPlugin {
# https://codeberg.org/esensar/nvim-dev-container
name = "nvim-dev-container";
name = "devcontainer";
src = pkgs.fetchgit {
url = "https://codeberg.org/esensar/nvim-dev-container";
rev = "ba9666bdaec23cfe8087c0b6bb0a15c93ec8ba87";
@ -16,5 +16,79 @@
extraConfigLua = ''
require("devcontainer").setup({})
'';
keymaps = [
{
mode = "n";
key = "<leader>d";
action = "";
options = {
desc = "Manage Dev Container";
silent = true;
};
}
{
mode = "n";
key = "<leader>ds";
action = ":DevcontainerStart<CR>";
options = {
desc = "Start Dev Container";
silent = false;
};
}
{
mode = "n";
key = "<leader>dc";
action = ":DevcontainerStopAll<CR>";
options = {
desc = "Stop Dev Container";
silent = false;
};
}
{
mode = "n";
key = "<leader>dr";
action = ":DevcontainerRemoveAll<CR>";
options = {
desc = "Remove Dev Container";
silent = false;
};
}
{
mode = "n";
key = "<leader>da";
action = ":DevcontainerAttach<CR>";
options = {
desc = "Attach to Dev Container";
silent = false;
};
}
{
mode = "n";
key = "<leader>de";
action = ":DevcontainerExec ";
options = {
desc = "Execute Command in Dev Container";
silent = false;
};
}
{
mode = "n";
key = "<leader>dl";
action = ":DevcontainerLogs<CR>";
options = {
desc = "Open Dev Container Logs";
silent = true;
};
}
{
mode = "n";
key = "<leader>dz";
action = ":DevcontainerEditNearestConfig<CR>";
options = {
desc = "Edit Nearest devcontainer.json";
silent = false;
};
}
];
};
}

View file

@ -9,37 +9,41 @@
(callPackage ../../../packages/luau-lsp.nix { inherit pkgs; })
];
plugins = {
lsp-status = {
enable = true;
};
lsp = {
enable = true;
postConfig = ''
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup('lsp_attach_disable_ruff_hover', { clear = true }),
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client == nil then
return
end
if client.name == 'ruff' then
-- Disable hover in favor of Pyright
client.server_capabilities.hoverProvider = false
end
end,
desc = 'LSP: Disable hover capability from Ruff',
})
require('lspconfig').basedpyright.setup { settings = { pyright = { disableOrganizeImports = true } } }
require('lspconfig').ruff.setup { }
require('lspconfig').nil_ls.setup {
cmd = { "${pkgs.nil}/bin/nil" },
settings = {
['nil'] = {
formatting = {
command = { "${pkgs.nixfmt-rfc-style}/bin/nixfmt" },
postConfig = # lua
''
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup('lsp_attach_disable_ruff_hover', { clear = true }),
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client == nil then
return
end
if client.name == 'ruff' then
-- Disable hover in favor of Pyright
client.server_capabilities.hoverProvider = false
end
end,
desc = 'LSP: Disable hover capability from Ruff',
})
require('lspconfig').basedpyright.setup { settings = { pyright = { disableOrganizeImports = true } } }
require('lspconfig').ruff.setup { }
require('lspconfig').nil_ls.setup {
cmd = { "${pkgs.nil}/bin/nil" },
settings = {
['nil'] = {
formatting = {
command = { "${pkgs.nixfmt-rfc-style}/bin/nixfmt" },
},
},
},
},
}
--require('luau-lsp').setup { }
'';
}
--require('luau-lsp').setup { }
'';
};
trouble = {
enable = true;

View file

@ -1,8 +1,111 @@
{ pkgs, ... }:
{
programs.nixvim = {
plugins.lualine = {
enable = true;
settings = { };
autoLoad = true;
settings = {
options = {
globalstatus = true;
ignore_focus = [
"neo-tree"
"nvim-tree"
"mini-files"
"TelescopePrompt"
];
};
sections = {
lualine_a = [
"mode"
];
lualine_b = [
"branch"
];
lualine_c = [
"filename"
"diff"
];
lualine_x = [
"diagnostics"
{
__unkeyed-1 = {
__raw = ''
function()
local msg = ""
local buf_ft = vim.api.nvim_buf_get_option(0, 'filetype')
local clients = vim.lsp.get_active_clients()
if next(clients) == nil then
return msg
end
for _, client in ipairs(clients) do
local filetypes = client.config.filetypes
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then
return client.name
end
end
return msg
end
'';
};
color = {
fg = "#ffffff";
};
icon = "";
}
"encoding"
"fileformat"
"filetype"
];
lualine_y = [
{
__unkeyed-1 = "aerial";
colored = true;
cond = {
__raw = ''
function()
local buf_size_limit = 1024 * 1024
if vim.api.nvim_buf_get_offset(0, vim.api.nvim_buf_line_count(0)) > buf_size_limit then
return false
end
return true
end
'';
};
dense = false;
dense_sep = ".";
depth = {
__raw = "nil";
};
sep = " ) ";
}
];
lualine_z = [
{
__unkeyed-1 = "location";
}
];
};
tabline = {
lualine_a = [
{
__unkeyed-1 = "buffers";
symbols = {
alternate_file = "";
};
disabled_filetypes = [
"TelescopePrompt"
];
}
];
lualine_z = [
"tabs"
];
};
};
};
extraPlugins = with pkgs.vimPlugins; [
copilot-lualine
];
};
}

View file

@ -0,0 +1,9 @@
{
programs.nixvim = {
plugins = {
lz-n = {
enable = true;
};
};
};
}

View file

@ -1,19 +0,0 @@
{
programs.nixvim = {
plugins.neo-tree = {
enable = true;
enableGitStatus = true;
};
keymaps = [
{
mode = "n";
key = "<leader>e";
action = ":Neotree toggle<CR>";
options = {
desc = "Toggle Neotree";
silent = true;
};
}
];
};
}

View file

@ -0,0 +1,23 @@
{
programs.nixvim = {
plugins = {
oil = {
enable = true;
settings = {
default_file_explorer = false;
};
};
};
keymaps = [
{
mode = "n";
key = "<leader>o";
action = "<CMD>Oil --float<CR>";
options = {
desc = "Manage Files";
silent = true;
};
}
];
};
}

View file

@ -0,0 +1,63 @@
{ pkgs, ... }:
{
programs.nixvim = {
extraPlugins = [
(pkgs.vimUtils.buildVimPlugin {
# https://github.com/stevearc/profile.nvim
name = "profile";
src = pkgs.fetchFromGitHub {
owner = "stevearc";
repo = "profile.nvim";
rev = "f2d2cf5eae9ba3b9ca6bc148507d153f3e6ae282";
sha256 = "sha256-xnScKSrlm1N3cw+hPmUd97b1gjue7FG+1f9genzw5yM=";
};
})
];
extraConfigLuaPre = # lua
''
local should_profile = os.getenv("NVIM_PROFILE")
if should_profile then
require("profile").instrument_autocmds()
if should_profile:lower():match("^start") then
require("profile").start("*")
else
require("profile").instrument("*")
end
end
local function toggle_profile()
local prof = require("profile")
if prof.is_recording() then
prof.stop()
vim.ui.input({ prompt = "Save profile to:", completion = "file", default = "profile.json" }, function(filename)
if filename then
prof.export(filename)
vim.notify(string.format("Wrote %s", filename))
end
end)
else
vim.ui.select({ "yes", "no" }, { prompt = "Would you like to start profiling?", format_item = function(item)
return item
end,
}, function(choice)
if choice == "yes" then
prof.start("*")
end
end)
end
end
vim.keymap.set("", "<leader>p", toggle_profile, { desc = "Toggle Profiling", silent = true })
'';
# keymaps = [
# {
# mode = "n";
# key = "<leader>p";
# action = "toggle_profile";
# options = {
# desc = "Toggle Profiling";
# silent = true;
# };
# }
# ];
};
}

View file

@ -2,19 +2,10 @@
{
programs.nixvim = {
extraPlugins = [
(pkgs.vimUtils.buildVimPlugin {
# https://codeberg.org/esensar/nvim-dev-container
name = "vim-rooter";
src = pkgs.fetchFromGitHub {
owner = "airblade";
repo = "vim-rooter";
rev = "51402fb77c4d6ae94994e37dc7ca13bec8f4afcc";
sha256 = "sha256-JrpYcQ/mJQQUvDdsYlaaep6J6/irDIrCAb8W49JHqzk=";
};
})
pkgs.vimPlugins.vim-rooter
];
extraConfigLua = ''
require("vim-rooter").setup({})
'';
globals = {
rooter_patterns = [ ".git" ];
};
};
}

View file

@ -2,15 +2,24 @@
{
programs.nixvim = {
extraPackages = with pkgs; [
ripgrep
fd
plocate
glow
];
plugins = {
aerial.enable = true;
neoclip.enable = true;
telescope = {
enable = true;
extensions = {
fzf-native.enable = true;
file-browser = {
enable = true;
settings = {
hijack_netrw = false;
};
};
};
enabledExtensions = [
"repo"
@ -26,7 +35,7 @@
};
extraPlugins = [
(pkgs.vimUtils.buildVimPlugin {
# https://codeberg.org/esensar/nvim-dev-container
# https://github.com/cljoly/telescope-repo.nvim
name = "telescope-repo.nvim";
src = pkgs.fetchFromGitHub {
owner = "cljoly";
@ -36,6 +45,43 @@
};
})
];
# https://github.com/nvim-telescope/telescope.nvim/issues/2806#issuecomment-1904877188
autoGroups.find_files_hijack_netrw.clear = true;
autoCmd = [
{
event = "VimEnter";
pattern = "*";
once = true;
callback.__raw = # lua
''
function()
pcall(vim.api.nvim_clear_autocmds, { group = "FileExplorer" })
end
'';
}
{
event = "BufEnter";
group = "find_files_hijack_netrw";
pattern = "*";
callback.__raw = # lua
''
function()
vim.schedule(function()
-- Early return if netrw or not a directory
if vim.bo[0].filetype == "netrw" or vim.fn.isdirectory(vim.fn.expand("%:p")) == 0 then
return
end
vim.api.nvim_buf_set_option(0, "bufhidden", "wipe")
require("telescope.builtin").find_files({
cwd = vim.fn.expand("%:p:h"),
})
end)
end
'';
}
];
keymaps = [
{
mode = "n";
@ -55,6 +101,15 @@
silent = true;
};
}
{
mode = "n";
key = "<leader>te";
action = ":Telescope file_browser<CR>";
options = {
desc = "File Explorer";
silent = true;
};
}
{
mode = "n";
key = "<leader>tg";
@ -64,6 +119,15 @@
silent = true;
};
}
{
mode = "n";
key = "<leader>ta";
action = ":Telescope aerial<CR>";
options = {
desc = "Aerial";
silent = true;
};
}
{
mode = "n";
key = "<leader>tb";
@ -109,6 +173,61 @@
silent = true;
};
}
{
mode = "n";
key = "<leader>tm";
action = ":Telescope man_pages<CR>";
options = {
desc = "Man Pages";
silent = true;
};
}
{
mode = "n";
key = "<leader>tn";
action = ":Telescope vim_options<CR>";
options = {
desc = "Vim Options";
silent = true;
};
}
# Git
{
mode = "n";
key = "<leader>tgc";
action = ":Telescope git_commits<CR>";
options = {
desc = "Git Commits";
silent = true;
};
}
{
mode = "n";
key = "<leader>tgb";
action = ":Telescope git_branches<CR>";
options = {
desc = "Git Branches";
silent = true;
};
}
{
mode = "n";
key = "<leader>tgs";
action = ":Telescope git_status<CR>";
options = {
desc = "Git Status";
silent = true;
};
}
{
mode = "n";
key = "<leader>tgS";
action = ":Telescope git_stash<CR>";
options = {
desc = "Git Stash";
silent = true;
};
}
];
};
}

View file

@ -0,0 +1,70 @@
{ pkgs, ... }:
{
programs.nixvim = {
plugins = {
treesitter-refactor = {
enable = true;
highlightCurrentScope.enable = true;
highlightDefinitions.enable = true;
navigation = {
enable = true;
keymaps = {
gotoDefinition = null;
gotoDefinitionLspFallback = "gnd";
gotoNextUsage = "<a-*>";
gotoPreviousUsage = "<a-#>";
listDefinitions = "gnD";
listDefinitionsToc = "gO";
};
};
smartRename = {
enable = true;
keymaps.smartRename = "grr";
};
};
treesitter-context = {
enable = true;
};
treesitter = {
enable = true;
settings = {
indent.enable = true;
incremental_selection = {
enable = true;
keymaps = {
init_selection = "gnn";
node_incremental = "grn";
scope_incremental = "grc";
node_decremental = "grm";
};
};
highlight = {
enable = true;
};
};
grammarPackages = with pkgs.vimPlugins.nvim-treesitter.builtGrammars; [
bash
c
cpp
css
dockerfile
go
graphql
html
javascript
json
jsonc
lua
python
regex
ruby
rust
svelte
toml
typescript
yaml
];
};
};
};
}

View file

@ -5,18 +5,37 @@
enable = true;
viAlias = true;
vimAlias = true;
colorschemes.catppuccin.enable = true;
clipboard.register = [
"unnamed"
"unnamedplus"
];
performance = {
byteCompileLua = {
enable = true;
configs = true;
initLua = true;
nvimRuntime = true;
plugins = true;
};
};
# extraFiles = {
# "queries/nix/injections.scm".text = lib.mkForce ''
# (string_literal
# (string_fragment) @lua
# (#match? @lua ".*")
# )
# '';
# };
colorscheme = "catppuccin";
colorschemes.catppuccin = {
enable = true;
#lazyLoad.enable = true;
};
plugins = {
# lz-n = {
# enable = true;
# lazyLoad = {
# enable = true;
# };
# };
treesitter.enable = true;
aerial.enable = true;
direnv.enable = true;
web-devicons.enable = true;
bufferline.enable = true;
#bufferline.enable = true;
glow.enable = true;
gitblame.enable = true;
git-conflict.enable = true;
@ -24,9 +43,16 @@
nix-develop.enable = true;
image.enable = true;
which-key.enable = true;
neocord.enable = true;
neocord.enable = false;
rainbow-delimiters.enable = true;
neoconf.enable = true;
colorizer.enable = true;
comment.enable = true;
dotnet.enable = true;
sqlite-lua.enable = true;
};
extraConfigVim = ''
set number " enable number lines
'';
};
}