feat: Init nvim from jalil-salame/nvim-config

Step one of Issue #15
This commit is contained in:
Jalil David Salamé Messina 2024-02-16 20:10:20 +01:00
parent a4dbd22402
commit d47b04a887
Signed by: jalil
GPG key ID: F016B9E770737A0B
11 changed files with 538 additions and 97 deletions

93
nvim/augroups.nix Normal file
View file

@ -0,0 +1,93 @@
{
highlightOnYank.name = "highlightOnYank";
highlightOnYank.autocmds = [
{
event = "TextYankPost";
pattern = "*";
luaCallback = ''
vim.highlight.on_yank {
higroup = (
vim.fn['hlexists'] 'HighlightedyankRegion' > 0 and 'HighlightedyankRegion' or 'IncSearch'
),
timeout = 200,
}
'';
}
];
runLinter.name = "runLinter";
runLinter.autocmds = [
{
event = "BufWritePost";
pattern = "*";
luaCallback = ''
require("lint").try_lint()
'';
}
];
restoreCursorPosition.name = "restoreCursorPosition";
restoreCursorPosition.autocmds = [
{
event = "BufReadPost";
pattern = "*";
luaCallback = ''
if vim.fn.line '\'"' > 0 and vim.fn.line '\'"' <= vim.fn.line '$' then
vim.cmd [[execute "normal! g'\""]]
end
'';
}
];
lspConfig.name = "lspConfig";
lspConfig.autocmds = [
{
event = "LspAttach";
pattern = "*";
luaCallback =
let
opts = "noremap = true, buffer = bufnr";
in
''
local bufnr = opts.buf
local client = vim.lsp.get_client_by_id(opts.data.client_id)
local capabilities = client.server_capabilities
-- Set Omnifunc if supported
if capabilities.completionProvider then
vim.bo[bufnr].omnifunc = "v:lua.vim.lsp.omnifunc"
end
-- Enable inlay hints if supported
if capabilities.inlayHintProvider then
vim.lsp.inlay_hint.enable(bufnr, true)
end
vim.keymap.set('n', -- Some Lsp servers do not advertise inlay hints properly so enable this keybinding regardless
'<space>ht',
function()
vim.lsp.inlay_hint.enable(0, not vim.lsp.inlay_hint.is_enabled())
end,
{ desc = '[H]ints [T]oggle', ${opts} }
)
-- Enable hover if supported
if capabilities.hoverProvider then
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = 'Hover Documentation', ${opts} })
end
-- Enable rename if supported
if capabilities.renameProvider then
vim.keymap.set('n', '<leader>r', vim.lsp.buf.rename, { desc = '[R]ename', ${opts} })
end
-- Enable code actions if supported
if capabilities.codeActionProvider then
vim.keymap.set({ 'n', 'v' }, '<leader>fa', vim.lsp.buf.code_action, { desc = '[F]ind Code [A]ctions', ${opts} })
end
-- Enable formatting if supported
if capabilities.documentFormattingProvider then
vim.keymap.set('n', '<leader>w', function() vim.lsp.buf.format { async = true } end, { desc = 'Format Buffer', ${opts} })
end
-- Other keybinds
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { desc = '[G]o to [D]efinition', ${opts} })
vim.keymap.set('n', 'gt', vim.lsp.buf.type_definition, { desc = '[G]o to [T]ype Definition', ${opts} })
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { desc = '[G]o to [I]mplementation', ${opts} })
'';
}
];
}

90
nvim/default.nix Normal file
View file

@ -0,0 +1,90 @@
{ pkgs, ... }: {
programs.nixneovim = {
enable = true;
package = pkgs.neovim-nightly;
defaultEditor = true;
colorschemes.gruvbox-nvim = {
enable = true;
bold = true;
transparentBg = true;
trueColor = true;
};
globals.mapleader = " ";
options = import ./options.nix;
plugins = import ./plugins;
mappings = import ./mappings.nix;
augroups = import ./augroups.nix;
extraPlugins = builtins.attrValues {
inherit (pkgs.vimExtraPlugins) dressing-nvim rustaceanvim idris2-nvim nui-nvim nvim-lint;
inherit (pkgs.vimPlugins) lualine-lsp-progress nvim-web-devicons FTerm-nvim cmp-cmdline formatter-nvim;
};
# Formatting
extraPackages = builtins.attrValues {
# Formatters
inherit (pkgs) stylua shfmt taplo yamlfmt alejandra;
};
extraLuaPreConfig = ''
-- Lua Pre Config
if vim.fn.has 'termguicolors' then
-- Enable RGB colors
vim.g.termguicolors = true
end
-- Useful function
local has_words_before = function()
-- unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0
and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil
end
-- END: Lua Pre Config
'';
extraLuaPostConfig = ''
do -- Setup cmp-cmdline
local cmp = require "cmp"
cmp.setup.cmdline("/", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources { {name = "rg" }, { name = "buffer" } },
})
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({ { name = "path" } }, { { name = "cmdline" } })
})
end
do -- Setup dressing.nvim
-- require("dressing").setup()
end
do -- Setup formatter.nvim
-- local util = require "formatter.util"
require("formatter").setup {
logging = true,
log_level = vim.log.levels.WARN,
["*"] = { require("formatter.filetypes.any").remove_trailing_whitespace },
-- Filetype Formatting
c = { require("formatter.filetypes.c").clangformat },
sh = { require("formatter.filetypes.sh").shfmt },
cpp = { require("formatter.filetypes.cpp").clangformat },
lua = { require("formatter.filetypes.lua").stylua },
nix = { require("formatter.filetypes.nix").alejandra },
zig = { require("formatter.filetypes.zig").zigfmt },
rust = { require("formatter.filetypes.rust").rustfmt },
toml = { require("formatter.filetypes.toml").taplo },
yaml = { require("formatter.filetypes.yaml").yamlfmt },
}
end
do -- Setup idris2-nvim
require("idris2").setup { }
end
do -- Setup nvim-lint
require("lint").linters_by_ft = {
latex = { "chktex", "typos" },
}
end
'';
};
}

91
nvim/mappings.nix Normal file
View file

@ -0,0 +1,91 @@
{
# Quickfix
normal."<leader>qo" = {
action = "'<cmd>Copen<CR>'";
desc = "Quickfix Open";
};
normal."<leader>qq" = {
action = "'<cmd>cclose<CR>'";
desc = "Quickfix Quit";
};
normal."<leader>qj" = {
action = "'<cmd>cnext<CR>'";
desc = "Quickfix next [J]";
};
normal."<leader>qk" = {
action = "'<cmd>cprev<CR>'";
desc = "Quickfix previous [K]";
};
# Open or create file
normal."<leader>gf" = {
action = "'<cmd>e <cfile><CR>'";
desc = "Go to File";
};
# Keep Selection when indenting
visualOnly.">" = {
action = "'>gv'";
desc = "Indent Selection";
};
visualOnly."<" = {
action = "'<gv'";
desc = "Deindent Selection";
};
# Diagnostics
normal."<leader>dj" = {
action = "vim.diagnostic.goto_next";
desc = "Diagnostics next [J]";
};
normal."<leader>dk" = {
action = "vim.diagnostic.goto_prev";
desc = "Diagnostics previous [K]";
};
normal."<leader>xx" = {
action = "require('trouble').toggle";
desc = "Toggle trouble";
};
normal."<leader>xw" = {
action = "function() require('trouble').toggle('workspace_diagnostics') end";
desc = "Toggle Workspace trouble";
};
normal."<leader>xd" = {
action = "function() require('trouble').toggle('document_diagnostics') end";
desc = "Toggle Document trouble";
};
normal."<leader>xq" = {
action = "function() require('trouble').toggle('quickfix') end";
desc = "Toggle Quickfix trouble";
};
normal."<leader>xl" = {
action = "function() require('trouble').toggle('loclist') end";
desc = "Toggle Loclist trouble";
};
normal."gR" = {
action = "function() require('trouble').toggle('lsp_references') end";
desc = "Toggle lsp References trouble";
};
# Telescope
normal."<leader>ff" = {
action = "require('telescope.builtin').find_files";
desc = "Find Files";
};
normal."<leader>fg" = {
action = "require('telescope.builtin').live_grep";
desc = "Find Grep";
};
normal."<leader>fh" = {
action = "require('telescope.builtin').help_tags";
desc = "Find Help";
};
normal."<leader>fb" = {
action = "require('telescope.builtin').buffers";
desc = "Find Buffer";
};
normal."<leader>fd" = {
action = "require('telescope.builtin').diagnostics";
desc = "Find Diagnostics";
};
normal."<leader>fq" = {
action = "require('telescope.builtin').quickfix";
desc = "Find Quickfix";
};
}

22
nvim/options.nix Normal file
View file

@ -0,0 +1,22 @@
{
# Appearance
number = true;
relativenumber = true;
colorcolumn = "+1";
cursorline = true;
wrap = false;
splitright = true;
# Tabs & indentation
smarttab = true;
autoindent = true;
smartindent = true;
# Search path
path = ".,/usr/include,**";
wildmenu = true;
hlsearch = true;
incsearch = true;
ignorecase = true; # Search ignores cases
smartcase = true; # Unless it has a capital letter
# Enable local configuration :h 'exrc'
exrc = true; # safe since nvim 0.9
}

88
nvim/plugins/cmp.nix Normal file
View file

@ -0,0 +1,88 @@
{
enable = true;
# Snippets
snippet.luasnip.enable = true;
# Completion Sources
sources = {
buffer.enable = true;
buffer.groupIndex = 3;
calc.enable = true;
calc.groupIndex = 2;
conventionalcommits.enable = true;
conventionalcommits.groupIndex = 1;
# cmdline.enable = true;
crates.enable = true;
crates.groupIndex = 1;
digraphs.enable = true;
digraphs.groupIndex = 3;
# emoji.enable = true;
# fuzzy_buffer.enable = true;
# fuzzy_path.enable = true;
luasnip.enable = true;
luasnip.groupIndex = 1;
nvim_lsp.enable = true;
nvim_lsp.groupIndex = 1;
nvim_lsp_document_symbol.enable = true;
nvim_lsp_document_symbol.groupIndex = 1;
nvim_lsp_signature_help.enable = true;
nvim_lsp_signature_help.groupIndex = 1;
path.enable = true;
path.groupIndex = 2;
# rg.enable = true;
spell.enable = true;
spell.groupIndex = 2;
treesitter.enable = true;
treesitter.groupIndex = 2;
zsh.enable = true;
zsh.groupIndex = 1;
};
# Menu Icons
formatting.format = "require('lspkind').cmp_format { mode = 'symbol', maxwidth = 50 }";
mappingPresets = [ "insert" ];
mapping = {
"<C-n>" = {
modes = [ "i" "s" ];
action = ''
function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif require("luasnip").expand_or_jumpable() then
require("luasnip").expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end
'';
};
"<C-p>" = {
modes = [ "i" "s" ];
action = ''
function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif require("luasnip").jumpable(-1) then
require("luasnip").jump(-1)
else
fallback()
end
end
'';
};
"<C-u>" = ''
cmp.mapping(function(fallback)
if require("luasnip").choice_active() then
require("luasnip").next_choice()
else
fallback()
end
end)
'';
"<C-b>" = "cmp.mapping.scroll_docs(-4)";
"<C-f>" = "cmp.mapping.scroll_docs(4)";
"<C-Space>" = "cmp.mapping.complete {}";
"<C-e>" = "cmp.mapping.close()";
"<CR>" = "cmp.mapping.confirm { select = true }";
};
}

17
nvim/plugins/default.nix Normal file
View file

@ -0,0 +1,17 @@
{
colorizer.enable = true;
colorizer.userDefaultOptions.names = false; # disable named colors (i.e. red)
gitsigns.enable = true;
lspconfig = import ./lspconfig.nix;
lspkind.enable = true;
lualine = import ./lualine.nix;
luasnip.enable = true;
luasnip.extraConfig = { update_events = "TextChanged,TextChangedI"; };
nvim-cmp = import ./cmp.nix;
telescope.enable = true;
treesitter.enable = true;
treesitter.indent = true;
treesitter.incrementalSelection.enable = true;
treesitter-context.enable = true;
trouble.enable = true;
}

View file

@ -0,0 +1,19 @@
{
enable = true;
servers.bashls.enable = true;
servers.clangd.enable = true;
servers.html.enable = true;
# servers.lua-language-server.enable = true;
servers.jsonls.enable = true;
servers.nil.enable = true;
servers.ocamllsp.enable = true;
servers.pyright.enable = true;
servers.rnix-lsp.enable = true;
servers.ruff-lsp.enable = true;
# servers.rust-analyzer.enable = true;
# servers.serve_d.enable = true;
servers.taplo.enable = true;
servers.texlab.enable = true;
servers.typst-lsp.enable = true;
# servers.vimls.enable = true;
}

50
nvim/plugins/lualine.nix Normal file
View file

@ -0,0 +1,50 @@
{
enable = true;
theme = "gruvbox";
sections = {
lualine_a = [ "mode" ];
lualine_b = [ "filename" "branch" ];
lualine_c = [
{
lsp_progress = {
separators = {
component = " ";
progress = " | ";
percentage = {
pre = "";
post = "%% ";
};
title = {
pre = "";
post = ": ";
};
lsp_client_name = {
pre = "[";
post = "]";
};
spinner = {
pre = "";
post = "";
};
message = {
pre = "(";
post = ")";
commenced = "In Progress";
completed = "Completed";
};
};
display_components = [ "lsp_client_name" "spinner" "title" "percentage" "message" ];
timer = {
progress_enddelay = 500;
spinner = 1000;
lsp_client_name_enddelay = 1000;
};
spinner_symbols = [ "🌑 " "🌒 " "🌓 " "🌔 " "🌕 " "🌖 " "🌗 " "🌘 " ];
};
}
];
lualine_x = [ ];
lualine_y = [ "encoding" "fileformat" "filetype" ];
lualine_z = [ "location" ];
};
}