dotfiles/hm/vim/default.nix

195 lines
5.8 KiB
Nix
Raw Normal View History

2024-01-08 23:04:24 +01:00
{ pkgs, lib, config, ... }:
{
# config = lib.mkIf config.programs.nixvim.enable { # Somehow this is infinite recursion?
config = {
2024-01-11 23:54:03 +01:00
home.sessionVariables = {
EDITOR = "nvim";
} // lib.optionalAttrs config.frogeye.desktop.xorg {
VISUAL = "nvim";
};
programs.bash.shellAliases = {
vi = "nvim";
vim = "nvim";
};
2024-01-08 23:04:24 +01:00
programs.nixvim = {
options = {
ignorecase = true;
smartcase = true;
gdefault = true;
tabstop = 4;
shiftwidth = 4;
expandtab = true;
splitbelow = true;
visualbell = true;
updatetime = 250;
undofile = true;
wildmode = "longest:full,full";
wildmenu = true;
};
globals = {
netrw_fastbrowse = 0; # Close the file explorer once you select a file
};
plugins = {
# Go to whatever
telescope = {
enable = true;
keymaps = {
gF = "find_files";
gf = "git_files";
gB = "buffers";
gl = "current_buffer_fuzzy_find";
gL = "live_grep";
gT = "tags";
gt = "treesitter";
gm = "marks";
gh = "oldfiles";
gH = "command_history";
gS = "search_history";
gC = "commands";
gr = "lsp_references";
ge = "diagnostics";
# ga = "lsp_code_actions";
# gE = "lsp_workspace_diagnostics";
# TODO Above makes nvim crash on startup, action is not provided
gd = "lsp_definitions";
gs = "lsp_document_symbols";
};
defaults = {
vimgrep_arguments = [
"${pkgs.ripgrep}/bin/rg"
"--color=never"
"--no-heading"
"--with-filename"
"--line-number"
"--column"
"--smart-case"
];
};
extensions.fzf-native = {
enable = true;
caseMode = "smart_case";
fuzzy = true;
overrideFileSorter = true;
overrideGenericSorter = true;
};
};
# Surrounding pairs
surround.enable = true; # Change surrounding pairs (e.g. brackets, quotes)
undotree.enable = true; # Navigate edition history
# Git
fugitive.enable = true; # Git basics
gitsigns.enable = true; # Show changed lines in the gutter
};
extraPlugins = with pkgs.vimPlugins; [
# Search/replace
vim-abolish # Regex for words, with case in mind
vim-easy-align # Aligning lines around a certain character
# Surrounding pairs
targets-vim # Better interaction with surrounding pairs
# Registers
registers-nvim # Show register content when pressing "
# TODO Doesn't work. Didn't work on Arch either
# Tags
vim-gutentags # Generate tags
symbols-outline-nvim # Show a symbol panel on the right
# TODO Fails on startup. Same on Arch. Config issue?
# Git
fugitive-gitlab-vim # Open files in GitLab
# TODO Connect it!
# Language-specific
tcomment_vim # Language-aware (un)commenting
] ++ lib.optionals config.frogeye.extra [
vim-LanguageTool # Check grammar for human languages
] ++ lib.optionals config.programs.pandoc.enable [
vim-pandoc # Pandoc-specific stuff because there's no LSP for it
vim-pandoc-syntax
] ++ lib.optionals config.frogeye.dev.ansible [
ansible-vim # TODO Doesn't have snippets
];
2024-01-12 18:08:11 +01:00
extraConfigLua = builtins.readFile ./symbols-outline-nvim.lua;
2024-01-08 23:04:24 +01:00
extraConfigVim = ''
" GENERAL
" Avoid showing message extra message when using completion
set shortmess+=c
command Reload source $MYVIMRC
" PLUGINS
" vim-gutentags
let g:gutentags_cache_dir = expand('~/.cache/nvim/tags')
'' + lib.optionalString config.frogeye.extra ''
" languagetool
let g:languagetool_cmd = "${pkgs.languagetool}/bin/languagetool-commandline"
" TODO Doesn't work
'' + lib.optionalString config.programs.pandoc.enable ''
" vim-pandox
let g:pandoc#modules#disabled = ["folding"]
let g:pandoc#spell#enabled = 0
let g:pandoc#syntax#conceal#use = 0
'';
autoCmd = [
# vim-easy-align: Align Markdown tables
{ event = "FileType"; pattern = "markdown"; command = "vmap <Bar> :EasyAlign*<Bar><Enter>"; }
];
userCommands = {
# Reload = { command = "source $MYVIRMC"; };
# TODO Is not working, options is set to nil even though it shouldn't
};
keymaps = [
# GENERAL
# Allow saving of files as sudo when I forgot to start vim using sudo.
# From https://stackoverflow.com/a/7078429
{ mode = "c"; key = "w!!"; action = "w !sudo tee > /dev/null %"; }
{ mode = "i"; key = "jk"; action = "<Esc>"; }
{ mode = "v"; key = "<Enter>"; action = "<Esc>"; }
{ key = "<Enter>"; action = "o<Esc>"; }
# { key = "<C-H>"; action = ":bp<CR>"; }
# { key = "<C-L>"; action = ":bn<CR>"; }
{ key = "<C-K>"; action = "kkkkkkkkkkkkkkkkkkkkk"; }
{ key = "<C-J>"; action = "jjjjjjjjjjjjjjjjjjjjj"; }
# \s to replace globally the word under the cursor
{ key = "<Leader>s"; action = ":%s/\\<<C-r><C-w>\\>/"; }
# PLUGINS
# symbols-outline-nvim
{ key = "<Space>s"; action = "<Cmd>SymbolsOutline<CR>"; options = { silent = true; }; }
# undotree
{ key = "<Space>u"; action = "<Cmd>UndotreeToggle<CR>"; options = { silent = true; }; }
];
};
};
imports = [
2024-01-12 18:08:11 +01:00
./code.nix
./completion.nix
2024-01-12 18:08:11 +01:00
./decoration.nix
./lsp.nix
];
2024-01-08 23:04:24 +01:00
}