diff --git a/modules/common/home.nix b/modules/common/home.nix index 57c57cf..ccafe4c 100644 --- a/modules/common/home.nix +++ b/modules/common/home.nix @@ -1,7 +1,9 @@ { lib, config, pkgs, ... }: { + home-manager.useGlobalPkgs = true; home-manager.users.sammy = { + imports = [ ./neovim.nix ]; home.username = "sammy"; home.homeDirectory = "/home/sammy"; home.stateVersion = "23.11"; # Please read the comment before changing. @@ -32,8 +34,6 @@ nushell = { enable = true; }; - - }; # Home Manager is pretty good at managing dotfiles. The primary way to manage diff --git a/modules/common/neovim.nix b/modules/common/neovim.nix new file mode 100644 index 0000000..ff59e52 --- /dev/null +++ b/modules/common/neovim.nix @@ -0,0 +1,62 @@ +{ config, pkgs, inputs, ... }: + +{ + + programs.neovim = + let + toLua = str: "lua << EOF\n${str}\nEOF\n"; + toLuaFile = file: "lua << EOF\n${builtins.readFile file}\nEOF\n"; + in + { + enable = true; + + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + + extraPackages = with pkgs; [ + lua-language-server + rnix-lsp + + xclip + wl-clipboard + ]; + + plugins = with pkgs.vimPlugins; [ + + { + plugin = comment-nvim; + config = toLua "require(\"Comment\").setup()"; + } + + { + plugin = catppuccin-nvim; + config = "colorscheme catppuccin"; + } + + { plugin = which-key-nvim; + config = toLua "require(\"which-key\").setup()"; + } + + nvim-cmp + neodev-nvim + + cmp_luasnip + cmp-nvim-lsp + + luasnip + friendly-snippets + + + lualine-nvim + nvim-web-devicons + + vim-nix + ]; + + extraLuaConfig = '' + ${builtins.readFile ./nvim/options.lua} + ${builtins.readFile ./nvim/keymap.lua} + ''; + }; +} diff --git a/modules/common/nvim/keymap.lua b/modules/common/nvim/keymap.lua new file mode 100644 index 0000000..262f0b4 --- /dev/null +++ b/modules/common/nvim/keymap.lua @@ -0,0 +1,69 @@ +local map = vim.keymap.set +local wk = require("which-key") + +-- better up/down +map({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) +map({ "n", "x" }, "", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) +map({ "n", "x" }, "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) +map({ "n", "x" }, "", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) + +-- Move to window using the hjkl keys +map("n", "", "h", { desc = "Go to left window", remap = true }) +map("n", "", "j", { desc = "Go to lower window", remap = true }) +map("n", "", "k", { desc = "Go to upper window", remap = true }) +map("n", "", "l", { desc = "Go to right window", remap = true }) + +-- Resize window using arrow keys +map("n", "", "resize +2", { desc = "Increase window height" }) +map("n", "", "resize -2", { desc = "Decrease window height" }) +map("n", "", "vertical resize -2", { desc = "Decrease window width" }) +map("n", "", "vertical resize +2", { desc = "Increase window width" }) + +-- Move Lines +map("n", "", "m .+1==", { desc = "Move down" }) +map("n", "", "m .-2==", { desc = "Move up" }) +map("i", "", "m .+1==gi", { desc = "Move down" }) +map("i", "", "m .-2==gi", { desc = "Move up" }) +map("v", "", ":m '>+1gv=gv", { desc = "Move down" }) +map("v", "", ":m '<-2gv=gv", { desc = "Move up" }) + +-- buffers +map("n", "", "bprevious", { desc = "Prev buffer" }) +map("n", "", "bnext", { desc = "Next buffer" }) + +-- Clear search with +map({ "i", "n" }, "", "noh", { desc = "Escape and clear hlsearch" }) + +-- save file +map({ "i", "x", "n", "s" }, "", "w", { desc = "Save file" }) + +--keywordprg +map("n", "K", "norm! K", { desc = "Keywordprg" }) + +-- better indenting +map("v", "<", "", ">gv") + +wk.register({["f"] = { name = "File" }}) +-- new file +map("n", "fn", "enew", { desc = "New File" }) + +map("n", "xl", "lopen", { desc = "Location List" }) +map("n", "xq", "copen", { desc = "Quickfix List" }) + +map("n", "ww", "p", { desc = "Other window", remap = true }) +map("n", "wd", "c", { desc = "Delete window", remap = true }) +map("n", "w-", "s", { desc = "Split window below", remap = true }) +map("n", "w|", "v", { desc = "Split window right", remap = true }) +map("n", "-", "s", { desc = "Split window below", remap = true }) +map("n", "|", "v", { desc = "Split window right", remap = true }) + +-- tabs +wk.register({[""] = { name = "Tabs" }}) +map("n", "l", "tablast", { desc = "Last Tab" }) +map("n", "f", "tabfirst", { desc = "First Tab" }) +map("n", "", "tabnew", { desc = "New Tab" }) +map("n", "]", "tabnext", { desc = "Next Tab" }) +map("n", "d", "tabclose", { desc = "Close Tab" }) +map("n", "[", "tabprevious", { desc = "Previous Tab" }) + diff --git a/modules/common/nvim/options.lua b/modules/common/nvim/options.lua new file mode 100644 index 0000000..8c2e091 --- /dev/null +++ b/modules/common/nvim/options.lua @@ -0,0 +1,54 @@ +-- partially taken from https://www.lazyvim.org and merged with my own config +-- +vim.g.mapleader = " " +vim.g.maplocalleader = "\\" + +-- root dir detection +vim.g.root_spec = { "lsp", { ".git", "lua" }, "cwd" } + +local opt = vim.opt + +opt.autowrite = true -- Enable auto write +opt.autoread = true +opt.clipboard = "unnamedplus" -- Sync with system clipboard +opt.completeopt = "menu,menuone,noselect" +opt.conceallevel = 3 -- Hide * markup for bold and italic +opt.confirm = true -- Confirm to save changes before exiting modified buffer +opt.cursorline = true -- Enable highlighting of the current line +opt.ignorecase = true -- Ignore case in search +opt.inccommand = "nosplit" -- preview incremental substitute +opt.laststatus = 3 -- global statusline +opt.list = true -- Show some invisible characters (tabs... +opt.mouse = "a" -- Enable mouse mode +opt.number = true -- Print line number +opt.pumblend = 10 -- Popup blend +opt.pumheight = 10 -- Maximum number of entries in a popup +opt.relativenumber = true -- Relative line numbers +opt.scrolloff = 4 -- Lines of context +opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize", "help", "globals", "skiprtp", "folds" } +opt.shiftround = true -- Round indent +opt.shiftwidth = 2 -- Size of an indent +opt.shortmess:append({ W = true, I = true, c = true, C = true }) +opt.showmode = false -- Dont show mode since we have a statusline +opt.sidescrolloff = 8 -- Columns of context +opt.signcolumn = "yes" -- Always show the signcolumn, otherwise it would shift the text each time +opt.smartcase = true -- Don't ignore case with capitals +opt.smartindent = true -- Insert indents automatically +opt.spelllang = { "en", "de" } +opt.splitbelow = true -- Put new windows below current +opt.splitkeep = "screen" +opt.splitright = true -- Put new windows right of current +opt.tabstop = 2 -- Number of spaces tabs count for +opt.termguicolors = true -- True color support +opt.timeoutlen = 300 +opt.undofile = true +opt.undolevels = 10000 +opt.updatetime = 200 -- Save swap file and trigger CursorHold +opt.virtualedit = "block" -- Allow cursor to move where there is no text in visual block mode +opt.wildmode = "longest:full,full" -- Command-line completion mode +opt.winminwidth = 5 -- Minimum window width +opt.wrap = false -- Disable line wrap + +-- Fix markdown indentation settings +vim.g.markdown_recommended_style = 0 +