nixos-config/users/simon/modules/neovim.nix

297 lines
9.8 KiB
Nix

{ config, lib, nixosConfig, pkgs, ... }:
let
languageClientSettings = pkgs.writeText "LanguageClient.json" (lib.generators.toJSON { } {
rust.clippy_preference = "on";
});
rainbow_csv = pkgs.vimUtils.buildVimPluginFrom2Nix rec {
name = "rainbow_csv";
src = pkgs.fetchFromGitHub {
owner = "mechatroner";
repo = name;
rev = "df89266d6c03479def77793fd7a0a651986865a5";
sha256 = "0c9b1r49vw6r3yhm6g02janyxw6d9j6bkjmv8zpdav46avmk74fh";
};
meta.license = lib.licenses.mit;
};
vim-openscad = pkgs.vimUtils.buildVimPluginFrom2Nix rec {
name = "vim-openscad";
src = pkgs.fetchFromGitHub {
owner = "sirtaj";
repo = name;
rev = "81db508b1888fdbea994d43ccef1acd86c8af3f7";
sha256 = "1wcdfayjpb9h0lzwdi5nda4c0ch263fdr0379l9k1gf47bgq9cx2";
};
meta.license = lib.licenses.publicDomain;
};
Vim-Jinja2-Syntax = pkgs.vimUtils.buildVimPluginFrom2Nix rec {
name = "Vim-Jinja2-Syntax";
src = pkgs.fetchFromGitHub {
owner = "Glench";
repo = name;
rev = "5d2496eb5fd4415c7ce062ccbcd53a3f0de93aa3";
sha256 = "1ss065b2psalli46bs3v13fhaplqydh13bg3jg3zr98wbdn70cws";
};
meta.license = lib.licenses.bsd3;
};
nerdtree-git-plugin = pkgs.vimUtils.buildVimPluginFrom2Nix rec {
name = "nerdtree-git-plugin";
src = pkgs.fetchFromGitHub {
owner = "Xuyuanp";
repo = name;
rev = "5fa0e3e1487b17f8a23fc2674ebde5f55ce6a816";
sha256 = "0nwb3jla0rsg9vb52n24gjis9k4fwn38iqk13ixxd6w5pnn8ax9j";
};
meta.license = lib.licenses.wtfpl;
};
pyls-black = pkgs.python3Packages.buildPythonPackage rec {
pname = "pyls-black";
version = "0.4.6";
src = pkgs.python3Packages.fetchPypi {
inherit pname version;
sha256 = "0qsnjrpqhws7ajwg5y01fcpn1y6jc89ql61rpaknwqq5srg0ww1k";
};
propagatedBuildInputs = with pkgs.python3Packages; [
black
toml
];
# circular dependency
doCheck = false;
postPatch = ''
sed -i 's/python-language-server; //' setup.cfg
'';
meta.license = lib.licenses.mit;
};
pyls = (pkgs.python3Packages.python-language-server.override {
providers = [
# everything except autopep8 and yapf (conflicts with black)
"mccabe"
"pycodestyle"
"pydocstyle"
"pyflakes"
"pylint"
"rope"
];
}).overrideAttrs (oldAttrs: oldAttrs // {
propagatedBuildInputs = oldAttrs.propagatedBuildInputs ++ [
pyls-black
];
});
in
{
programs.neovim = {
enable = true;
vimAlias = true;
extraConfig = ''
" Basic display
set number
set colorcolumn=80
" Persistent undo
set undofile
set undolevels=4096
set undoreload=16384
" Search
set ignorecase
" Hide search when enter is pressed
nnoremap <silent> <CR> :nohlsearch<CR>
" Autoload settings from file
set modeline
" Use system clipboard
set clipboard=unnamedplus
" Support more file encodings
set fileencodings=ucs-bom,utf-8,default,sjis,latin1
" Scroll before reaching top/bottom
set scrolloff=5
" Conceal when line is not active
set conceallevel=1
" Just hide buffer instead of unloading
set hidden
" Remap leader key
let mapleader = ","
" Jump to the last position
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal! g`\"" | endif
set background=dark
silent! colorscheme solarized
" Set unknown filetypes
autocmd BufRead,BufNewFile *.vpy set filetype=python
" Filetype specific properties
autocmd Filetype arduino setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype c setlocal ts=4 sw=4 sts=4 expandtab
autocmd Filetype cpp setlocal ts=4 sw=4 sts=4 expandtab
autocmd Filetype css setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype dockerfile setlocal ts=4 sw=4 sts=4 expandtab
autocmd Filetype dot setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype gitcommit setlocal colorcolumn=72
autocmd Filetype go setlocal ts=4 sw=4 sts=4
autocmd Filetype haskell setlocal ts=4 sw=4 sts=4 expandtab
autocmd Filetype html setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype jinja.html setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype javascript setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype jinja setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype json setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype lua setlocal ts=4 sw=4 sts=4 expandtab
autocmd Filetype markdown setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype openscad setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype python setlocal ts=4 sw=4 sts=4 expandtab
autocmd Filetype sass setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype scss setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype sh setlocal ts=4 sw=4 sts=4
autocmd Filetype tex setlocal ts=1 sw=1 sts=1 expandtab
autocmd Filetype toml setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype vim setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype vue setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype xml setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype yaml setlocal ts=2 sw=2 sts=2 expandtab
autocmd Filetype zsh setlocal ts=4 sw=4 sts=4 expandtab
'';
plugins = (with pkgs.vimPlugins; [
{
plugin = deoplete-nvim;
config = ''
let g:deoplete#enable_at_startup = 1
'';
}
editorconfig-vim
fzf-vim
{
plugin = nerdtree;
config = ''
map <Leader>N :NERDTreeTabsToggle<CR>
map <Leader>n :NERDTreeFocusToggle<CR>
'';
}
{
plugin = rust-vim;
config = ''
let g:rustfmt_autosave_if_config_present = 1
let g:rust_fold = 1
map <Leader>rt :RustTest<CR>
'';
}
{
plugin = tagbar;
config = "nmap <F8> :TagbarToggle<CR>";
}
{
plugin = ultisnips;
config = ''
let g:UltiSnipsExpandTrigger = '<tab>'
let g:UltiSnipsJumpForwardTrigger = '<tab>'
let g:UltiSnipsJumpBackwardTrigger = '<s-tab>'
'';
}
{
plugin = vim-airline;
config = ''
let g:airline_powerline_fonts = 1
let g:airline_solarized_bg='dark'
let g:airline_theme='solarized'
'';
}
vim-airline-themes
vim-better-whitespace
vim-colors-solarized
vim-devicons
vim-fugitive
vim-nerdtree-tabs
vim-nix
vim-snippets
vim-toml
{
plugin = vimtex;
config = ''
let g:tex_flavor='latex'
let g:vimtex_view_method='zathura'
let g:tex_conceal='abdmg'
let g:vimtex_syntax_autoload_packages = [
\'amsmath',
\'luacode',
\]
" this disables some helful warnings that often have a reason why I ignore them
let g:vimtex_quickfix_ignore_filters = [
\'Underfull \\hbox (badness [0-9]*) in ',
\'Overfull \\hbox ([0-9]*.[0-9]*pt too wide) in ',
\'Overfull \\vbox ([0-9]*.[0-9]*pt too high) detected ',
\'Package hyperref Warning: Token not allowed in a PDF string',
\'Package typearea Warning: Bad type area settings!',
\]
" When using math environments vim does not know if if it currently is in one
" or outside of one unless it parses the file from the start. Parsing the
" file from the start each time fixes this but leads to a performance drop
" (depending on the number of lines).
" Also, somehow using FileType tex does not work, so this will enable slow
" syntax highlighting everywhere once a *.tex file is opened.
autocmd BufEnter *.tex syntax sync fromstart
'';
}
] ++ (lib.optionals nixosConfig.sbruder.full [
{
plugin = LanguageClient-neovim;
config = ''
let g:LanguageClient_serverCommands = {
\ 'rust': ['${pkgs.rls}/bin/rls'],
\ 'go': ['${pkgs.gopls}/bin/gopls'],
\ 'python': ['${pyls}/bin/pyls'],
\ 'typescript': ['${pkgs.nodePackages.javascript-typescript-langserver}/bin/javascript-typescript-stdio'],
\ 'javascript': ['${pkgs.nodePackages.javascript-typescript-langserver}/bin/javascript-typescript-stdio'],
\ 'haskell': ['${pkgs.haskellPackages.haskell-language-server}/bin/haskell-language-server', '--lsp'],
\ 'nix': ['${pkgs.rnix-lsp}/bin/rnix-lsp'],
\ }
let g:LanguageClient_loggingFile = '${config.xdg.dataHome}/nvim/LanguageClient.log'
let g:LanguageClient_settingsPath = '${languageClientSettings}'
let g:LanguageClient_selectionUI='fzf'
function LC_maps()
if has_key(g:LanguageClient_serverCommands, &filetype)
nnoremap <buffer> <silent> <F5> :call LanguageClient_contextMenu()<CR>
nnoremap <buffer> <silent> K :call LanguageClient#textDocument_hover()<CR>
nnoremap <buffer> <silent> gd :call LanguageClient#textDocument_definition()<CR>
nnoremap <buffer> <silent> <F2> :call LanguageClient#textDocument_rename()<CR>
nnoremap <buffer> <silent> <Leader>f :call LanguageClient#textDocument_formatting()<CR>
" disable since it breaks most code
"set formatexpr=LanguageClient#textDocument_rangeFormatting_sync()
endif
endfunction
autocmd FileType * call LC_maps()
'';
}
])) ++ [
Vim-Jinja2-Syntax
nerdtree-git-plugin
rainbow_csv
vim-openscad
];
};
xdg.configFile = {
"nvim/UltiSnips".source = ../files/nvim/UltiSnips;
};
home.sessionVariables.EDITOR = "nvim";
}