dotfiles/config/nix/hm/vim.nix

409 lines
14 KiB
Nix
Raw Normal View History

2023-11-19 22:41:09 +01:00
{ pkgs, lib, config, ... }:
2023-10-29 12:15:56 +01:00
let
nixvim = import (builtins.fetchGit {
url = "https://github.com/nix-community/nixvim";
ref = "nixos-23.05";
});
2023-10-31 22:26:01 +01:00
vim-shot-f = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "vim-shot-f";
version = "2016-02-05";
src = pkgs.fetchFromGitHub {
owner = "deris";
repo = "vim-shot-f";
rev = "eea71d2a1038aa87fe175de9150b39dc155e5e7f";
sha256 = "iAPvIs/lhW+w5kFTZKaY97D/kfCGtqKrJVFvZ8cHu+c=";
};
meta.homepage = "https://github.com/deris/vim-shot-f";
};
2023-11-22 00:52:31 +01:00
quick-scope = pkgs.vimUtils.buildVimPluginFrom2Nix rec {
2023-10-31 22:26:01 +01:00
pname = "quick-scope";
version = "2.6.1";
src = pkgs.fetchFromGitHub {
2023-11-22 00:52:31 +01:00
owner = "unblevable";
2023-10-31 22:26:01 +01:00
repo = "quick-scope";
2023-11-22 00:52:31 +01:00
rev = "v${version}";
sha256 = "TcA4jZIdnQd06V+JrXGiCMr0Yhm9gB6OMiTSdzMt/Qw=";
2023-10-31 22:26:01 +01:00
};
meta.homepage = "https://github.com/unblevable/quick-scope";
};
2023-10-29 12:15:56 +01:00
in
{
imports = [
nixvim.homeManagerModules.nixvim
];
programs.nixvim = {
enable = true;
options = {
# From https://www.hillelwayne.com/post/intermediate-vim/
title = true;
number = true;
relativenumber = true;
scrolloff = 10;
lazyredraw = true; # Do not redraw screen in the middle of a macro. Makes them complete faster.
cursorcolumn = true;
ignorecase = true;
smartcase = true;
gdefault = true;
tabstop = 4;
shiftwidth = 4;
expandtab = true;
splitbelow = true;
visualbell = true;
updatetime = 250;
undofile = true;
# From http://stackoverflow.com/a/5004785/2766106
list = true;
listchars = "tab:,trail:·,extends:,precedes:,nbsp:_";
showbreak = "";
wildmode = "longest:full,full";
wildmenu = true;
};
globals = {
netrw_fastbrowse = 0; # Close the file explorer once you select a file
};
2023-10-29 12:15:56 +01:00
colorschemes.base16 = {
# FIXME Dynamic... or use stylix
enable = true;
colorscheme = "solarized-light";
};
plugins = {
# Catches attention when cursor changed position
# TODO Unmapped, do I still want to use it?
specs = {
enable = true;
min_jump = 5;
2023-11-02 17:06:46 +01:00
fader = { builtin = "pulse_fader"; };
resizer = { builtin = "shrink_resizer"; };
2023-10-29 12:15:56 +01:00
};
# Tabline
barbar.enable = true;
# Go to whatever
telescope = {
enable = true;
2023-10-31 23:48:01 +01:00
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";
# ga = "lsp_code_actions";
# ge = "lsp_document_diagnostics";
# gE = "lsp_workspace_diagnostics";
# FIXME 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;
};
};
2023-10-31 22:26:01 +01:00
# Surrounding pairs
surround.enable = true; # Change surrounding pairs (e.g. brackets, quotes)
2023-10-31 23:48:01 +01:00
# Language Server
lsp = {
enable = true;
keymaps = {
silent = true;
diagnostic = {
"<Space>e" = "open_float";
"[e" = "goto_prev";
"]e" = "goto_next";
};
lspBuf = {
"gD" = "declaration";
"K" = "hover";
"gi" = "implementation";
"<C-S-k>" = "signature_help";
"<space>wa" = "add_workspace_folder";
"<space>wr" = "remove_workspace_folder";
# "<space>wl" = "list_workspace_folder";
# TODO Full thing was function() print(vim.inspect(vim.lsp.buf.list_workspace_folder())) end but not sure I'm ever really using this
# Also makes nvim crash like this, so uncommented
"<space>D" = "type_definition";
"<space>rn" = "rename";
"<space>f" = "format";
# TODO Full thing was function() vim.lsp.buf.format { async = true } end, so async while this isn't
# Maybe replace this with lsp-format?
};
};
servers = {
# FIXME ansiblels
bashls.enable = true; # Bash
jsonls.enable = true; # JSON
lua-ls.enable = true; # Lua (for Neovim debugging)
2023-10-31 23:48:01 +01:00
# FIXME perlls
2023-11-22 16:32:20 +01:00
pylsp = lib.mkIf config.frogeye.dev.python {
# Python
2023-10-31 23:48:01 +01:00
enable = true;
settings.plugins = {
black.enabled = true;
2023-11-12 22:44:20 +01:00
flake8 = {
enabled = true;
maxLineLength = 88; # Compatibility with Black
};
2023-10-31 23:48:01 +01:00
isort.enabled = true;
mccabe.enabled = true;
2023-11-19 22:41:09 +01:00
pycodestyle = {
enabled = true;
maxLineLength = 88; # Compatibility with Black
};
pyflakes.enabled = true;
pylint.enabled = true;
2023-11-19 22:41:09 +01:00
pylsp_mypy = {
enabled = true;
overrides = [
"--cache-dir=${config.xdg.cacheHome}/mypy"
"--ignore-missing-imports"
"--disallow-untyped-defs"
"--disallow-untyped-calls"
"--disallow-incomplete-defs"
"--disallow-untyped-decorators"
];
};
# FIXME Somehow no warning is shown
# TODO Could add some, could also remove some
2023-10-31 23:48:01 +01:00
};
};
# FIXME phpactor. Only from 23.11
# phpactor.enable = true; # PHP
rnix-lsp.enable = true; # Nix
# FIXME sqlls
yamlls.enable = true; # YAML
2023-10-31 23:48:01 +01:00
# TODO Check out none-ls
};
# FIXME vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') as onAttach... is it needed?
# FIXME flags = { debounce_text_changes = 150 } is the default value ok? Maybe it was actually ignored
};
nvim-lightbulb = {
# Shows a lightbulb whenever a codeAction is available under the cursor
2023-10-31 23:48:01 +01:00
enable = true;
autocmd.enabled = true;
};
lspkind.enable = true; # Add icons to LSP completions
2023-11-01 09:17:01 +01:00
# Treesitter
treesitter = {
# Allows for better syntax highlighting
2023-11-01 09:17:01 +01:00
enable = true;
incrementalSelection = {
enable = true;
};
# indent = true; # Not very working last time I tried apparently
};
# TODO Investigate https://github.com/nvim-treesitter/nvim-treesitter-textobjects
indent-blankline.enable = true; # 23.11 integrate with rainbow-delimiters and use more of the options
2023-11-02 15:42:17 +01:00
undotree.enable = true; # Navigate edition history
# Git
fugitive.enable = true; # Git basics
gitsigns.enable = true; # Show changed lines in the gutter
# Language-specific
# dap.enable = true; # Debug Adapter Protocol client # 23.11
nvim-colorizer.enable = true; # Display colors of color-codes
2023-10-29 12:15:56 +01:00
};
extraPlugins = with pkgs.vimPlugins; [
2023-10-31 22:26:01 +01:00
nvim-scrollview # Scroll bar
# Status line
2023-10-31 22:26:01 +01:00
feline-nvim # Customizable status line.
# TODO Abandonned. Maybe use lualine?
# 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
# f/F mode
vim-shot-f # Highlight relevant characters for f/F/t/T modes
quick-scope # Highlight relevant characters for f/F modes one per word but always
# 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?
2023-10-31 23:48:01 +01:00
# Language server
lsp_signature-nvim # Show argument definition when typing a function
2023-11-01 09:17:01 +01:00
# Treesitter
nvim-ts-rainbow # Randomly color parenthesis pairs
# 23.11: Replace with plugins.rainbow-delimiters
2023-11-01 18:03:14 +01:00
# Snippets
vim-vsnip
vim-vsnip-integ
friendly-snippets
# Auto-completion
nvim-compe
# TODO Archived. Maybe use nvim-cmp and plugins instead?
2023-11-02 15:42:17 +01:00
# Git
fugitive-gitlab-vim # Open files in GitLab
# TODO Connect it!
# Language-specific
tcomment_vim # Language-aware (un)commenting
2023-11-22 16:32:20 +01:00
] ++ lib.optionals config.frogeye.extra [
2023-11-02 15:42:17 +01:00
vim-LanguageTool # Check grammar for human languages
2023-11-22 16:32:20 +01:00
] ++ lib.optionals config.programs.pandoc.enable [
2023-11-02 15:42:17 +01:00
vim-pandoc # Pandoc-specific stuff because there's no LSP for it
vim-pandoc-syntax
2023-11-22 16:32:20 +01:00
] ++ lib.optionals config.frogeye.dev.c [
2023-11-02 15:42:17 +01:00
nvim-dap # Debug Adapter Protocol client
2023-11-22 16:32:20 +01:00
] ++ lib.optionals config.frogeye.dev.ansible [
2023-11-02 15:42:17 +01:00
ansible-vim # FIXME See if it doesn't require to do ./UltiSnips/generate.sh
2023-10-31 22:26:01 +01:00
];
extraConfigLua = lib.strings.concatMapStringsSep "\n" (f: builtins.readFile f) [
./vim/feline.lua
./vim/symbols-outline-nvim.lua
2023-10-31 23:48:01 +01:00
./vim/lsp_signature-nvim.lua
2023-11-01 09:17:01 +01:00
./vim/nvim-ts-rainbow.lua
2023-10-31 22:26:01 +01:00
];
extraConfigVim = ''
" GENERAL
" Avoid showing message extra message when using completion
set shortmess+=c
command Reload source $MYVIMRC
" PLUGINS
2023-10-31 22:26:01 +01:00
" vim-gutentags
let g:gutentags_cache_dir = expand('~/.cache/nvim/tags')
2023-11-01 18:03:14 +01:00
" nvim-compe
" Copy-pasted because I couldn't be bothered
set completeopt=menuone,noselect
inoremap <silent><expr> <C-Space> compe#complete()
inoremap <silent><expr> <CR> compe#confirm('<CR>')
inoremap <silent><expr> <C-e> compe#close('<C-e>')
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
2023-11-22 16:32:20 +01:00
'' + lib.optionalString config.frogeye.extra ''
2023-11-02 15:42:17 +01:00
" languagetool
let g:languagetool_cmd = "${pkgs.languagetool}/bin/languagetool-commandline"
" TODO Doesn't work
2023-11-22 16:32:20 +01:00
'' + lib.optionalString config.programs.pandoc.enable ''
2023-11-02 15:42:17 +01:00
" vim-pandox
let g:pandoc#modules#disabled = ["folding"]
let g:pandoc#spell#enabled = 0
let g:pandoc#syntax#conceal#use = 0
2023-10-31 22:26:01 +01:00
'';
autoCmd = [
# Turn off relativenumber only for insert mode
{ event = "InsertEnter *"; command = "set norelativenumber"; }
{ event = "InsertLeave *"; command = "set relativenumber"; }
# Additional extensions
{ event = "BufNewFile,BufRead"; pattern = "*.jinja"; command = "set filetype=jinja2"; } # TODO Probably GH-specific?
2023-10-31 22:26:01 +01:00
# vim-easy-align: Align Markdown tables
{ event = "FileType markdown"; command = "vmap <Bar> :EasyAlign*<Bar><Enter>"; }
2023-10-29 12:15:56 +01:00
];
userCommands = {
# Reload = { command = "source $MYVIRMC"; };
# TODO Is not working, options is set to nil even though it shouldn't
};
2023-10-29 12:15:56 +01:00
# 23.11: Use keymaps, seems better
maps = {
# GENERAL
# Allow saving of files as sudo when I forgot to start vim using sudo.
# From https://stackoverflow.com/a/7078429
command."w!!" = { action = "w !sudo tee > /dev/null %"; };
insert."jk" = { action = "<Esc>"; };
visual."<Enter>" = { action = "<Esc>"; };
normal."<Enter>" = { action = "o<Esc>"; };
# normal."<C-H>" = { action = ":bp<CR>"; };
# normal."<C-L>" = { action = ":bn<CR>"; };
normal."<C-K>" = { action = "kkkkkkkkkkkkkkkkkkkkk"; };
normal."<C-J>" = { action = "jjjjjjjjjjjjjjjjjjjjj"; };
# \s to replace globally the word under the cursor
normal."<Leader>s" = { action = ":%s/\\<<C-r><C-w>\\>/"; };
# PLUGINS
2023-10-29 12:15:56 +01:00
# barbar
normal."<C-H>" = { action = "<Cmd>BufferPrevious<CR>"; silent = true; };
normal."<C-L>" = { action = "<Cmd>BufferNext<CR>"; silent = true; };
# TODO https://www.reddit.com/r/neovim/comments/mbj8m5/how_to_setup_ctrlshiftkey_mappings_in_neovim_and/
normal."<Space><C-H>" = { action = "<Cmd>BufferMovePrevious<CR>"; silent = true; };
normal."<Space><C-L>" = { action = "<Cmd>BufferMoveNext<CR>"; silent = true; };
# TODO gotos don't work
normal."<C-1>" = { action = "<Cmd>BufferGoto 1<CR>"; silent = true; };
normal."<C-2>" = { action = "<Cmd>BufferGoto 2<CR>"; silent = true; };
normal."<C-3>" = { action = "<Cmd>BufferGoto 3<CR>"; silent = true; };
normal."<C-4>" = { action = "<Cmd>BufferGoto 4<CR>"; silent = true; };
normal."<C-5>" = { action = "<Cmd>BufferGoto 5<CR>"; silent = true; };
normal."<C-6>" = { action = "<Cmd>BufferGoto 6<CR>"; silent = true; };
normal."<C-7>" = { action = "<Cmd>BufferGoto 7<CR>"; silent = true; };
normal."<C-8>" = { action = "<Cmd>BufferGoto 8<CR>"; silent = true; };
normal."<C-9>" = { action = "<Cmd>BufferGoto 9<CR>"; silent = true; };
normal."<C-0>" = { action = "<Cmd>BufferLast<CR>"; silent = true; };
normal."gb" = { action = "<Cmd>BufferPick<CR>"; silent = true; };
# TODO Other useful options?
2023-10-31 22:26:01 +01:00
# symbols-outline-nvim
normal."<Space>s" = { action = "<Cmd>SymbolsOutline<CR>"; silent = true; };
2023-11-02 15:42:17 +01:00
# undotree
normal."<Space>u" = { action = "<Cmd>UndotreeToggle<CR>"; silent = true; };
2023-10-29 12:15:56 +01:00
};
};
}