nix/home-manager/common/software/cli/nixvim/base.nix

349 lines
11 KiB
Nix
Raw Normal View History

2024-02-16 07:39:00 +01:00
{ inputs, pkgs, lib, theme, ... }: {
imports = [
2024-02-19 14:21:29 +01:00
./alpha.nix
inputs.nixvim.homeManagerModules.nixvim
2024-03-18 03:45:39 +01:00
] ++ lib.optional (builtins.isString theme) ../../../../../stylix/themes/${theme}/home-manager/nixvim.nix;
2024-02-15 02:43:27 +01:00
# https://github.com/nix-community/nixvim
2024-02-15 11:34:17 +01:00
# Docs:
# https://nix-community.github.io/nixvim/
programs.nixvim = {
enable = true;
viAlias = true;
vimAlias = true;
2024-02-15 02:43:27 +01:00
globals.mapleader = " ";
globals.maplocalleader = " ";
2024-02-15 02:43:27 +01:00
options = {
number = true;
2024-02-18 13:41:10 +01:00
wrap = false;
2024-02-19 06:51:48 +01:00
cursorline = true;
cursorcolumn = true;
shiftwidth = 2;
breakindent = true;
2024-02-18 13:41:10 +01:00
colorcolumn = "100";
showmode = false;
};
2024-02-16 07:39:00 +01:00
keymaps = let
map = mode: key: action: { mode = mode; key = key; action = action; };
nmap = key: action: map [ "n" ] key action;
nvmap = key: action: map [ "n" "v" ] key action;
2024-02-16 10:56:48 +01:00
# imap = key: action: map [ "i" ] key action;
desc = d: { options.desc = d; };
silent = { options.silent = true; };
expr = { options.expr = true; };
in [
# Unmap keys that aren't useful, or that we want to use for different things
(nvmap "<Space>" "<Nop>" // silent)
(nvmap "<Cr>" "<Nop>" // silent)
(nvmap "s" "<Nop>" // silent)
# Redo
(nmap "R" "<C-r>")
# Copy and paste
(nvmap "<leader>y" "\"+y" // desc "Cop[y] to clipboard")
(nvmap "<leader>p" "\"+p" // desc "[P]aste from clipboard")
# Jump to start/end of line
(nvmap "H" "0")
(nvmap "L" "$")
# Navigate up and down word wrapped text as if it were not word wrapped
(nmap "k" "v:count == 0 ? 'gk' : 'k'" // silent // expr)
(nmap "j" "v:count == 0 ? 'gj' : 'j'" // silent // expr)
# Center cursor when jumping foward or back
(nmap "<C-o>" "<C-o>zz")
(nmap "<C-i>" "<C-i>zz")
# Insert Mode
2024-02-15 02:43:27 +01:00
# Normal Mode
# NVimTree
2024-04-01 06:20:09 +02:00
(nmap "<leader>n" "<Nop>" // desc "[N]vimTree")
2024-02-17 13:13:25 +01:00
(nmap "<leader>nf" ":NvimTreeFocus<CR>" // desc "[F]ocus NvimTree")
(nmap "<leader>nt" ":NvimTreeToggle<CR>" // desc "[T]oggle NvimTree")
(nmap "<leader>ns" ":NvimTreeFindFile<CR>"// desc "[S]earch NvimTree")
(nmap "<leader>nc" ":NvimTreeClose<CR>" // desc "[C]lose NvimTree")
(nmap "<leader>nr" ":NvimTreeRefresh<CR>" // desc "[R]efresh NvimTree")
2024-04-01 06:20:09 +02:00
(nmap "<leader>nT" ":NoiceTelescope<CR>" // desc "Noice [T]elescope")
# ToggleTerm
2024-04-01 06:20:09 +02:00
(nmap "<leader>Tt" ":ToggleTerm<CR>" // desc "[T]oggle Terminal")
(nmap "<leader>Ts" ":TermSelect<CR>" // desc "[S]elect a terminal")
# Fugitive
2024-04-01 06:20:09 +02:00
(nmap "<leader>gc" ":Git cam \"" // desc "[C]ommit" )
(nmap "<leader>gp" ":Git push<CR>" // desc "Git [p]ush")
(nmap "<leader>gP" ":Git pull<CR>" // desc "[P]ull")
(nmap "<leader>ga" ":Git add " // desc "[A]dd file...")
(nmap "<leader>gb" ":Git blame<CR>" // desc "[B]lame")
(nmap "<leader>gd" ":Git diff<CR>" // desc "[D]iff")
# Trouble
2024-04-01 06:20:09 +02:00
(nmap "<leader>tf" ":Trouble<CR>" // desc "[F]ocus")
(nmap "<leader>tt" ":TroubleToggle<CR>" // desc "[T]oggle")
(nmap "<leader>tc" ":TroubleClose<CR>" // desc "[C]lose")
2024-04-01 05:38:00 +02:00
# Navbuddy
2024-04-01 06:20:09 +02:00
(nmap "<leader>N" ":Navbuddy<CR>" // desc "[N]avbuddy")
# Window Management
2024-04-01 06:20:09 +02:00
(nmap "<leader>wh" ":wincmd h<CR>" // desc "Move left")
(nmap "<leader>wl" ":wincmd l<CR>" // desc "Move right")
(nmap "<leader>wj" ":wincmd j<CR>" // desc "Move down")
(nmap "<leader>wk" ":wincmd k<CR>" // desc "Move up")
(nmap "<leader>wn" ":wincmd w<CR>" // desc "Move to next")
(nmap "<leader>wN" ":wincmd p<CR>" // desc "Move to previous")
(nmap "<leader>wc" ":wincmd c<CR>" // desc "[C]lose active window")
(nmap "<leader>woh" ":wincmd n<CR>" // desc "Open [H]orizontal window")
(nmap "<leader>wov" ":wincmd v<CR>" // desc "Open [V]ertical window")
# resize window
2024-04-01 06:20:09 +02:00
(nmap "<leader>wrh" ":resize " // desc "Resize Horizontal")
(nmap "<leader>wrv" ":vertical resize " // desc "Resize Vertical")
# Buffer Management
2024-04-01 06:20:09 +02:00
(nmap "<leader>bn" ":bnext<CR>" // desc "Next buffer")
(nmap "<leader>bN" ":bNext<CR>" // desc "Previous buffer")
(nmap "<leader>bc" ":bdelete<CR>" // desc "[c]lose buffer")
(nmap "<leader>bt" ":enew<CR>" // desc "New [T]ab")
2024-02-16 11:54:13 +01:00
# Multicursors
2024-04-01 06:20:09 +02:00
(nmap "<leader>ms" ":MCstart<CR>" // desc "[S]tart Multicorsor")
(nmap "<leader>mv" ":MCvisual<CR>" // desc "[V]isual Multicorsor")
(nmap "<leader>mc" ":MCclear<CR>" // desc "[C]lear Multicorsor")
(nmap "<leader>mu" ":MCunderCursor<CR>" // desc "Select [U]nder Corsor")
(nmap "<leader>mp" ":MCpattern<CR>" // desc "Select [P]attern")
];
2024-02-15 05:11:10 +01:00
plugins = {
2024-04-01 06:20:09 +02:00
# Testing
noice = {
enable = true;
popupmenu.enabled = true;
};
notify = {
enable = true;
topDown = true;
fps = 60;
stages = "slide";
};
2024-04-01 05:38:00 +02:00
# Git related
# Gutter information for git modifications
gitsigns.enable = true;
# git plugin for vim
fugitive.enable = true;
# pretty stuff
# Rainbow matching {} [] () 's
rainbow-delimiters.enable = true;
# Colorize hex colors inline
nvim-colorizer.enable = true;
# Nix related
# Nix language syntax highlighting / file type associations
nix.enable = true;
# Run nix develop / shell without exiting vim
nix-develop.enable = true;
# Efficiency
2024-02-16 11:13:19 +01:00
# Multicursor support
multicursors.enable = true;
# auto bracket completion
nvim-autopairs.enable = true;
2024-04-01 05:38:00 +02:00
# Indentation guides
indent-blankline.enable = true;
# Surround text blocks
surround.enable = true;
# Automatic indent
intellitab.enable = true;
# Code navigation
navbuddy.enable = true;
navbuddy.lsp.autoAttach = true;
# Layout Related
# winbar that uses nvim-navic in order to get LSP context from your language server.
barbecue.enable = true;
# tab bar like Firefox or Chrome
bufferline.enable = true;
# sidebar file browser
nvim-tree.enable = true;
# Terminal in vim
toggleterm.enable = true;
2024-04-01 05:38:00 +02:00
# Alerts / CodeActions
trouble.enable = true;
2024-04-01 05:38:00 +02:00
# Code Related
# Parser generator tool
treesitter.enable = true;
# Snippet engine for neovim
luasnip.enable = true;
cmp_luasnip.enable = true;
# CMP Addons
2024-02-16 10:56:48 +01:00
cmp-buffer.enable = true;
cmp-path.enable = true;
cmp-nvim-lsp.enable = true;
2024-04-01 05:38:00 +02:00
cmp-nvim-lsp-document-symbol.enable = true;
cmp-nvim-lsp-signature-help.enable = true;
2024-02-17 09:46:00 +01:00
# List of linters for nixvim
lint = {
enable = true;
lintersByFt = {
text = ["vale"];
json = ["jsonlint"];
markdown = ["vale"];
rst = ["vale"];
ruby = ["ruby"];
janet = ["janet"];
inko = ["inko"];
clojure = ["clj-kondo"];
dockerfile = ["hadolint"];
terraform = ["tflint"];
yaml = ["yamllint"];
nix = ["nix"];
};
};
2024-02-16 10:56:48 +01:00
# Popup to show shortcuts
which-key = {
enable = true;
registrations = {
"<leader>b" = "Manage buffers...";
"<leader>c" = "Colorscheme...";
"<leader>g" = "Git Options...";
"<leader>l" = "LSP Options...";
2024-04-01 06:20:09 +02:00
"<leader>n" = "NvimTree / Noice...";
"<leader>t" = "Trouble...";
"<leader>T" = "ToggleTerm...";
"<leader>w" = "Manage Windows...";
"<leader>wo" = "Open New...";
"<leader>wr" = "Resize...";
2024-02-16 11:54:13 +01:00
"<leader>m" = "Multicursor...";
};
};
2024-02-15 02:43:27 +01:00
# Airline / Powerline alternative
lualine = {
enable = true;
componentSeparators = {
2024-02-16 08:58:28 +01:00
right = "«";
left = "»";
};
2024-02-19 04:17:22 +01:00
sectionSeparators = {
right = "";
left = "";
};
};
2024-02-15 02:43:27 +01:00
telescope = {
enable = true;
extensions.fzf-native.enable = true;
keymaps = {
"<leader><leader>" = {
action = "find_files";
desc = "Search files by name";
};
"<leader>s" = {
action = "live_grep";
desc = "Search by live grep";
};
"<leader>bl" = {
action = "buffers";
desc = "[L]list open [B]uffers";
};
"<leader>h" = {
action = "help_tags";
desc = "Search [H]elp";
};
"<leader>W" = {
action = "grep_string";
desc = "Search for [W]ord under cursor";
};
"<leader>gs" = {
action = "git_status";
desc = "Search [G]it [S]tatus";
};
"<leader>gl" = {
action = "git_commits";
desc = "View [G]it [L]ogs";
};
"<leader>r" = {
action = "oldfiles";
desc = "Search [R]ecently opened files by name";
};
"<leader>cs" = {
action = "colorscheme";
desc = "Change [C]olor[s]cheme";
};
2024-02-15 02:43:27 +01:00
};
};
2024-02-15 02:43:27 +01:00
nvim-cmp = {
enable = true;
autoEnableSources = true;
mapping = {
"<C-Space>" = "cmp.mapping.complete()";
"<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 })";
"<S-Tab>" = {
action = "cmp.mapping.select_prev_item()";
modes = [
"i"
"s"
];
};
"<Tab>" = {
action = "cmp.mapping.select_next_item()";
modes = [
"i"
"s"
];
};
2024-02-15 02:43:27 +01:00
};
sources = [
{ name = "nvim_lua"; }
2024-04-01 05:38:00 +02:00
{ name = "nvim_lsp"; }
{ name = "nvim_lsp_signature_help"; }
{ name = "calc"; }
{ name = "path"; }
{ name = "buffer"; }
{ name = "luasnip"; }
2024-02-15 02:43:27 +01:00
];
2024-04-01 05:38:00 +02:00
snippet.expand = "luasnip";
window = {
completion.border = "rounded";
documentation.border = "rounded";
};
formatting = {
fields = [ "menu" "abbr" "kind" ];
# https://rsdlt.github.io/posts/rust-nvim-ide-guide-walkthrough-development-debug/
format = ''
function(entry, item)
local menu_icon ={
nvim_lsp = 'λ',
luasnip = '',
buffer = 'Ω',
path = '🖫',
}
item.menu = menu_icon[entry.source.name]
return item
end,
'';
};
};
};
colorschemes = {
tokyonight.enable = true;
gruvbox.enable = true;
catppuccin.enable = true;
dracula.enable = true;
oxocarbon.enable = true;
2024-02-15 02:43:27 +01:00
};
2024-03-30 07:27:21 +01:00
extraPlugins = with pkgs.vimPlugins; [
awesome-vim-colorschemes
everforest
onehalf
rose-pine
melange-nvim
];
};
2024-02-15 02:43:27 +01:00
}