overlays-personal/pkgs/vim/default.nix
2021-09-14 17:22:10 +03:00

336 lines
9.5 KiB
Nix
Executable file

{ pkgs
, extraPlugins ? []
, extraOptions ? ""
, ...
}:
# At first, largely adapted from:
# https://www.mpscholten.de/nixos/2016/04/11/setting-up-vim-on-nixos.html
# Changed quite a bit since
with pkgs;
let
plugins = let inherit (vimUtils) buildVimPluginFrom2Nix; in {
"vim-hcl" = buildVimPluginFrom2Nix { # created by nix#NixDerivation
pname = "vim-hcl";
version = "git";
src = fetchgit {
url = "git://github.com/jvirtanen/vim-hcl";
rev = "c64a006facad8c3cc0f16ba324e63524932a96e7";
sha256 = "0547xgbk725rnib8ka775a8r57dlywkyw1kjwma78n93h64dwnlr";
};
dependencies = [];
};
"systemd-syntax" = buildVimPluginFrom2Nix { # created by nix#NixDerivation
pname = "systemd-syntax";
version = "git";
src = fetchgit {
url = "git://github.com/Matt-Deacalion/vim-systemd-syntax";
rev = "394a516f524e74ac8808ede1496b25d8b9824827";
sha256 = "0fqk5fxrdf8nazic244ia4bi75midmpj896vdkdmxnv563lnhkcy";
};
dependencies = [];
};
"opencl-syntax" = buildVimPluginFrom2Nix { # created by nix#NixDerivation
pname = "opencl-syntax";
version = "git";
src = fetchgit {
url = "git://github.com/petRUShka/vim-opencl";
rev = "7668b018fe9461c6b51e0b736ed84aa84d6bafce";
sha256 = "0z8qasymkkaa272bjxmkp4sgd8qr4ypcqxlyzxgh5imp3gmrc6n1";
};
dependencies = [];
};
"vim-gnupg" = buildVimPluginFrom2Nix { # created by nix#NixDerivation
pname = "vim-gnupg";
version = "git";
src = fetchFromGitHub {
owner = "jamessan";
repo = "vim-gnupg";
rev = "f663d0e857bd88cb39c16ca45c37a27488648562";
sha256 = "0y0g3br54sj0h8s6ashny2km2260qw8psqxq00jn0l2chjwsi0d9";
};
dependencies = [];
};
vim-timedot = buildVimPluginFrom2Nix {
pname = "vim-timedot";
version = "git";
src = fetchFromGitHub {
owner = "jpotier";
repo = "vim-timedot";
rev = "ab48ee1002e25ae705dd84bb3db8b88bb0c2dc93";
sha256 = "0vgga3fmppb71apd31bwji98d62vs1p77c1hssshmh2fc7yck6s8";
};
};
vim-selinux = buildVimPluginFrom2Nix {
pname = "vim-selinux";
version = "git";
src = fetchFromGitHub {
owner = "lzap";
repo = "vim-selinux";
rev = "735743a3539431c33824cb432b92267a0fc82251";
sha256 = "16pk2zscyiayfccn760p2zki4cjfhp26bikisgswjg900zwr5yns";
};
};
vim-lilypond = buildVimPluginFrom2Nix { # created by nix#NixDerivation
pname = "vim-lilypond";
version = "git";
src = "${pkgs.lilypond.outPath}/share/lilypond/${pkgs.lilypond.version}/vim";
dependencies = [];
};
vim-css-color = buildVimPluginFrom2Nix {
pname = "vim-css-color";
version = "git";
src = fetchFromGitHub {
owner = "jpotier";
repo = "vim-css-color";
rev = "bd7cac457b4459e3e60fec39c094832d233c6a7f";
sha256 = "08k1jh9n0kz9xwmy0ig03w9lx0r2m2rhmfwb0idy81madllcidjc";
};
};
}; in vim_configurable.customize {
name = "vim";
vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; with plugins; {
# loaded on launch
start = [
calendar-vim
dhall-vim
editorconfig-vim
fzf-vim
fzfWrapper
goyo-vim
gundo-vim
nerdtree
opencl-syntax
systemd-syntax
vim-abolish
vim-airline
vim-airline-themes
vim-better-whitespace
vim-gnupg
vim-hcl
vim-ledger
vim-lilypond
vim-lsp
vim-nix
vim-orgmode
vim-repeat
vim-selinux
vim-speeddating
vim-surround
vim-terraform
vim-timedot
vimtex
] ++ extraPlugins;
# manually loadable by calling `:packadd $plugin-name`
opt = [
vim-css-color
];
# To automatically load a plugin when opening a filetype, add vimrc lines like:
# autocmd FileType php :packadd phpCompletion
};
vimrcConfig.customRC = ''
" Must have for vim
set nocompatible
" Display nbsp
set listchars=tab:\|\ ,nbsp:·
set list
" Remap ESC on ,,
map ,, <ESC>
imap ,, <ESC>
scriptencoding utf-8
" Must be *after* pathogen (not using pathogen anymore)
filetype plugin indent on
" Leader
let mapleader=","
nnoremap <leader>a :echo("\<leader\> works! It is set to <leader>")<CR>
" let maplocalleader = "-"
" Highlighting
syntax enable
if has('gui_running')
" When gui is running, it pretty much sets its own colors
set guifont=Victor\ Mono\ 14
set notitle
set guioptions=a
else
" If we're in a terminal, then we stay default, terminal will choose
" which colors it likes.
endif
" Set line numbering
set number
" Don't wrap lines, it's ugly
set nowrap
" Deal with tabs
set softtabstop=2
set tabstop=2 " 1 tab = 2 spaces
set shiftwidth=2 " Indent with 2 spaces
set expandtab " Insert spaces instead of tabs
" Set par as default wrapper
set formatprg=${par.outPath}/bin/par\ -w80
" Set mouse on
set mouse=a
" Don't set timeout - this breaks the leader use
set notimeout
set ttimeout
" Color lines in a different shade up to 80 columns
let &colorcolumn=join(range(81,999),",")
" automatically jump to the end of the text you just copied/pasted:
xnoremap <silent> y y`]
nnoremap <silent> yy yy`]
xnoremap <silent> p p`]
xnoremap <silent> P P`]
nnoremap <silent> p p`]
nnoremap <silent> P P`]
" vimtex options
let g:vimtex_fold_enabled=1
let g:vimtex_fold_manual=1
let g:vimtex_compiler_enabled=0
let g:tex_flavor = 'latex'
" conceal to unicode symbols
nnoremap <leader>l :silent let &conceallevel = (&conceallevel+1)%4<CR>
set conceallevel=0
set concealcursor=nvc
let g:tex_conceal="abdmgs"
" nice pluginless stuff
set path+=**
set wildmenu
" Tag generation
command! MakeTags !${universal-ctags}/bin/ctags -R .
" Less noise in netrw
let g:netrw_altv=1
let g:netrw_banner=0
let g:netrw_browse_split=4
let g:netrw_list_hide=netrw_gitignore#Hide()
let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
let g:netrw_liststyle=3
let g:netrw_winsize=25
" Normal backspace
set backspace=indent,eol,start
" Set filetype tex for tikz files
au BufNewFile,BufRead *.tikz set filetype=tex
" Thx Mats for the following
:cnoremap <C-A> <Home>
:cnoremap <C-B> <Left>
:cnoremap <C-F> <Right>
:cnoremap <C-E> <End>
" NERDTree when starting
"autocmd vimenter * NERDTree
let g:NERDTreeDirArrowExpandable = '+'
let g:NERDTreeDirArrowCollapsible = '-'
" SmartCase (only search by case if capital letter is used)
set ignorecase
set smartcase
" Allow for more than 10 tabs to be opened at once
set tabpagemax=40
" Help ledger
let g:ledger_bin = '${hledger}/bin/hledger'
let g:ledger_extra_options = '--pedantic --explicit --check-payees'
" Virtual Edit maaan
set ve=block
" Read Vagrantfile as ruby source
augroup vagrant
au!
au BufRead,BufNewFile Vagrantfile set filetype=ruby
augroup END
" Haskell Language Server
if executable('dhall-lsp-server')
au User lsp_setup call lsp#register_server({
\ 'name': 'dhall-lsp',
\ 'cmd': {server_info->['dhall-lsp-server']},
\ 'allowlist': ['dhall'],
\ })
endif
if executable('haskell-language-server-wrapper')
au User lsp_setup call lsp#register_server({
\ 'name': 'haskell-lsp',
\ 'cmd': {server_info->['haskell-language-server-wrapper', '--lsp']},
\ 'allowlist': ['haskell'],
\ })
endif
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> gt <plug>(lsp-type-definition)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <Plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <Plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
nmap <buffer> <leader>a <plug>(lsp-code-action)
nmap <buffer> <leader>dd <plug>(lsp-document-diagnostics)
" refer to doc to add more commands
endfunction
augroup lsp_install
au!
" call s:on_lsp_buffer_enabled only for languages that has the server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
" Extra options
${extraOptions}
'';
}
# " vimwiki stuff
# " let g:vimwiki_global_ext = 0
# " let g:vimwiki_conceallevel = 0
# " let g:vimwiki_auto_chdir = 1
# " let g:vimwiki_list = [
# " \{'path': '~/zk/'},
# " \{'path': '~/vimwiki/personal.wiki'}
# " \]
# " :autocmd FileType vimwiki map <leader>d :VimwikiMakeDiaryNote
# " :autocmd FileType vimwiki Goyo 80x20
# "
# " function! ToggleCalendar()
# " execute ":Calendar"
# " if exists("g:calendar_open")
# " if g:calendar_open == 1
# " execute "q"
# " unlet g:calendar_open
# " else
# " g:calendar_open = 1
# " end
# " else
# " let g:calendar_open = 1
# " end
# " endfunction
# " :autocmd FileType vimwiki map <leader>c :call ToggleCalendar()