From 02d599d0a072e74047700b0556a773ae4812a5ec Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 21 Feb 2023 00:42:54 +0900 Subject: [PATCH] Add a basic nvim config --- flake.nix | 1 + modules/home/default.nix | 1 + modules/home/hyprland/default.nix | 3 + modules/home/hyprland/hyprland.conf | 11 +- modules/home/nvim/default.nix | 16 +++ modules/home/nvim/init.lua | 15 +++ modules/home/nvim/lazy-lock.json | 21 ++++ modules/home/nvim/lua/plugins/line.lua | 115 ++++++++++++++++++++ modules/home/nvim/lua/plugins/settings.lua | 31 ++++++ modules/home/nvim/lua/plugins/telescope.lua | 76 +++++++++++++ modules/home/nvim/lua/plugins/tree.lua | 62 +++++++++++ modules/home/nvim/lua/plugins/ui.lua | 33 ++++++ modules/home/nvim/lua/settings.lua | 92 ++++++++++++++++ modules/home/zsh/default.nix | 1 + 14 files changed, 473 insertions(+), 5 deletions(-) create mode 100644 modules/home/nvim/default.nix create mode 100644 modules/home/nvim/init.lua create mode 100644 modules/home/nvim/lazy-lock.json create mode 100644 modules/home/nvim/lua/plugins/line.lua create mode 100644 modules/home/nvim/lua/plugins/settings.lua create mode 100644 modules/home/nvim/lua/plugins/telescope.lua create mode 100644 modules/home/nvim/lua/plugins/tree.lua create mode 100644 modules/home/nvim/lua/plugins/ui.lua create mode 100644 modules/home/nvim/lua/settings.lua diff --git a/flake.nix b/flake.nix index 2c1575a..c9f1f11 100644 --- a/flake.nix +++ b/flake.nix @@ -110,6 +110,7 @@ apps.enable = true; zsh.enable = true; git.enable = true; + nvim.enable = true; }; }; }; diff --git a/modules/home/default.nix b/modules/home/default.nix index e11787b..7117e1e 100644 --- a/modules/home/default.nix +++ b/modules/home/default.nix @@ -6,6 +6,7 @@ ./apps ./zsh ./git + ./nvim ]; home.stateVersion = "22.11"; diff --git a/modules/home/hyprland/default.nix b/modules/home/hyprland/default.nix index d1518e4..5c062b1 100644 --- a/modules/home/hyprland/default.nix +++ b/modules/home/hyprland/default.nix @@ -16,6 +16,9 @@ in { xorg.xprop discord kitty + grim + slurp + wl-clipboard ]; wayland.windowManager.hyprland = { enable = true; diff --git a/modules/home/hyprland/hyprland.conf b/modules/home/hyprland/hyprland.conf index afb97fe..375e4ee 100644 --- a/modules/home/hyprland/hyprland.conf +++ b/modules/home/hyprland/hyprland.conf @@ -129,11 +129,6 @@ bind = $mainMod SHIFT, F, fakefullscreen, bind = $mainMod, backslash, togglespecialworkspace, special:default bind = $mainMod, V, togglefloating, -bind = $mainMod, E, exec, kitty -bind = $mainMod, R, exec, google-chrome-stable -bind = $mainMod, P, exec, rofi -show run -bindr = SUPER, SUPER_L, exec, ~/.config/eww/togglepanel.sh - # Move focus with mainMod + arrow keys bind = $mainMod, left, movefocus, l bind = $mainMod, right, movefocus, r @@ -171,6 +166,12 @@ bind = $mainMod SHIFT, S, movetoworkspace, special:default bindm = $mainMod, mouse:272, movewindow bindm = $mainMod, mouse:273, resizewindow +bind = $mainMod, E, exec, kitty +bind = $mainMod, R, exec, google-chrome-stable +bind = $mainMod, P, exec, rofi -show run +bind = $mainMod, X, exec, grim -g "$(slurp -b 00000000 -s 61616140)" - | wl-copy +#bindr = SUPER, SUPER_L, exec, ~/.config/eww/togglepanel.sh + bindl=,XF86MonBrightnessUp,exec,brightnessctl set 5%+ bindl=,XF86MonBrightnessDown,exec,brightnessctl set 5%- bindl=,XF86AudioRaiseVolume,exec,pactl set-sink-volume @DEFAULT_SINK@ +5% diff --git a/modules/home/nvim/default.nix b/modules/home/nvim/default.nix new file mode 100644 index 0000000..03a27b2 --- /dev/null +++ b/modules/home/nvim/default.nix @@ -0,0 +1,16 @@ +{ + lib, + config, + pkgs, + ... +}: let + cfg = config.modules.nvim; +in { + options.modules.nvim = {enable = lib.mkEnableOption "nvim";}; + + config = lib.mkIf cfg.enable { + home.packages = with pkgs; [neovim]; + + xdg.configFile."nvim".source = ./.; + }; +} diff --git a/modules/home/nvim/init.lua b/modules/home/nvim/init.lua new file mode 100644 index 0000000..1066b97 --- /dev/null +++ b/modules/home/nvim/init.lua @@ -0,0 +1,15 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require("./settings"); +require("lazy").setup("plugins"); diff --git a/modules/home/nvim/lazy-lock.json b/modules/home/nvim/lazy-lock.json new file mode 100644 index 0000000..3f10f13 --- /dev/null +++ b/modules/home/nvim/lazy-lock.json @@ -0,0 +1,21 @@ +{ + "catppuccin": { "branch": "main", "commit": "fe32c776d86e8ba608e6294c43302c985835bfea" }, + "increment-activator": { "branch": "master", "commit": "55efcff88be45bd98cfdf7333dd718399373d10c" }, + "indent-blankline.nvim": { "branch": "master", "commit": "018bd04d80c9a73d399c1061fa0c3b14a7614399" }, + "lazy.nvim": { "branch": "main", "commit": "8077428e63feb0f3bf795d53b23ba1695b28ab0e" }, + "lualine.nvim": { "branch": "master", "commit": "e99d733e0213ceb8f548ae6551b04ae32e590c80" }, + "neo-tree.nvim": { "branch": "v2.x", "commit": "245cf1e68840defcc75a16297740f6203f5a045d" }, + "nui.nvim": { "branch": "main", "commit": "d147222a1300901656f3ebd5b95f91732785a329" }, + "nvim-lspconfig": { "branch": "master", "commit": "b5db147e28337319331d516a826b00976f3584de" }, + "nvim-navic": { "branch": "master", "commit": "7e9d2b2b601149fecdccd11b516acb721e571fe6" }, + "nvim-scrollbar": { "branch": "main", "commit": "75210c554e935740448cfb532d8a671ae544bb1b" }, + "nvim-web-devicons": { "branch": "master", "commit": "4709a504d2cd2680fb511675e64ef2790d491d36" }, + "plenary.nvim": { "branch": "master", "commit": "253d34830709d690f013daf2853a9d21ad7accab" }, + "telescope-fzf-native.nvim": { "branch": "feature/69-prebuilt-release-binaries", "commit": "6388c4f4ec5eab8b89f974a9fa57fc955a67bbb2" }, + "telescope.nvim": { "branch": "master", "commit": "f40e3e2304c633411ddf266075f7db5184b1db02" }, + "vim-repeat": { "branch": "master", "commit": "24afe922e6a05891756ecf331f39a1f6743d3d5a" }, + "vim-sleuth": { "branch": "master", "commit": "1cc4557420f215d02c4d2645a748a816c220e99b" }, + "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" }, + "vim-unimpaired": { "branch": "master", "commit": "6d44a6dc2ec34607c41ec78acf81657248580bf1" }, + "virt-column.nvim": { "branch": "master", "commit": "93b40ea038f676f5a72d7d1f2336fe7b051fc0ce" } +} \ No newline at end of file diff --git a/modules/home/nvim/lua/plugins/line.lua b/modules/home/nvim/lua/plugins/line.lua new file mode 100644 index 0000000..b31e66a --- /dev/null +++ b/modules/home/nvim/lua/plugins/line.lua @@ -0,0 +1,115 @@ +return { + { + "nvim-lualine/lualine.nvim", + event = "VeryLazy", + opts = function() + local gps = require("nvim-navic") + local toggleterm = { + sections = { + lualine_a = { + { + 'mode', + fmt = function(str) return string.format("%7s", str) end + }, + }, + lualine_b = { + function() + return 'ToggleTerm #' .. vim.b.toggle_number + end + } + }, + filetypes = { "toggleterm" }, + } + + return { + options = { + theme = "auto", + component_separators = '|', + section_separators = { left = '', right = '' }, + always_divide_middle = true, + globalstatus = true, + disabled_filetypes = {}, + }, + sections = { + lualine_a = { + { + 'mode', + fmt = function(str) return string.format("%7s", str) end + }, + }, + lualine_b = { + { + "diagnostics", + sources = { + function() + local diag_severity = vim.diagnostic.severity + + local function workspace_diag(severity) + local count = vim.diagnostic.get(nil, { severity = severity }) + return vim.tbl_count(count) + end + + return { + error = workspace_diag(diag_severity.ERROR), + warn = workspace_diag(diag_severity.WARN), + info = workspace_diag(diag_severity.INFO), + hint = workspace_diag(diag_severity.HINT) + } + end, + }, + sections = { "error", "warn" }, + symbols = { error = " ", warn = " " }, + always_visible = false, + } + }, + lualine_c = { + { + function() + return "" + end, + color = "ErrorMsg", + cond = function() return not auto_save_state end, + }, + { 'filetype', colored = true, icon_only = true, separator = "", padding = { left = 1, right = 0 } }, + { + 'filename', + separator = '>', + path = 0, + symbols = { + modified = '', + readonly = '[-]', + unnamed = '[No Name]', + }, + }, + { gps.get_location, cond = gps.is_available }, + }, + lualine_x = { + -- require "dap".status, + 'fileformat', + }, + lualine_y = { 'branch', 'progress' }, + lualine_z = { + { + 'location', + }, + }, + }, + tabline = {}, + extensions = { + "quickfix", + "neo-tree", + "fugitive", + toggleterm + }, + } + end + }, + { + "SmiteshP/nvim-navic", + lazy = true, + dependencies = { + "neovim/nvim-lspconfig", + }, + opts = {highlight = true}, + } +} diff --git a/modules/home/nvim/lua/plugins/settings.lua b/modules/home/nvim/lua/plugins/settings.lua new file mode 100644 index 0000000..98a24f8 --- /dev/null +++ b/modules/home/nvim/lua/plugins/settings.lua @@ -0,0 +1,31 @@ +return { + { + "catppuccin/nvim", + name = "catppuccin", + lazy = false, + priority = 1000, + config = function() + require("catppuccin").setup({ + integrations = { + which_key = true, + lsp_trouble = true, + telescope = true, + treesitter = true, + neotree = true, + harpoon = true, + gitsigns = true, + semantic_tokens = true, + indent_blankline = { + enabled = true, + }, + } + }) + vim.cmd([[colorscheme catppuccin-mocha]]) + end + }, + "tpope/vim-surround", + "tpope/vim-sleuth", + { "tpope/vim-repeat", event = "VeryLazy" }, + { "tpope/vim-unimpaired", config = function() vim.g.nremap = { ["[u"] = "", ["]u"] = "" } end }, + "nishigori/increment-activator", +} diff --git a/modules/home/nvim/lua/plugins/telescope.lua b/modules/home/nvim/lua/plugins/telescope.lua new file mode 100644 index 0000000..5da836a --- /dev/null +++ b/modules/home/nvim/lua/plugins/telescope.lua @@ -0,0 +1,76 @@ +return { + { + "nvim-telescope/telescope.nvim", + dependencies = { + { + "airtonix/telescope-fzf-native.nvim", + branch = 'feature/69-prebuilt-release-binaries', + build = function() + require('telescope-fzf-native').download_library() + end + }, + "nvim-lua/plenary.nvim", + }, + cmd = "Telescope", + version = false, -- telescope did only one release, so use HEAD for now + keys = { + { "f", "Telescope find_files", desc = "Find Files" }, + { "F", "Telescope live_grep", desc = "Grep" }, + { "gl", "Telescope git_commits", desc = "Git log" }, + { "gs", "Telescope git_status", desc = "Git status" }, + }, + opts = function() + local actions = require "telescope.actions" + + return { + defaults = { + prompt_prefix = " ", + selection_caret = " ", + sorting_strategy = "ascending", + layout_strategy = "horizontal", + layout_config = { + horizontal = { + prompt_position = "top", + } + }, + path_display = { "truncate" }, + mappings = { + i = { + [""] = actions.close, + [""] = function () vim.api.nvim_input("") end, + [""] = function () vim.api.nvim_input("") end, + [""] = actions.move_selection_previous, + [""] = actions.move_selection_next, + [""] = function() + local has_trouble, trouble_action = pcall(require, "trouble.providers.telescope") + if has_trouble then + trouble_action.open_with_trouble() + end + end + }, + }, + }, + extensions = { + fzf = { + fuzzy = true, -- false will only do exact matching + override_generic_sorter = true, -- override the generic sorter + override_file_sorter = true, -- override the file sorter + } + }, + pickers = { + find_files = { + hidden = true, + find_command = { "fd", "--type", "f", "--strip-cwd-prefix", "-E", ".git" }, + }, + git_status = { + mappings = { + i = { + -- [""] = local_actions.commit, + }, + }, + }, + }, + } + end + } +} diff --git a/modules/home/nvim/lua/plugins/tree.lua b/modules/home/nvim/lua/plugins/tree.lua new file mode 100644 index 0000000..01d0f3d --- /dev/null +++ b/modules/home/nvim/lua/plugins/tree.lua @@ -0,0 +1,62 @@ +return { + { + "nvim-neo-tree/neo-tree.nvim", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", + "MunifTanjim/nui.nvim", + }, + cmd = "Neotree", + keys = { + { "-", "Neotree current dir=%:h reveal_force_cwd toggle", desc = "Toggle explorer", }, + { "\\", "Neotree current dir=%:h reveal_force_cwd toggle", desc = "Toggle explorer", }, + { "e", "Neotree left toggle", desc = "Toggle left explorer", }, + }, + deactivate = function() + vim.cmd([[Neotree close]]) + end, + init = function() + vim.g.neo_tree_remove_legacy_commands = 1 + if vim.fn.argc() == 1 then + local stat = vim.loop.fs_stat(vim.fn.argv(0)) + if stat and stat.type == "directory" then + require("neo-tree") + end + end + end, + opts = { + close_if_last_window = true, + sort_case_insensitive = true, + default_component_configs = { + git_status = { + symbols = { + -- Change type + added = "✚", + deleted = "", + modified = "", + renamed = "", + -- Status type + untracked = "", + ignored = "◌", + unstaged = "", + staged = "✓", + conflict = "", + }, + align = "left", + }, + }, + window = { + mappings = { + [""] = "none", + }, + }, + filesystem = { + follow_current_file = true, + hijack_netrw_behavior = "open_current", + filtered_items = { + hide_dotfiles = false, + }, + }, + }, + }, +} diff --git a/modules/home/nvim/lua/plugins/ui.lua b/modules/home/nvim/lua/plugins/ui.lua new file mode 100644 index 0000000..0994da0 --- /dev/null +++ b/modules/home/nvim/lua/plugins/ui.lua @@ -0,0 +1,33 @@ +return { + { + "lukas-reineke/indent-blankline.nvim", + event = { "BufReadPost", "BufNewFile" }, + opts = { + char = "▏", + filetype_exclude = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy" }, + show_trailing_blankline_indent = true, + use_treesitter = true, + show_current_context = true, + }, + }, + + { + "lukas-reineke/virt-column.nvim", + lazy = true, + config = true, + init = function() + vim.cmd [[ + augroup virtcolumn + autocmd! + autocmd FileType * if index(["netrw", "NvimTree", "neo-tree", "UltestAttach", "dap-float", "Trouble", "lspinfo", "qf", "harpoon", "toggleterm", "packer"], &ft) == -1 | lua require("virt-column").setup_buffer({ virtcolumn = "80,120", char = "▏" }) + augroup end + ]] + end, + }, + + { + "petertriho/nvim-scrollbar", + -- TODO: Add colors highlights. + config = true; + }, +} diff --git a/modules/home/nvim/lua/settings.lua b/modules/home/nvim/lua/settings.lua new file mode 100644 index 0000000..8c7d09a --- /dev/null +++ b/modules/home/nvim/lua/settings.lua @@ -0,0 +1,92 @@ +local options = { + fileencoding = "utf-8", + expandtab = false, + shiftwidth = 4, + tabstop = 4, + cinoptions = { + "(1s", + "m1", + }, + + hlsearch = true, + ignorecase = true, + smartcase = true, + + mouse = "a", + splitbelow = true, + splitright = true, + cursorline = true, + sidescrolloff = 8, + wrap = false, + + termguicolors = true, + swapfile = false, + undofile = true, + updatetime = 300, -- faster completion (4000ms default) + + number = true, + relativenumber = true, + numberwidth = 4, + signcolumn = "yes", + + list = true, + listchars = { + space = "·", + tab = "▷ ", + extends = "◣", + precedes = "◢", + nbsp = "○", + }, + fillchars = { + diff = "╱", + }, +} + +for k, v in pairs(options) do + vim.opt[k] = v +end +vim.cmd("set formatoptions-=ro") + +local opts = { noremap = true, silent = true } +local keymap = vim.api.nvim_set_keymap + +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- Stay in indent mode +keymap("v", "<", "", ">gv", opts) + +-- Move in insert mode -- +keymap("i", "", "", opts) +keymap("i", "", "", opts) +keymap("i", "", "", opts) +keymap("i", "", "", opts) + +keymap("i", "", "", opts) +keymap("c", "", "", opts) +keymap("i", "", "", opts) -- Keymap for CTRL-BACKSPACE on some termial emulators. +keymap("c", "", "", opts) + +keymap("n", "y", '"+y', opts) +keymap("x", "y", '"+y', opts) +keymap("n", "Y", '"+y$', opts) +keymap("x", "Y", '"+y$', opts) + +keymap("n", "p", '"+p', opts) +keymap("x", "p", '"+p', opts) +keymap("n", "P", '"+P', opts) +keymap("x", "P", '"+P', opts) + + +keymap("t", "", "", opts) + +vim.cmd("autocmd FileType qf setl nolist") +vim.cmd("syntax on") +vim.cmd [[ + augroup highlight_yank + autocmd! + autocmd TextYankPost * silent!lua require('vim.highlight').on_yank({higroup = 'Visual', timeout = 200}) + augroup end +]] + diff --git a/modules/home/zsh/default.nix b/modules/home/zsh/default.nix index 8578489..43ea8ac 100644 --- a/modules/home/zsh/default.nix +++ b/modules/home/zsh/default.nix @@ -20,6 +20,7 @@ in { htop tldr jq + fd ripgrep psmisc atuin