From 6082da3e201c4331ce71c47d0d25d91bc2237852 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 11 Nov 2024 01:38:52 +0300 Subject: [PATCH] neovim/init: set basic options via `vim.options` Less DAGs, more customizability. --- modules/neovim/init/basic.nix | 71 +++++++++++++++-------------------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/modules/neovim/init/basic.nix b/modules/neovim/init/basic.nix index 2114dcb..a4e44e8 100644 --- a/modules/neovim/init/basic.nix +++ b/modules/neovim/init/basic.nix @@ -5,9 +5,11 @@ }: let inherit (lib.options) mkOption mkEnableOption literalExpression literalMD; inherit (lib.strings) optionalString; + inherit (lib.attrsets) mapAttrs; inherit (lib.types) enum bool str int either; inherit (lib.generators) mkLuaInline; inherit (lib.nvim.dag) entryAfter; + inherit (lib.nvim.binds) pushDownDefault; inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.types) luaInline; @@ -181,46 +183,47 @@ in { }; }; - config = { - vim.luaConfigRC.basic = entryAfter ["globalsScript"] '' + config.vim = { + options = { + encoding = "utf-8"; + hidden = true; + expandtab = true; + mouse = cfg.mouseSupport; + tabstop = cfg.tabWidth; + shiftwidth = cfg.tabWidth; + softtabstop = cfg.tabWidth; + cmdheight = cfg.cmdHeight; + updatetime = cfg.updateTime; + tm = cfg.mapTimeout; + cursorlineopt = cfg.cursorlineOpt; + splitbelow = cfg.splitBelow; + splitright = cfg.splitRight; + autoindent = cfg.autoIndent; + termguicolors = cfg.colourTerm; + wrap = cfg.wordWrap; + }; + + globals = { + mapleader = cfg.leaderKey; + maplocalleader = cfg.leaderKey; + editorconfig = cfg.enableEditorconfig; + }; + + # Options that are more difficult to set through 'vim.options'. Fear not, though + # as the Lua DAG is still as powerful as it could be. + luaConfigRC.basic = entryAfter ["globalsScript"] '' -- Settings that are set for everything - vim.o.encoding = "utf-8" - vim.o.hidden = true vim.opt.shortmess:append("c") - vim.o.expandtab = true - vim.o.mouse = ${toLuaObject cfg.mouseSupport} - vim.o.tabstop = ${toLuaObject cfg.tabWidth} - vim.o.shiftwidth = ${toLuaObject cfg.tabWidth} - vim.o.softtabstop = ${toLuaObject cfg.tabWidth} - vim.o.cmdheight = ${toLuaObject cfg.cmdHeight} - vim.o.updatetime = ${toLuaObject cfg.updateTime} - vim.o.tm = ${toLuaObject cfg.mapTimeout} - vim.o.cursorlineopt = ${toLuaObject cfg.cursorlineOpt} - vim.o.scrolloff = ${toLuaObject cfg.scrollOffset} - vim.g.mapleader = ${toLuaObject cfg.leaderKey} - vim.g.maplocalleader = ${toLuaObject cfg.leaderKey} ${optionalString cfg.undoFile.enable '' vim.o.undofile = true vim.o.undodir = ${toLuaObject cfg.undoFile.path} ''} - ${optionalString cfg.splitBelow '' - vim.o.splitbelow = true - ''} - - ${optionalString cfg.splitRight '' - vim.o.splitright = true - ''} - ${optionalString cfg.showSignColumn '' vim.o.signcolumn = "yes" ''} - ${optionalString cfg.autoIndent '' - vim.o.autoindent = true - ''} - ${optionalString cfg.preventJunkFiles '' vim.o.swapfile = false vim.o.backup = false @@ -261,23 +264,11 @@ in { vim.cmd("syntax on") ''} - ${optionalString (!cfg.wordWrap) '' - vim.o.wrap = false - ''} - ${optionalString cfg.hideSearchHighlight '' vim.o.hlsearch = false vim.o.incsearch = true ''} - ${optionalString cfg.colourTerm '' - vim.o.termguicolors = true - ''} - - ${optionalString (!cfg.enableEditorconfig) '' - vim.g.editorconfig = false - ''} - ${optionalString (cfg.searchCase == "ignore") '' vim.o.smartcase = false vim.o.ignorecase = true