Skip to content

Commit

Permalink
neovim/init: set basic options via vim.options
Browse files Browse the repository at this point in the history
Less DAGs, more customizability.
  • Loading branch information
NotAShelf committed Nov 10, 2024
1 parent c08d0a7 commit 4c238c0
Showing 1 changed file with 104 additions and 111 deletions.
215 changes: 104 additions & 111 deletions modules/neovim/init/basic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -182,116 +184,107 @@ in {
};

config = {
vim.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
vim.o.writebackup = false
''}
${optionalString (cfg.bell == "none") ''
vim.o.errorbells = false
vim.o.visualbell = false
''}
${optionalString (cfg.bell == "on") ''
vim.o.visualbell = false
''}
${optionalString (cfg.bell == "visual") ''
vim.o.errorbells = false
''}
${optionalString (cfg.lineNumberMode == "relative") ''
vim.o.relativenumber = true
''}
${optionalString (cfg.lineNumberMode == "number") ''
vim.o.number = true
''}
${optionalString (cfg.lineNumberMode == "relNumber") ''
vim.o.number = true
vim.o.relativenumber = true
''}
${optionalString cfg.useSystemClipboard ''
vim.opt.clipboard:append("unnamedplus")
''}
${optionalString cfg.syntaxHighlighting ''
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
''}
${optionalString (cfg.searchCase == "smart") ''
vim.o.smartcase = true
vim.o.ignorecase = true
''}
${optionalString (cfg.searchCase == "sensitive") ''
vim.o.smartcase = false
vim.o.ignorecase = false
''}
'';
vim = {
# mkOptionDefault will reduce priority of set options so that users may override
# any given option without applying `mkForce` to increase their priority.
# This should, overall, make configuring 'vim.options' frictionless.
options = mapAttrs (_: pushDownDefault) {
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;
mapleader = cfg.leaderKey;
maplocalleader = cfg.leaderKey;
splitbelow = cfg.splitBelow;
splitright = cfg.splitRight;
signcolumn = cfg.showSignColumn;
autoindent = cfg.autoIndent;
termguicolors = cfg.colourTerm;
wrap = cfg.wordWrap;
};

globals = mapAttrs (_: pushDownDefault) {
editorconfig = cfg.enableEditorconfig;
};

# Options that are more difficult to set through the module system. 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.opt.shortmess:append("c")
${optionalString cfg.undoFile.enable ''
vim.o.undofile = true
vim.o.undodir = ${toLuaObject cfg.undoFile.path}
''}
${optionalString cfg.preventJunkFiles ''
vim.o.swapfile = false
vim.o.backup = false
vim.o.writebackup = false
''}
${optionalString (cfg.bell == "none") ''
vim.o.errorbells = false
vim.o.visualbell = false
''}
${optionalString (cfg.bell == "on") ''
vim.o.visualbell = false
''}
${optionalString (cfg.bell == "visual") ''
vim.o.errorbells = false
''}
${optionalString (cfg.lineNumberMode == "relative") ''
vim.o.relativenumber = true
''}
${optionalString (cfg.lineNumberMode == "number") ''
vim.o.number = true
''}
${optionalString (cfg.lineNumberMode == "relNumber") ''
vim.o.number = true
vim.o.relativenumber = true
''}
${optionalString cfg.useSystemClipboard ''
vim.opt.clipboard:append("unnamedplus")
''}
${optionalString cfg.syntaxHighlighting ''
vim.cmd("syntax on")
''}
${optionalString cfg.hideSearchHighlight ''
vim.o.hlsearch = false
vim.o.incsearch = true
''}
${optionalString (cfg.searchCase == "ignore") ''
vim.o.smartcase = false
vim.o.ignorecase = true
''}
${optionalString (cfg.searchCase == "smart") ''
vim.o.smartcase = true
vim.o.ignorecase = true
''}
${optionalString (cfg.searchCase == "sensitive") ''
vim.o.smartcase = false
vim.o.ignorecase = false
''}
'';
};
};
}

0 comments on commit 4c238c0

Please sign in to comment.