From 013e5ce859323bd6c4b3a2c0f51e7cf392c85d66 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 26 May 2024 01:51:57 +0100 Subject: [PATCH] rice nixvim --- home/common/core/default.nix | 5 + home/common/core/nixvim.nix | 356 ++++++++++++++++++++++++++++++++++ home/fileserver.nix | 1 + home/users/sam/default.nix | 1 - hosts/common/core/default.nix | 2 +- 5 files changed, 363 insertions(+), 2 deletions(-) create mode 100644 home/common/core/nixvim.nix diff --git a/home/common/core/default.nix b/home/common/core/default.nix index 48a1333..df84dac 100644 --- a/home/common/core/default.nix +++ b/home/common/core/default.nix @@ -2,5 +2,10 @@ { imports = [ ./zsh.nix + ./nixvim.nix ] ; + + home.packages = [ + pkgs.ripgrep + ]; } diff --git a/home/common/core/nixvim.nix b/home/common/core/nixvim.nix new file mode 100644 index 0000000..fde5a9c --- /dev/null +++ b/home/common/core/nixvim.nix @@ -0,0 +1,356 @@ +{ inputs, pkgs, ... }: { + imports = [ + inputs.nixvim.homeManagerModules.nixvim + ]; + + programs.nixvim = { + enable = true; + enableMan = true; # install man pages for nixvim options + + clipboard.register = "unnamedplus"; # use system clipboard instead of internal registers + + colorschemes.kanagawa = { + enable = true; + settings = { + commentStyle = { + italic = true; + }; + dimInactive = true; + terminalColors = true; + theme = "wave"; + transparent = false; + undercurl = true; + }; + }; + + opts = { + # + # ========= General Appearance ========= + # + background = ""; + number = true; # show line numbers + relativenumber = true; # show relative linenumbers + laststatus = 0; # Display status line always + history = 1000; # Store lots of :cmdline history + showcmd = true; # Show incomplete cmds down the bottom + showmode = true; # Show current mode down the bottom + autoread = true; # Reload files changed outside vim + lazyredraw = true; # Redraw only when needed + showmatch = true; # highlight matching braces + ruler = true; # show current line and column + visualbell = true; # No sounds + + listchars = "trail:·"; # Display tabs and trailing spaces visually + + # ========= Font ========= + guifont = "NotoSansMono:h9"; # fontname:fontsize + + # ========= Cursor ========= + guicursor = "n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20,n-v-i:blinkon0"; + + # ========= Redirect Temp Files ========= + # backup + backupdir = "$HOME/.local/state/vim/backup//,/tmp//,."; + writebackup = false; + # swap + directory = "$HOME/.local/vim/swap//,/tmp//,."; + + # ================ Indentation ====================== + autoindent = true; + cindent = true; # automatically indent braces + smartindent = true; + smarttab = true; + shiftwidth = 2; + softtabstop = 4; + tabstop = 2; + expandtab = true; + + # ================ Folds ============================ + foldmethod = "indent"; # fold based on indent + foldnestmax = 3; # deepest fold is 3 levels + foldenable = false; # don't fold by default + + # ================ Completion ======================= + wildmode = "list:longest"; + wildmenu = true; # enable ctrl-n and ctrl-p to scroll thru matches + + # stuff to ignore when tab completing + wildignore = "*.o,*.obj,*~,vim/backups,sass-cache,DS_Store,vendor/rails/**,vendor/cache/**,*.gem,log/**,tmp/**,*.png,*.jpg,*.gif"; + + # ================ Scrolling ======================== + scrolloff = 4; # Start scrolling when we're 4 lines away from margins + sidescrolloff = 15; + sidescroll = 1; + + # ================ Searching ======================== + incsearch = true; + hlsearch = true; + ignorecase = true; + smartcase = true; + + # ================ Movement ======================== + backspace = "indent,eol,start"; # allow backspace in insert mode + }; + + # + # ========= UI Plugins ========= + # + + plugins.nvim-colorizer = { + enable = true; + fileTypes = [ "*" ]; + }; + + plugins.lualine = { + enable = true; + theme = "auto"; + componentSeparators = { + left = ""; + right = ""; + }; + sectionSeparators = { + left = ""; + right = ""; + }; + sections = { + lualine_a = [ "mode" ]; + lualine_b = [ "branch" "diff" "diagnostics" ]; + lualine_c = [ "filename" ]; + lualine_x = [ "encoding" "fileformat" "filetype" ]; + lualine_y = [ "progress" ]; + lualine_z = [ "locations" ]; + }; + }; + + # + # ========= File Search ========= + # + plugins.telescope = { + # https://github.com/nvim-telescope/telescope.nvim + enable = true; + extensions.fzy-native.enable = true; + }; + + # ========= File Nav =========== + # + plugins.harpoon = { + enable = true; + keymaps = { + toggleQuickMenu = "b"; + }; + }; + + plugins.nvim-tree = { + enable = true; + view.width = { + min = 30; + max = -1; + padding = 1; + }; + disableNetrw = true; + filters.dotfiles = true; + + }; + + # + # ========== Dev Tools ========= + # + plugins.surround.enable = true; # vim-surround + + plugins.gitsigns = { + enable = true; + settings.signs.add = { + hl = "GitSignsAdd"; + text = " ▎"; + numhl = "GitSignsAddNr"; + linehl = "GitSignsAddLn"; + }; + settings.signs.change = { + hl = "GitSignsChange"; + text = " ▎"; + numhl = "GitSignsChangeNr"; + linehl = "GitSignsChangeLn"; + }; + settings.signs.delete = { + hl = "GitSignsDelete"; + text = " ●"; + numhl = "GitSignsDeleteNr"; + linehl = "GitSignsDeleteLn"; + }; + settings.signs.topdelete = { + hl = "GitSignsDelete"; + text = " ●"; + numhl = "GitSignsDeleteNr"; + linehl = "GitSignsDeleteLn"; + }; + settings.signs.changedelete = { + hl = "GitSignsChange"; + text = " ▎"; + numhl = "GitSignsChangeNr"; + linehl = "GitSignsChangeLn"; + }; + }; + + # Load Plugins that aren't provided as modules by nixvim + extraPlugins = builtins.attrValues { + inherit (pkgs.vimPlugins) + ale + vim-numbertoggle# Use relative number on focused buffer only + vimade# Dim unfocused buffers + vimwiki# Vim Wiki + YouCompleteMe# Code completion engine + vim-dadbod + vim-dadbod-ui + + # Keep vim-devicons as last entry + vim-devicons; + }; + + # ========= Mapleader ========= + globals.mapleader = ";"; + + # + # ========= Key binds ========= + # + keymaps = [ + # Switching windows + { + mode = [ "n" ]; + action = "h"; + key = ""; + options = { + silent = true; + }; + } + { + mode = [ "n" ]; + action = "j"; + key = ""; + options = { + silent = true; + }; + } + { + mode = [ "n" ]; + action = "k"; + key = ""; + options = { + silent = true; + }; + } + { + mode = [ "n" ]; + action = "l"; + key = ""; + options = { + silent = true; + }; + } + # Toggle nvim-tree + { + mode = [ "n" ]; + action = "NvimTreeFindFileToggle"; + key = "tt"; + options = { + silent = true; + }; + } + { + # clear search highlighting + mode = [ "n" ]; + key = ""; + action = "nohlsearch"; + options = { noremap = true; }; + } + + # ========== Telescope Plugin ========= + { + # find files + mode = [ "n" ]; + key = "ff"; + action = "Telescope find_files"; + options = { noremap = true; }; + } + { + # live grep + mode = [ "n" ]; + key = "fg"; + action = "Telescope live_grep"; + options = { noremap = true; }; + } + { + # buffers + mode = [ "n" ]; + key = "fb"; + action = "Telescope buffers"; + options = { noremap = true; }; + } + { + # help tags + mode = [ "n" ]; + key = "fh"; + action = "Telescope help_tags"; + options = { noremap = true; }; + } + + ]; + extraConfigVim = '' + " ================ Persistent Undo ================== + " Keep undo history across sessions, by storing in file. + " Only works all the time. + if has('persistent_undo') + silent !mkdir ~/.vim/backups > /dev/null 2>&1 + set undodir=~/.vim/backups + set undofile + endif + + " ================ Vim Wiki config ================= + " See :h vimwiki_list for info on registering wiki paths + let wiki_0 = {} + let wiki_0.path = '~/dotfiles.wiki/' + let wiki_0.index = 'home' + let wiki_0.syntax = 'markdown' + let wiki_0.ext = '.md' + + " fill spaces in page names with _ in pathing + let wiki_0.links_space_char = '_' + + " ================ Ale ======================== + " linter and fixer packages have to be installed via AUR or pamac + let g:ale_linters = { + \ 'c': ['clang-tidy'], + \ 'python': ['flake8'], + \ 'vim': ['vint'], + \ 'markdown': ['markdownlint'], + \ } + + let g:ale_fixers = { + \ 'c': ['clang-format'], + \ 'javascript': ['prettier', 'eslint'], + \ 'json': ['fixjson', 'prettier'], + \ 'python': ['black', 'isort'], + \ } + + " Set global fixers for all file types except Markdown + " Why? because double spaces at the end of a line in markdown indicate a + " linebreak without creating a new paragraph + function! SetGlobalFixers() + let g:ale_fixers['*'] = ['trim_whitespace', 'remove_trailing_lines'] + endfunction + + augroup GlobalFixers + autocmd! + autocmd VimEnter * call SetGlobalFixers() + augroup END + + " Set buffer-local fixers for Markdown files + augroup MarkdownFixers + autocmd! + autocmd FileType markdown let b:ale_fixers = ['prettier'] + augroup END + + let g:ale_fix_on_save = 1 + ''; + + }; +} diff --git a/home/fileserver.nix b/home/fileserver.nix index 2151435..0766451 100644 --- a/home/fileserver.nix +++ b/home/fileserver.nix @@ -15,3 +15,4 @@ ./common/optional/git.nix ]; +} diff --git a/home/users/sam/default.nix b/home/users/sam/default.nix index ea21adf..5e770b5 100644 --- a/home/users/sam/default.nix +++ b/home/users/sam/default.nix @@ -10,7 +10,6 @@ home.packages = [ pkgs.firefox - pkgs.neovim pkgs.kitty pkgs.zathura pkgs.xfce.thunar diff --git a/hosts/common/core/default.nix b/hosts/common/core/default.nix index 56c622a..c3bca2f 100644 --- a/hosts/common/core/default.nix +++ b/hosts/common/core/default.nix @@ -41,7 +41,7 @@ in pkgs.curl pkgs.just pkgs.git - pkgs.neovim + pkgs.vim ]; }