From aa53d0640845dfd4fb7e411f586a42e0cff02dfb Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 28 Apr 2023 22:50:37 +0200 Subject: [PATCH] home-manager,nvim: add init.vim --- .config/nvim/init.vim | 526 ++++++++++++++++++++++++++++++++++++++++++ home-leo.nix | 3 + 2 files changed, 529 insertions(+) create mode 100755 .config/nvim/init.vim diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim new file mode 100755 index 0000000..8aee305 --- /dev/null +++ b/.config/nvim/init.vim @@ -0,0 +1,526 @@ +" not necessary, as vim will turn this on by default, when .vimrc is found +" set nocompatible + +set encoding=utf-8 " important for powerline besides others +scriptencoding=utf8 + +filetype off "required + +augroup install_vim_plug + autocmd! + if empty(glob('~/.local/share/nvim/site/autoload/plug.vim')) + silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs + \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + autocmd VimEnter * PlugInstall --sync | source $MYVIMRC + endif +augroup END + +augroup plug_auto_install + autocmd! + " Run PlugInstall if there are missing plugins + autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) + \| PlugInstall --sync | source $MYVIMRC + \| endif +augroup END + + +call plug#begin() +Plug 'vim-airline/vim-airline' +Plug 'vim-airline/vim-airline-themes' +Plug 'ryanoasis/vim-devicons' + +Plug 'dracula/vim' +Plug 'axvr/photon.vim' + +Plug 'ncm2/ncm2' +Plug 'SirVer/ultisnips' +Plug 'honza/vim-snippets' + +Plug 'ctrlpvim/ctrlp.vim' +Plug 'mhinz/vim-startify' + +Plug 'preservim/nerdcommenter' +Plug 'airblade/vim-gitgutter' +Plug 'tpope/vim-fugitive' +Plug 'tpope/vim-surround' +Plug 'tpope/vim-repeat' + +" https://github.com/neovim/nvim-lspconfig +Plug 'neovim/nvim-lspconfig' +Plug 'kabouzeid/nvim-lspinstall' + +"Plug 'zchee/nvim-go', { 'do': 'make'} +Plug 'fatih/vim-go', { 'for': ['go', 'gomod', 'gohtmltmpl', 'gotexttmpl'], 'do': ':GoInstallBinaries' } +Plug 'themaxmarchuk/tailwindcss-colors.nvim' +Plug 'brenoprata10/nvim-highlight-colors' + +Plug 'majutsushi/tagbar' +Plug 'NoahTheDuke/vim-just', { 'for': ['just'] } +Plug 'fladson/vim-kitty', { 'for': ['kitty'] } +call plug#end() + + +" airline config +" turn on vimscript 9 support +let g:airline_experimental = 1 + +let g:airline_powerline_fonts = 1 +let g:airline_highlighting_cache = 1 +" violet, wombat, deus +let g:airline_theme = 'minimalist' +let g:airline#extensions#tabline#enabled = 1 +let g:airline#extensions#tabline#formatter = 'unique_tail_improved' +" show tab number instead of number of splits +let g:airline#extensions#tabline#tab_nr_type = 1 + +let g:airline_mode_map = { + \ '__' : '-', + \ 'c' : 'C', + \ 'i' : 'I', + \ 'ic' : 'I-C', + \ 'ix' : 'I-X', + \ 'n' : 'N', + \ 'multi' : 'M', + \ 'ni' : 'N', + \ 'no' : 'N', + \ 'R' : 'R', + \ 'Rv' : 'R', + \ 's' : 'S', + \ 'S' : 'S', + \ '' : 'S', + \ 't' : 'T', + \ 'v' : 'V', + \ 'V' : 'V-L', + \ '' : 'V-B', + \ } + +" skip displaying fileformat output if the output matches a configured string. +let g:airline#parts#ffenc#skip_expected_string='utf-8[unix]' + +" certain number of spaces are allowed after tabs, but not in between. +" this algorithm works well for /** */ style comments in a tab-indented file. +let g:airline#extensions#whitespace#mixed_indent_algo = 1 + +" turn off the warning section entirely. +let g:airline_section_warning = '' + +let g:airline_skip_empty_sections = 1 + +" separator symbols +let g:airline_left_sep = '' +let g:airline_right_sep = '' +let g:airline_left_alt_sep = '' +let g:airline_right_alt_sep = '' + +if !exists('g:airline_symbols') + let g:airline_symbols = {} +endif + +let g:airline_symbols.branch = '' +let g:airline_symbols.colnr = '℅:' +let g:airline_symbols.readonly = '' +let g:airline_symbols.nx='∄' + +" ale integration +let g:airline#extensions#ale#enabled = 1 +" nrrwrgn integration +let g:airline#extensions#nrrwrgn#enabled = 1 +" vcs integration +let g:airline#extensions#branch#enabled = 0 +" show summary of changed hunks (gitgutter and/or vim-signify) +let g:airline#extensions#hunks#enabled = 1 +" tabline integration +let g:airline#extensions#tabline#enabled = 1 +let g:airline#extensions#ctrlp#enabled = 1 +let g:airline#extensions#taboo#enabled = 0 +let g:airline#extensions#battery#enabled = 0 +let g:airline#extensions#bookmark#enabled = 0 +let g:airline#extensions#flog#enabled = 0 +let g:airline#extensions#bufferline#enabled = 0 +let g:airline#extensions#capslock#enabled = 0 +let g:airline#extensions#coc#enabled = 0 +" syntastic integration +let g:airline#extensions#syntastic#enabled = 0 +" vim-csv +let g:airline#extensions#csv#enabled = 0 +let g:airline#extensions#ctrlspace#enabled = 0 +" Built-in extension to displays cursor in different colors depending on the +" current mode (only works in terminals iTerm, AppleTerm and xterm) +" * this fixes the issue of airline changing terminal cursor colour in kitty+fedora35/fedora36 +let g:airline#extensions#cursormode#enabled = 0 + + +if has('patch-8.1.1880') + " set completeopt=longest,menuone,popuphidden + set completeopt=longest,menuone,popup + " Highlight the completion documentation popup background/foreground the same as + " the completion menu itself, for better readability with highlighted + " documentation. + set completepopup=highlight:Pmenu,border:off +else + set completeopt=longest,menuone,preview + " Set desired preview window height for viewing documentation. + set previewheight=5 +endif + + +" colo dracula +colo photon +set autochdir +set number relativenumber +set smartcase +set splitbelow splitright +set lazyredraw +set ttyfast +set listchars=trail:•,tab:>-,nbsp:☣,eol:¬,extends:❯,precedes:❮ +set nolist " show/hide tabs and EOL chars (hidden characters) +" don't indent wrapped lines +set nobreakindent + +set confirm " ask confirmation like save before quit. +set wildmenu " Tab completion menu when using command mode +" https://bitbucket.org/sjl/dotfiles/src/tip/vim/vimrc#cl-153 +set wildignore+=.hg,.git,.svn " Version control +set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files +set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images +set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files +set wildignore+=*.dwo " DWARF debug object files +set wildignore+=*.spl " compiled spelling word lists +set wildignore+=*.pyc " Python byte code +set wildignore+=node_modules/** +set wildmode=longest:longest,full + +set colorcolumn=80 +filetype plugin indent on +set hlsearch incsearch +augroup filetypes + autocmd! + au BufRead,BufNewFile *.tmpl setlocal filetype=gohtmltmpl + au FileType gohtmltmpl setlocal ff=unix ts=2 shiftwidth=2 sts=2 noexpandtab +augroup END + + +" -------- +" plugin configurations +" -------- + +let g:gitgutter_terminal_reports_focus=0 +let g:gitgutter_async = 1 +let g:gitgutter_sign_column_always = 1 +let g:gitgutter_sign_allow_clobber=0 +let g:gitgutter_set_sign_backgrounds = 0 +let g:gitgutter_preview_win_floating = 1 +set foldtext=gitgutter#fold#foldtext() +nmap ghs (GitGutterStageHunk) +nmap ghu (GitGutterUndoHunk) +nnoremap d :GitGutterLineHighlightsToggle + + + +" nerdcommenter +noremap :call nerdcommenter#Comment(0,"toggle") +" Add spaces after comment delimiters by default +let g:NERDSpaceDelims = 1 +" Allow commenting and inverting empty lines (useful when commenting a region) +let g:NERDCommentEmptyLines = 1 +" Enable trimming of trailing whitespace when uncommenting +let g:NERDTrimTrailingWhitespace = 1 +" Add your own custom formats or override the defaults +let g:NERDCustomDelimiters = { + \ 'vim': { 'left': '"','right': '' }, + \ 'c': {'left': '/**','right': '*/' }, + \ 'dhall': {'left': '-- | ', 'right': '' }, + \ 'zsh': { 'left': '#','right': ''}, + \ 'sysctl': {'left': '#', 'right': ''}, + \ 'systemd': {'left': ';', 'right': ''}, + \} +" let g:NERDTreeGitStatusWithFlags = 1 + + +" netrw +let g:netrw_banner = 0 +let g:netrw_keepdir = 0 +" prefer tree-style listing +let g:netrw_liststyle = 3 +" let g:netrw_liststyle = 1 +let g:netrw_sort_options = 'i' +" open files in a new horizontal split +let g:netrw_browse_split = 1 + + +" ctrlp +" Setup some default ignores +let g:ctrlp_custom_ignore = { + \ 'dir':'\v[\/](\.(git\/(branches|hooks|info|logs|modules|objects|rebase-merge|refs)|hg|svn)|\_site)$', + \ 'file':'\v\.(exe|so|dll|class|png|jpg|jpeg)|(\.(git\/(description|index|packed-refs|COMMIT_EDITMSG|HEAD|FETCH_HEAD|ORIG_HEAD|REBASE_HEAD)))$', + \} + +" Use the nearest .git directory as the cwd +" This makes a lot of sense if you are working on a project that is in version +" control. It also supports works with .svn, .hg, .bzr. +" let g:ctrlp_working_path_mode = 'r' +let g:ctrlp_working_path_mode = 'raw' +let g:ctrlp_cache_dir = $HOME . '/.cache/ctrlp' + +" The Silver Searcher +if executable('ag') + " use ag instead of grep. + set grepprg=ag\ --nogroup\ --nocolor + + " use ag in CtrlP + let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""' + " ag is fast enough that CtrlP doesn't need to cache + let g:ctrlp_use_caching = 0 +endif + +nnoremap :CtrlP +nnoremap s (ctrlp) + +let g:ctrlp_show_hidden = 1 +" Use a leader instead of the actual named binding +nmap p (ctrlp) + +" ctrlp buffers +" Easy bindings for its various modes +nmap bb :CtrlPBuffer +nmap bm :CtrlPMixed +nmap bs :CtrlPMRU + +" buffers +nmap T :enew +nmap bq :bp bd # +nmap gd :bd +map gn :bn +map gp :bp + +command! W execute 'w' | edit! +command! WW execute 'silent w !sudo tee % >/dev/null' | edit! + +" always show full path on +nnoremap 1 +" open a terminal in $PWD +nnoremap tt :terminal +" terminal normal mode +tnoremap N +" toggle showing whitespace +noremap :set list! +nnoremap :TagbarToggle +" [bro]wse [ol]d files +nnoremap r :bro ol + +" tab switching +nnoremap gT +nnoremap gt + +" resize windows +map - - +map + + + +" vmap to stay in Visual Mode after shifting > and < +vmap < >gv + + +"------------------------------------ +" vim-go.vim +"------------------------------------ +" use gopls +let g:go_def_mode='gopls' +let g:go_info_mode='gopls' +" Status line types/signatures. +let g:go_auto_type_info = 1 + +let g:go_highlight_types = 1 +let g:go_highlight_functions = 1 +let g:go_highlight_methods = 1 +let g:go_highlight_structs = 1 +let g:go_highlight_interfaces = 1 +let g:go_highlight_operators = 1 +let g:go_highlight_build_constraints = 1 +let g:go_highlight_extra_types = 1 +" if sluggish +" let g:go_highlight_structs = 0 +" let g:go_highlight_interfaces = 0 +" let g:go_highlight_operators = 0 +" let g:go_list_type = 'quickfix' +let g:go_list_type = '' +" let g:go_version_warning = 0 +let g:go_fmt_fail_silently = 0 +" auto formatting and importing +let g:go_fmt_command = 'gopls' +let g:go_fmt_autosave = 1 +" go install mvdan.cc/gofumpt@latest +let g:go_gopls_gofumpt = 1 +" let g:go_gopls_options = ['-remote=auto'] +let g:go_gopls_options = ['-remote=unix;/tmp/.gopls-daemon.sock'] +" let lsp handle connecting to gopls +let g:go_gopls_enabled = 1 +" let g:go_doc_popup_window = 0 +let g:go_doc_popup_window = 1 +let g:go_fillstruct_mode = 'gopls' +let g:go_term_reuse = 1 +let g:go_term_enabled = 1 +let g:go_doc_balloon = 1 + + +augroup vimgo + au! + au FileType go nmap gb (go-build) + au FileType go nmap b (go-build) + au FileType go nmap gr (go-run) + au FileType go nmap gt (go-test) + au FileType go nmap gs (go-implements) + au FileType go nmap gi (go-info) + au FileType go nmap ge (go-rename) + au FileType go nmap gd (go-doc) + " Navigation commands + au FileType go nmap ds (go-def-split) + au FileType go nmap dv (go-def-vertical) + " Alternate commands + au FileType go nmap hae (go-alternate-edit) + au FileType go nmap vae (go-alternate-vertical) + " Use new vim 8.2 popup windows for Go Doc +augroup END + +" go_tags +"------------------------------------ +exec 'source ' . escape(expand('~/.vim'),' ') . '/' . 'gotags.vimrc.vim' + + +" when quitting a file, save the cursor position +augroup save_cursor_position + if &filetype !~# 'commit\|rebase' + autocmd! + " also automatically open any folds the cursor might land on. + autocmd BufReadPost * silent! normal! g`" zv + endif +augroup END + + +set hidden +set conceallevel=0 +set mouse=a +set nogdefault + +let g:vim_json_conceal = 0 +let g:markdown_syntax_conceal = 0 + +set timeoutlen=200 +set notimeout ttimeout ttimeoutlen=10 +set undofile +set undodir=~/.vim/nvimundo// +set undolevels=2000 +set undoreload=10001 +if !isdirectory(expand(&undodir)) + call mkdir(expand(&undodir), 'p') +endif + +set nobackup +set nowritebackup +set directory=~/.vim/swp// +if !isdirectory(expand(&directory)) + call mkdir(expand(&directory), 'p') +endif + +set title +set showcmd +set showmatch +set updatetime=250 +set noscrollbind +set noerrorbells +set laststatus=2 " show status bar +set report=1 " Always report number of lines changed by ex commands +set termguicolors +set t_Co=256 +set guifont=Fira\ Code\ weight=450\ 12 + +let g:netrw_beval = 1 +set t_vb= + +" cursorline optimizations +set cursorlineopt=number +" 0 automatic selection +" 1 old engine +" 2 NFA engine +" set regexpengine=1 +set regexpengine=0 +" set redrawtime=500 +" set synmaxcol=128 +syntax sync minlines=256 + +" use +/clipboard as default register +set clipboard=unnamed,unnamedplus + +" but since it's needed for direnv, we have to enable it. +set exrc +set secure + +" https://sw.kovidgoyal.net/kitty/faq/#using-a-color-theme-with-a-background-color-does-not-work-well-in-vim +" work around vim's background colour erase: +" +" vim hardcodes background color erase even if the terminfo file does +" not contain bce (not to mention that libvte based terminals +" incorrectly contain bce in their terminfo files). This causes +" incorrect background rendering when using a color theme with a +" background color. +let &t_ut='' + +" compensate for lack of theme italics +for s in ['Comment', 'markdownItalic', 'Boolean'] + execute 'hi ' s ' cterm=italic' +endfor +hi CursorLineNR cterm=bold + +lua < + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set('n', 'D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set({ 'n', 'v' }, 'ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', 'f', function() + vim.lsp.buf.format { async = true } + end, opts) + end, +}) + + +-- https://dev.to/vonheikemen/neovim-using-vim-plug-in-lua-3oom + +EOF + + +" vim: ft=vim ff=unix expandtab ts=2 sw=2 diff --git a/home-leo.nix b/home-leo.nix index 2c63539..601c621 100644 --- a/home-leo.nix +++ b/home-leo.nix @@ -71,6 +71,9 @@ in { ".config/helix/config.toml" = { source = ./.config/helix/config.toml; }; + ".config/nvim/init.vim" = { + source = ./.config/nvim/init.vim; + }; ".config/sway/config" = { source = ./.config/sway/config;