-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvim.nix
67 lines (54 loc) · 1.7 KB
/
vim.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{ pkgs, config, lib, ... }:
with lib;
let
# A script that calls 'vim' from the user's env.
# This is the default value for the 'vim.bin' option.
impure_vim = pkgs.writeShellScript "impure-vim" ''
exec vim "$@"
'';
# Escaped for bash
viminfo_path_esc = ''"$HOME"/${escapeShellArg config.cache_dir}/viminfo'';
session_path_esc = ''"$HOME"/${escapeShellArg config.cache_dir}/session.vim'';
vimrc_file = builtins.toFile "vimrc" config.vim.vimrc;
in {
options = {
vim = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Enable vim. The 'command' is set to call Vim, with a custom .vimrc
and a session file.
The session file is saved automatically when Vim exists. (eg. with :qa)
'';
};
bin = mkOption {
type = types.path;
default = impure_vim;
description =
"Vim binary to use. The default is to lookup vim from the PATH.";
};
vimrc = mkOption {
type = types.lines;
default = "";
description = "Local vimrc.";
};
};
};
config = mkIf (config.vim.enable != "") {
command = ''
exec ${config.vim.bin} -i ${viminfo_path_esc} -S ${vimrc_file} -S ${session_path_esc}
'';
activation_script = ''
session_path=${session_path_esc}
if ! [[ -e $session_path ]]; then
echo "let v:this_session = \"$session_path\"" > "$session_path"
fi
'';
vim.vimrc = ''
" Remove some session options to make it work better with automatic sessions
set sessionoptions=blank,help,tabpages,winsize,terminal
autocmd VimLeave * execute "mksession!" v:this_session
'';
};
}