nixos-config/modules/programs/vim.nix

225 lines
5.1 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
{ config, lib, pkgs, ... }:
let
cfg = config.programs.custom.vim;
nix-xptemplates = pkgs.writeTextFile {
2019-12-20 05:54:26 +01:00
name = "nix-xptemplates";
2019-10-24 02:20:38 +02:00
destination = "/ftplugin/nix/nix.xpt.vim";
2019-12-20 05:54:26 +01:00
text = # vim
''
XPTemplate priority=personal
XPT option " tips
`name^ = mkOption {
type = with types; `type^;
description = ${"''"}
`cursor^
${"''"};
};
XPT package " tips
{ config, lib, ... }:
{
`cursor^
}
XPT terranix" tips
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.`name^;
in {
options.`name^ = mkOption {
default = {};
type = with types; attrsOf (submodule ({ name, ... }:{
options = {
enable = mkEnableOption "`name^.name";
};
}));
};
config =
let
allConfigs = cfg
in
mkIf (cfg != {} ){
`cursor^
};
}
XPT module " tips
{ config, lib, pkgs, ... }:
with lib;
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
let
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
cfg = config.`name^;
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
in {
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
options.`name^ = {
enable = mkEnableOption "enable `name^";
};
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
config = mkIf cfg.enable {
`cursor^
};
}
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
XPT shell " tips
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
# needed pkgs
# -----------
buildInputs = with pkgs; [
`name^
];
2019-10-24 02:20:38 +02:00
2019-12-20 05:54:26 +01:00
# run this on start
# -----------------
shellHook = ${"''"}
HISTFILE=${"$"}{toString ./.}/.history
${"''"};
}
XPT fhsUser " tips
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
name = "fhs-user-env";
targetPkgs = pkgs: with pkgs; [
# core stuff
# ----------
vim silver-searcher curl coreutils git tig
# common X dependencies
# ---------------------
atk cairo dbus eudev expat fontconfig freetype gdk_pixbuf glib gnome3.GConf gtk2-x11
mesa_glu nspr nss pango xlibs.libXScrnSaver xlibs.libXcomposite xlibs.libXcursor
xlibs.libXdamage xlibs.libXfixes xlibs.libXi xlibs.libXrender xlibs.libXtst xorg.libX11
xorg.libXext xorg.libXinerama xorg.libxcb
liblo zlib fftw minixml libcxx alsaLib glibc
# new stuff
# ---------
`cursor^
];
# multilib packages
# -----------------
# these are packages compiled 32bit and 64bit
multiPkgs = pkgs: with pkgs; [
];
# environment variables
# ---------------------
profile = ${"''"}
export TERM="xterm"
${"''"};
}).env
'';
2019-10-24 02:20:38 +02:00
};
# active plugins
# --------------
2019-12-20 05:54:26 +01:00
extra-runtimepath = with pkgs;
lib.concatMapStringsSep "," (pkg: "${pkg.rtp}") [
vimPlugins.Syntastic
vimPlugins.ack-vim
vimPlugins.airline
vimPlugins.vim-nix
vimPlugins.xptemplate
];
2019-10-24 02:20:38 +02:00
# the vimrc
# ---------
vimrc = pkgs.writeText "vimrc" ''
" turn on linenumbers
" to turn of :set nonumber
:set number
" show Trailing Whitespaces
:set list listchars=tab:»·,trail:
" Map leader is the key for shortcuts
nnoremap <SPACE> <Nop>
let mapleader = "\<Space>"
" move blocks of text in visual mode
" does not work correctly
vmap <up> xkP`[V`]
vmap <down> xp`[V`]
" search/grep case insensitive
:set ignorecase
" tabs should always be 2 spaces
set et ts=2 sts=2 sw=2
" installed vim-plugins
set runtimepath=${extra-runtimepath},$VIMRUNTIME,$HOME/.vim,${nix-xptemplates}
" syntax highlighting on
syntax on
" xptemplates
" -----------
" a plugin to insert snippets on demand
set nocompatible
filetype plugin on
" enable cursor cross
" -------------------
":hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
":hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
:hi CursorLine cterm=NONE ctermbg=0 guibg=#073642
:hi CursorColumn cterm=NONE ctermbg=0 guibg=#073642
set cursorline
set cursorcolumn
" save view
" ---------
augroup AutoSaveFolds
autocmd!
autocmd BufWinLeave * mkview
autocmd BufWinEnter * silent loadview
augroup END
2019-11-21 00:38:29 +01:00
" some language stuff
" -------------------
:map <leader>s :setlocal spell spelllang=en
2019-10-24 02:20:38 +02:00
'';
in {
# no options
options.programs.custom.vim.enable = lib.mkEnableOption "vim";
config = lib.mkIf cfg.enable {
# create vimrc
# ------------
# and load it as config for vim
environment.variables.VIMINIT = ":so /etc/vimrc";
environment.etc.vimrc.source = vimrc;
# set vim to the default editor
# -----------------------------
programs.vim.defaultEditor = true;
# install vim
# -----------
2019-12-20 05:54:26 +01:00
environment.systemPackages = [ pkgs.vim ];
2019-10-24 02:20:38 +02:00
};
}