2023-04-24 07:22:33 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2022-11-22 05:28:41 +00:00
|
|
|
|
2023-01-28 00:19:48 +00:00
|
|
|
let
|
|
|
|
inherit (builtins) map;
|
2023-04-24 07:22:33 +00:00
|
|
|
inherit (lib) concatMapStrings mkIf optionalString;
|
2023-01-28 00:19:48 +00:00
|
|
|
# this structure roughly mirrors home-manager's `programs.neovim.plugins` option
|
|
|
|
plugins = with pkgs.vimPlugins; [
|
2023-06-26 00:06:33 +00:00
|
|
|
{
|
|
|
|
# docs: fzf-vim (fuzzy finder): https://github.com/junegunn/fzf.vim
|
|
|
|
plugin = fzf-vim;
|
|
|
|
}
|
|
|
|
{
|
2023-01-28 00:19:48 +00:00
|
|
|
# treesitter syntax highlighting: https://nixos.wiki/wiki/Tree_sitters
|
|
|
|
# docs: https://github.com/nvim-treesitter/nvim-treesitter
|
|
|
|
# config taken from: https://github.com/i077/system/blob/master/modules/home/neovim/default.nix
|
|
|
|
# this is required for tree-sitter to even highlight
|
2023-07-07 10:45:41 +00:00
|
|
|
plugin = nvim-treesitter.withPlugins (_: nvim-treesitter.allGrammars ++ [
|
|
|
|
# XXX: this is apparently not enough to enable syntax highlighting!
|
|
|
|
# nvim-treesitter ships its own queries which may be distinct from e.g. helix.
|
|
|
|
# the queries aren't included when i ship the grammar in this manner
|
|
|
|
pkgs.tree-sitter-nix-shell
|
|
|
|
]);
|
2023-01-28 00:19:48 +00:00
|
|
|
type = "lua";
|
|
|
|
config = ''
|
2024-02-20 10:23:52 +00:00
|
|
|
-- lifted mostly from readme: <https://github.com/nvim-treesitter/nvim-treesitter>
|
2023-01-28 00:19:48 +00:00
|
|
|
require'nvim-treesitter.configs'.setup {
|
|
|
|
highlight = {
|
|
|
|
enable = true,
|
|
|
|
-- disable treesitter on Rust so that we can use SyntaxRange
|
|
|
|
-- and leverage TeX rendering in rust projects
|
|
|
|
disable = { "rust", "tex", "latex" },
|
|
|
|
-- disable = { "tex", "latex" },
|
|
|
|
-- true to also use builtin vim syntax highlighting when treesitter fails
|
|
|
|
additional_vim_regex_highlighting = false
|
|
|
|
},
|
|
|
|
incremental_selection = {
|
|
|
|
enable = true,
|
|
|
|
keymaps = {
|
|
|
|
init_selection = "gnn",
|
|
|
|
node_incremental = "grn",
|
2024-02-20 10:23:52 +00:00
|
|
|
scope_incremental = "grc",
|
2023-01-28 00:19:48 +00:00
|
|
|
node_decremental = "grm"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
indent = {
|
|
|
|
enable = true,
|
|
|
|
disable = {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vim.o.foldmethod = 'expr'
|
|
|
|
vim.o.foldexpr = 'nvim_treesitter#foldexpr()'
|
|
|
|
'';
|
2023-06-26 00:06:33 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
# docs: tex-conceal-vim: https://github.com/KeitaNakamura/tex-conceal.vim/
|
|
|
|
plugin = tex-conceal-vim;
|
|
|
|
type = "viml";
|
|
|
|
config = ''
|
|
|
|
" present prettier fractions
|
|
|
|
let g:tex_conceal_frac=1
|
|
|
|
'';
|
|
|
|
}
|
2023-06-26 00:22:13 +00:00
|
|
|
{
|
|
|
|
# source: <https://github.com/LnL7/vim-nix>
|
|
|
|
# fixes auto-indent (incl tab size) when editing .nix files
|
|
|
|
plugin = vim-nix;
|
|
|
|
}
|
2023-06-26 00:06:33 +00:00
|
|
|
{
|
|
|
|
# docs: surround-nvim: https://github.com/ur4ltz/surround.nvim/
|
|
|
|
# docs: vim-surround: https://github.com/tpope/vim-surround
|
|
|
|
plugin = vim-surround;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
plugin = vim-SyntaxRange;
|
|
|
|
type = "viml";
|
|
|
|
config = ''
|
|
|
|
" enable markdown-style codeblock highlighting for tex code
|
|
|
|
autocmd BufEnter * call SyntaxRange#Include('```tex', '```', 'tex', 'NonText')
|
|
|
|
" autocmd Syntax tex set conceallevel=2
|
|
|
|
'';
|
|
|
|
}
|
2023-01-28 00:19:48 +00:00
|
|
|
];
|
|
|
|
plugin-packages = map (p: p.plugin) plugins;
|
2023-07-04 10:28:44 +00:00
|
|
|
plugin-config-viml = concatMapStrings (p: optionalString (p.type or "" == "viml") p.config) plugins;
|
2023-01-28 00:19:48 +00:00
|
|
|
plugin-config-lua = concatMapStrings (p: optionalString (p.type or "" == "lua") p.config) plugins;
|
|
|
|
in
|
2022-10-21 15:30:35 +00:00
|
|
|
{
|
2023-06-27 10:26:11 +00:00
|
|
|
sane.programs.neovim = {
|
2024-01-28 10:39:08 +00:00
|
|
|
sandbox.method = "bwrap";
|
2024-02-25 01:55:46 +00:00
|
|
|
sandbox.autodetectCliPaths = "existingOrParent";
|
2024-02-14 09:11:31 +00:00
|
|
|
sandbox.whitelistWayland = true; # for system clipboard integration
|
2024-01-28 10:39:08 +00:00
|
|
|
# sandbox.whitelistPwd = true;
|
|
|
|
sandbox.extraHomePaths = [
|
|
|
|
# directories where i'm liable to `:e ../...`
|
|
|
|
# "archive"
|
|
|
|
"dev"
|
|
|
|
"knowledge"
|
|
|
|
"nixos"
|
|
|
|
"records"
|
|
|
|
"ref"
|
|
|
|
"tmp"
|
|
|
|
# "use"
|
|
|
|
];
|
2024-02-14 09:11:31 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
packageUnwrapped = let
|
|
|
|
configArgs = {
|
|
|
|
withRuby = false; #< doesn't cross-compile w/o binfmt
|
|
|
|
viAlias = true;
|
|
|
|
vimAlias = true;
|
|
|
|
plugins = plugin-packages;
|
|
|
|
customRC = ''
|
|
|
|
" let the terminal handle mouse events, that way i get OS-level ctrl+shift+c/etc
|
|
|
|
" this used to be default, until <https://github.com/neovim/neovim/pull/19290>
|
|
|
|
set mouse=
|
2023-01-28 00:19:48 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
" copy/paste to system clipboard
|
|
|
|
set clipboard=unnamedplus
|
2022-10-21 15:30:35 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
" screw tabs; always expand them into spaces
|
|
|
|
set expandtab
|
2022-10-21 15:30:35 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
" at least don't open files with sections folded by default
|
|
|
|
set nofoldenable
|
2022-10-21 15:30:35 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
" allow text substitutions for certain glyphs.
|
|
|
|
" higher number = more aggressive substitution (0, 1, 2, 3)
|
|
|
|
" i only make use of this for tex, but it's unclear how to
|
|
|
|
" apply that *just* to tex and retain the SyntaxRange stuff.
|
|
|
|
set conceallevel=2
|
2022-10-21 15:30:35 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
" horizontal rule under the active line
|
|
|
|
" set cursorline
|
2022-10-21 15:30:35 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
" highlight trailing space & related syntax errors (doesn't seem to work??)
|
|
|
|
" let c_space_errors=1
|
|
|
|
" let python_space_errors=1
|
2022-10-21 15:30:35 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
" enable highlighting of leading/trailing spaces,
|
|
|
|
" and especially tabs
|
|
|
|
" source: https://www.reddit.com/r/neovim/comments/chlmfk/highlight_trailing_whitespaces_in_neovim/
|
|
|
|
set list
|
|
|
|
set listchars=tab:▷\·,trail:·,extends:◣,precedes:◢,nbsp:○
|
2022-10-21 15:30:35 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
""""" PLUGIN CONFIG (vim)
|
|
|
|
${plugin-config-viml}
|
2022-10-21 15:30:35 +00:00
|
|
|
|
2024-05-13 17:05:14 +00:00
|
|
|
""""" PLUGIN CONFIG (lua)
|
|
|
|
lua <<EOF
|
|
|
|
${plugin-config-lua}
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in pkgs.wrapNeovimUnstable
|
|
|
|
pkgs.neovim-unwrapped
|
|
|
|
# XXX(2024/05/13): manifestRc must be null for cross-compilation to work.
|
|
|
|
# wrapper invokes `neovim` with all plugins enabled at build time i guess to generate caches and stuff?
|
|
|
|
# alternative is to emulate `nvim-wrapper` during build.
|
|
|
|
((pkgs.neovimUtils.makeNeovimConfig configArgs) // { manifestRc = null; })
|
|
|
|
;
|
2023-11-25 04:46:24 +00:00
|
|
|
|
|
|
|
# private because there could be sensitive things in the swap
|
|
|
|
persist.byStore.private = [ ".cache/vim-swap" ];
|
|
|
|
env.EDITOR = "vim";
|
|
|
|
# git claims it should use EDITOR, but it doesn't!
|
|
|
|
env.GIT_EDITOR = "vim";
|
|
|
|
mime.priority = 200; # default=100 => yield to other, more specialized applications
|
|
|
|
mime.associations."application/schema+json" = "nvim.desktop";
|
|
|
|
mime.associations."plain/text" = "nvim.desktop";
|
|
|
|
mime.associations."text/markdown" = "nvim.desktop";
|
2022-10-21 15:30:35 +00:00
|
|
|
};
|
|
|
|
}
|