From 5a13b64f2fe6f9626d78f61bd97b2290e2c2d18f Mon Sep 17 00:00:00 2001 From: uku Date: Sun, 17 Nov 2024 09:58:51 +0100 Subject: [PATCH] feat: add neovim config --- configs/client.nix | 1 + programs/neovim/default.nix | 11 +++++ programs/neovim/init.lua | 89 +++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 programs/neovim/default.nix create mode 100644 programs/neovim/init.lua diff --git a/configs/client.nix b/configs/client.nix index 52abc35..a1ccde0 100644 --- a/configs/client.nix +++ b/configs/client.nix @@ -3,6 +3,7 @@ ./common.nix ../programs/rust.nix + ../programs/neovim ]; environment.systemPackages = with pkgs; [ diff --git a/programs/neovim/default.nix b/programs/neovim/default.nix new file mode 100644 index 0000000..d054583 --- /dev/null +++ b/programs/neovim/default.nix @@ -0,0 +1,11 @@ +{pkgs, ...}: { + environment.systemPackages = with pkgs; [ + unzip + (lua5_1.withPackages (ps: with ps; [luarocks])) + ]; + + hm.programs.neovim = { + enable = true; + extraLuaConfig = builtins.readFile ./init.lua; + }; +} diff --git a/programs/neovim/init.lua b/programs/neovim/init.lua new file mode 100644 index 0000000..81cbec6 --- /dev/null +++ b/programs/neovim/init.lua @@ -0,0 +1,89 @@ +-- sets the "key", which can be used in shortcuts +vim.g.mapleader = ' ' + +vim.g.have_nerd_font = true + +-- [[ vim options, see `:help vim.opt` ]] +-- line numbers +vim.opt.number = true + +-- enable mouse +vim.opt.mouse = 'a' + +-- save undo history +vim.opt.undofile = true + +-- case insensitive search, unless the terms contains uppercase or '\C' +vim.opt.ignorecase = true +vim.opt.smartcase = true + +-- save swapfile 250ms after nothing is done +vim.opt.updatetime = 250 + +-- timeout mapped sequences after 300ms +vim.opt.timeoutlen = 300 + +-- configure where splits open +vim.opt.splitright = true +vim.opt.splitbelow = true + +-- show whitespace characters clearly (see :help 'list') +vim.opt.list = true + +-- preview substitutions (:s & :%s) while typing +vim.opt.inccommand = 'split' + +-- highlight the line the cursor is on +vim.opt.cursorline = true + +-- sync os clipboard and neovim +vim.schedule(function() + vim.opt.clipboard = 'unnamedplus' +end) + + +-- [[ shortcuts, see `:help vim.keymap.set()` ]] +-- hide search results when pressing esc +vim.keymap.set('n', '', 'nohlsearch') + + +-- disable arrow keys in normal mode +vim.keymap.set('n', '', 'echo "Use h to move!!"') +vim.keymap.set('n', '', 'echo "Use l to move!!"') +vim.keymap.set('n', '', 'echo "Use k to move!!"') +vim.keymap.set('n', '', 'echo "Use j to move!!"') + +-- Keybinds to make split navigation easier. +-- Use CTRL+ to switch between windows +-- +-- See `:help wincmd` for a list of all window commands +vim.keymap.set('n', '', '', { desc = 'Move focus to the left window' }) +vim.keymap.set('n', '', '', { desc = 'Move focus to the right window' }) +vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) +vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) + +-- [[ ROCKS.NVIM ]] +local rocks_config = { + rocks_path = vim.env.HOME .. "/.local/share/nvim/rocks", +} + +vim.g.rocks_nvim = rocks_config + +local luarocks_path = { + vim.fs.joinpath(rocks_config.rocks_path, "share", "lua", "5.1", "?.lua"), + vim.fs.joinpath(rocks_config.rocks_path, "share", "lua", "5.1", "?", "init.lua"), +} +package.path = package.path .. ";" .. table.concat(luarocks_path, ";") + +local luarocks_cpath = { + vim.fs.joinpath(rocks_config.rocks_path, "lib", "lua", "5.1", "?.so"), + vim.fs.joinpath(rocks_config.rocks_path, "lib64", "lua", "5.1", "?.so"), + -- Remove the dylib and dll paths if you do not need macos or windows support + vim.fs.joinpath(rocks_config.rocks_path, "lib", "lua", "5.1", "?.dylib"), + vim.fs.joinpath(rocks_config.rocks_path, "lib64", "lua", "5.1", "?.dylib"), + vim.fs.joinpath(rocks_config.rocks_path, "lib", "lua", "5.1", "?.dll"), + vim.fs.joinpath(rocks_config.rocks_path, "lib64", "lua", "5.1", "?.dll"), +} +package.cpath = package.cpath .. ";" .. table.concat(luarocks_cpath, ";") + +vim.opt.runtimepath:append(vim.fs.joinpath(rocks_config.rocks_path, "lib", "luarocks", "rocks-5.1", "*", "*"))