From ad7eaf0f3bb3bdf7038a270a9b027a6365b23e3b Mon Sep 17 00:00:00 2001 From: Wil Taylor Date: Mon, 17 May 2021 12:01:15 +1000 Subject: [PATCH] Added basic settings --- 2 | 139 +++++++++++++++++++++++++ modules/basic/default.nix | 212 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 345 insertions(+), 6 deletions(-) create mode 100644 2 diff --git a/2 b/2 new file mode 100644 index 0000000..ff2ba05 --- /dev/null +++ b/2 @@ -0,0 +1,139 @@ +{ pkgs, lib, config, ...}: +with lib; +with builtins; + +let + cfg = config.vim; +in { + options.vim = { + colourTerm = mkOption { + default = true; + description = "Set terminal up for 256 colours"; + type = types.bool; + }; + + disableArrows = mkOption { + default = false; + description = "Set to prevent arrow keys from moving cursor"; + type = types.bool; + }; + + hideSearchHighlight = mkOption { + default = true; + description = "Hide search highlight so it doesn't stay highlighted"; + type = types.bool; + }; + + scrollOffset = mkOption { + default = 8; + description = "Start scrolling this number of lines from the top or bottom of the page."; + type = types.int; + }; + + wordWrap = mkOption { + default = false; + description = "Enable word wrapping."; + type = types.bool; + }; + + syntaxHighlighting = mkOption { + default = true; + description = "Enable syntax highlighting"; + type = types.bool; + }; + + mapLeaderSpace = mkOption { + default = true; + description = "Map the space key to leader key"; + type = types.bool; + }; + + useSystemClipboard = mkOption { + default = true; + description = "Make use of the clipboard for default yank and paste operations. Don't use * and +"; + type = types.bool; + }; + + mouseSupport = mkOption { + default = "a"; + description = "Set modes for mouse support. a - all, n - normal, v - visual, i - insert, c - command"; + type = types.str; + }; + + lineNumberMode = mkOption { + default = "relNumber"; + description = "How line numbers are displayed. none, relative, number, relNumber"; + type = with types; enum ["relative" "number" "relNumber" "none"]; + }; + + config = ( + let + writeIf = cond: msg: if cond then msg else ""; + in { + + vim.nmap = if (cfg.disableArrows) then { + "" = ""; + "" = ""; + "" = ""; + "" = ""; + } else {}; + + vim.imap = if (cfg.disableArrows) then { + "" = ""; + "" = ""; + "" = ""; + "" = ""; + } else {}; + + vim.nnoremap = if (cfg.mapLeaderSpace) then { + "" = ""; + } else {}; + + vim.configRC = '' + + "Settings that are set for everything + encoding=utf-8 + set mouse=${mouseSupport} + + ${writeIf (cfg.lineNumberMode == "relative") '' + set relativenumber + ''} + + ${writeIf (cfg.lineNumberMode == "number") '' + set number + ''} + + ${writeIf (cfg.lineNumberMode == "relNumber") '' + set number relativenumber + ''} + + ${writeIf cfg.useSystemClipboard '' + set clipboard+=unnamedplus + ''} + + ${writeIf cfg.mapLeaderSpace '' + let mapleader=" " + let maplocalleader=" " + ''} + + ${writeIf cfg.syntaxHighlighting '' + syntax on + ''} + + ${writeIf (cfg.wordWrap == false) '' + set nowrap + ''} + + ${writeIf cfg.hideSearchHighlight '' + set nohlsearch + set incsearch + ''} + + ${writeIf cfg.colourTerm '' + set termguicolors + set t_Co=256 + ''} + + ''; + }); +} diff --git a/modules/basic/default.nix b/modules/basic/default.nix index 973cc88..f74ef7d 100644 --- a/modules/basic/default.nix +++ b/modules/basic/default.nix @@ -17,9 +17,121 @@ in { description = "Set to prevent arrow keys from moving cursor"; type = types.bool; }; + + hideSearchHighlight = mkOption { + default = true; + description = "Hide search highlight so it doesn't stay highlighted"; + type = types.bool; + }; + + scrollOffset = mkOption { + default = 8; + description = "Start scrolling this number of lines from the top or bottom of the page."; + type = types.int; + }; + + wordWrap = mkOption { + default = false; + description = "Enable word wrapping."; + type = types.bool; + }; + + syntaxHighlighting = mkOption { + default = true; + description = "Enable syntax highlighting"; + type = types.bool; + }; + + mapLeaderSpace = mkOption { + default = true; + description = "Map the space key to leader key"; + type = types.bool; + }; + + useSystemClipboard = mkOption { + default = true; + description = "Make use of the clipboard for default yank and paste operations. Don't use * and +"; + type = types.bool; + }; + + mouseSupport = mkOption { + default = "a"; + description = "Set modes for mouse support. a - all, n - normal, v - visual, i - insert, c - command"; + type = types.str; + }; + + lineNumberMode = mkOption { + default = "relNumber"; + description = "How line numbers are displayed. none, relative, number, relNumber"; + type = with types; enum ["relative" "number" "relNumber" "none"]; + }; + + preventJunkFiles = mkOption { + default = true; + description = "Prevent swapfile, backupfile from being created"; + type = types.bool; + }; + + tabWidth = mkOption { + default = 2; + description = "Set the width of tabs to 2"; + type = types.int; + }; + + autoIndent = mkOption { + default = true; + description = "Enable auto indent"; + type = types.bool; + }; + + cmdHeight = mkOption { + default = 2; + description = "Hight of the command pane"; + type = types.int; + }; + + updateTime = mkOption { + default = 300; + description = "The number of milliseconds till Cursor Hold event is fired"; + type = types.int; + }; + + showSignColumn = mkOption { + default = true; + description = "Show the sign column"; + type = types.bool; + }; + + bell = mkOption { + default = "none"; + description = "Set how bells are handled. Options: on, visual or none"; + type = types.enum [ "none" "visual" "on" ]; + }; + + mapTimeout = mkOption { + default = 500; + description = "Timeout in ms that neovim will wait for mapped action to complete"; + type = types.int; + }; + + splitBelow = mkOption { + default = true; + description = "New splits will open below instead of on top"; + type = types.bool; + }; + + splitRight = mkOption { + default = true; + description = "New splits will open to the right"; + type = types.bool; + }; + }; - config = { + config = ( + let + writeIf = cond: msg: if cond then msg else ""; + in { vim.nmap = if (cfg.disableArrows) then { "" = ""; @@ -35,11 +147,99 @@ in { "" = ""; } else {}; + vim.nnoremap = if (cfg.mapLeaderSpace) then { + "" = ""; + } else {}; + vim.configRC = '' - '' + (if cfg.colourTerm then '' - set termguicolors - set t_Co=256 - '' else ""); - }; + "Settings that are set for everything + set encoding=utf-8 + set mouse=${cfg.mouseSupport} + set tabstop=${toString cfg.tabWidth} + set shiftwidth=${toString cfg.tabWidth} + set softtabstop=${toString cfg.tabWidth} + set expandtab + set cmdheight=${toString cfg.cmdHeight} + set updatetime=${toString cfg.updateTime} + set shortmess+=c + set tm=${toString cfg.mapTimeout} + set hidden + + ${writeIf cfg.splitBelow '' + set splitbelow + ''} + + ${writeIf cfg.splitRight '' + set splitright + ''} + + ${writeIf cfg.showSignColumn '' + set signcolumn=yes + ''} + + ${writeIf cfg.autoIndent '' + set ai + ''} + + ${writeIf cfg.preventJunkFiles '' + set noswapfile + set nobackup + set nowritebackup + ''} + + ${writeIf (cfg.bell == "none") '' + set noerrorbells + set novisualbell + ''} + + ${writeIf (cfg.bell == "on") '' + set novisualbell + ''} + + ${writeIf (cfg.bell == "visual") '' + set noerrorbells + ''} + + ${writeIf (cfg.lineNumberMode == "relative") '' + set relativenumber + ''} + + ${writeIf (cfg.lineNumberMode == "number") '' + set number + ''} + + ${writeIf (cfg.lineNumberMode == "relNumber") '' + set number relativenumber + ''} + + ${writeIf cfg.useSystemClipboard '' + set clipboard+=unnamedplus + ''} + + ${writeIf cfg.mapLeaderSpace '' + let mapleader=" " + let maplocalleader=" " + ''} + + ${writeIf cfg.syntaxHighlighting '' + syntax on + ''} + + ${writeIf (cfg.wordWrap == false) '' + set nowrap + ''} + + ${writeIf cfg.hideSearchHighlight '' + set nohlsearch + set incsearch + ''} + + ${writeIf cfg.colourTerm '' + set termguicolors + set t_Co=256 + ''} + + ''; + }); }