" try not to put any lines in your vimrc that you don't understand :) set nocompatible filetype off "required if empty(glob('~/.vim/autoload/plug.vim')) silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim autocmd VimEnter * PlugInstall --sync | source $MYVIMRC endif 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 " both "filetype indent on" and "syntax on" are called by Plug, keeping DRY call plug#begin() " colourschemes Plug 'liuchengxu/space-vim-theme' Plug 'nikolasvargas/spacemacs-theme' Plug 'cocopon/iceberg.vim' Plug 'sainnhe/edge' Plug 'chriskempson/base16-vim' Plug 'axvr/photon.vim' Plug 'Lokaltog/vim-monotone' Plug 'https://git.sr.ht/~romainl/vim-bruin' Plug 'fxn/vim-monochrome' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' Plug 'ctrlpvim/ctrlp.vim' Plug 'mhinz/vim-startify' " 🌷 Distraction-free writing in Vim Plug 'junegunn/goyo.vim', { 'for': 'markdown' } Plug 'preservim/nerdcommenter' Plug 'airblade/vim-gitgutter' Plug 'tpope/vim-surround' " fugitive.vim: A Git wrapper so awesome, it should be illegal Plug 'tpope/vim-fugitive' Plug 'tpope/vim-repeat' Plug 'tpope/vim-speeddating', { 'on': [] }| " quick date incrementing " plugin fails to work if it's only loaded on a predefined list of " formats, commented for now " Plug 'tpope/vim-afterimage', { 'for': ['xpm', 'png', 'ico', 'gif'] } Plug 'tpope/vim-jdaddy', { 'for': 'json' } Plug 'tpope/vim-ragtag', { 'for': ['html', 'xhtml', 'wml', 'xml', 'xslt', 'xsd', 'jsp', 'php', 'aspperl', 'aspvbs', 'cf', 'mason', 'htmldjango', 'eruby'] } Plug 'bazelbuild/vim-ft-bzl', { 'for': ['starlark', 'bzl'] } Plug 'z0mbix/vim-shfmt', { 'for': ['sh', 'bash'] } " Plug 'gorodinskiy/vim-coloresque'| " coloured background for colour names/codes " Plug 'lpinilla/vim-codepainter'| " text highlighting Plug 'rhysd/git-messenger.vim' " Plug 'Yggdroot/indentLine' " here Plug 'adamheins/vim-highlight-match-under-cursor' Plug 'roxma/nvim-yarp' Plug 'roxma/vim-hug-neovim-rpc' Plug 'Shougo/deoplete.nvim' Plug 'prabirshrestha/async.vim' Plug 'prabirshrestha/vim-lsp' Plug 'rhysd/vim-lsp-ale' Plug 'dense-analysis/ale' Plug 'OmniSharp/omnisharp-vim', { 'for': ['cs', 'csh'] } Plug 'justmao945/vim-clang', { 'on': [] } Plug 'cdelledonne/vim-cmake' Plug 'majutsushi/tagbar' Plug 'lvht/tagbar-markdown', { 'for': 'markdown' } Plug 'lervag/vimtex', { 'for': 'tex' } Plug 'xuhdev/vim-latex-live-preview', { 'for': 'tex' } Plug 'cespare/vim-toml', { 'for': 'toml' } Plug 'Glench/Vim-Jinja2-Syntax', { 'for': ['ansible', 'jinja2'] } Plug 'pearofducks/ansible-vim', { 'for': ['ansible', 'jinja2'] } Plug 'hashivim/vim-terraform', { 'for': 'terraform' } Plug 'aouelete/sway-vim-syntax', { 'for': 'sway' } Plug 'rust-lang/rust.vim', { 'for': 'rust' } Plug 'fatih/vim-go', { 'for': ['go', 'gomod', 'gohtmltmpl', 'gotexttmpl'], 'do': ':GoInstallBinaries' } Plug 'chikamichi/mediawiki.vim', { 'for': 'wiki' } Plug 's3rvac/vim-syntax-redminewiki', { 'for': 'redminewiki' } Plug 'mfukar/robotframework-vim', { 'for': 'robotframework' } call plug#end() " 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 = '' " 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 = 1 " 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 " lsp " disable diagnostics support - leave that to ALE let g:lsp_diagnostics_enabled = 0 let g:lsp_diagnostics_virtual_text_enabled = 0 " ref: " https://github.com/rhysd/vim-lsp-ale/blob/master/doc/vim-lsp-ale.txt#L98 " let g:lsp_ale_auto_config_vim_lsp = 0 " let g:lsp_ale_auto_config_ale = 0 let g:ale_close_preview_on_insert = 1 let g:ale_detail_to_floating_preview = 1 let g:ale_virtualtext_cursor = 1 let g:ale_hover_to_floating_preview = 1 let g:ale_completion_enabled = 1 let g:ale_hover_to_preview = 1 let g:ale_lsp_suggestions = 1 let g:ale_open_list = 0 let g:ale_keep_list_window_open = 0 let g:ale_list_window_size = 5 let g:ale_lint_on_text_changed = 'normal' let g:ale_lint_on_insert_leave = 1 let g:ale_lint_delay = 1000| " the default being 200 let g:ale_completion_autoimport = 1 let g:ale_linters = { 'go': ['gopls', 'govet', 'golint'], \ 'dockerfile': ['hadolint'], \ 'cs': ['OmniSharp'], \ 'c': ['clang-format', 'ccls', 'clangd', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder'], \ 'cpp': ['clang-format','ccls', 'clangd', 'clangtidy', 'cppcheck', 'flawfinder'], \ 'tf': ['tflint', 'terraform', 'tfsec', 'checkov'] } let g:ale_fixers = { 'c': ['ccls', 'clang-format', 'clangtidy', 'cppcheck', 'cquery', 'flawfinder'], \ 'cpp': ['clang-format', 'clangtidy', 'cppcheck', 'flawfinder'], \ 'go': ['gopls'] } 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 let g:gitgutter_terminal_reports_focus=0 let g:gitgutter_async = 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() " let g:gitgutter_map_keys = 0 nmap ghs (GitGutterStageHunk) nmap ghu (GitGutterUndoHunk) nnoremap d :GitGutterLineHighlightsToggle let g:deoplete#enable_at_startup = 1 let g:deoplete#enable_ignore_case = 1 let g:livepreview_cursorhold_recompile = 0 let g:livepreview_previewer = 'evince' let g:livepreview_engine = 'pdflatex -shell-escape -interaction=nonstopmode' let g:vimtex_compiler_progname = 'pdflatex -shell-escape --interaction=nonstopmode' let g:tex_flavor = 'latex' " nerdcommenter " _ stands for forward slash (/) 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 """" Enable NERDCommenterToggle to check all selected lines is commented or not """let g:NERDToggleCheckAllLines = 1 " Add your own custom formats or override the defaults let g:NERDCustomDelimiters = { \ 'vim': { 'left': '"','right': '' }, \ 'c': {'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 " indentline " let g:indentLine_setColors = 1 " let g:indentLine_char_list = ['|', '¦', '┆', '┊', ':'] " let g:indentLine_concealcursor = 'inc' " let g:indentLine_conceallevel = 0 " let g:indentLine_conceallevel = 2 " set conceallevel for json and markdown let g:vim_json_conceal = 0 let g:markdown_syntax_conceal = 0 let g:git_messenger_close_on_cursor_moved = v:false let g:git_messenger_always_into_popup = v:true hi gitmessengerHash term=None guifg=#f0eaaa ctermfg=111 " OmniSharp " IDE0010: Populate switch - display in ALE as `Info` " IDE0055: Fix formatting - display in ALE as `Warning` style error " CS8019: Duplicate of IDE0005 let g:OmniSharp_diagnostic_overrides = { \ 'IDE0010': {'type': 'I'}, \ 'IDE0055': {'type': 'W', 'subtype': 'Style'}, \ 'CS8019': {'type': 'None'}, \} " -------------------------- " syntastic """let g:syntastic_always_populate_loc_list = 1 """let g:syntastic_auto_loc_list = 2 """let g:syntastic_loc_list_height = 8 """let g:syntastic_check_on_open = 1 """let g:syntastic_check_on_wq = 0 """let g:syntastic_aggregate_errors = 1 """let g:syntastic_quiet_messages = { "type": "style" } """let g:syntastic_enable_highlighting=1 """let g:syntastic_echo_current_error=1 """" let g:syntastic_auto_jump=1 """let g:syntastic_auto_jump = 0 """let g:syntastic_id_checkers = 1 """let g:syntastic_error_symbol = "✗" """let g:syntastic_warning_symbol = "⚠" """function! SyntasticCheckHook(errors) """ if !empty(a:errors) """ let g:syntastic_loc_list_height = min([len(a:errors), 10]) """ endif """endfunction """ """set statusline+=%#warningmsg# """set statusline+=%{exists('g:loaded_syntastic_plugin')?SyntasticStatuslineFlag():''} """set statusline+=%* """ """let g:syntastic_javascript_checkers = ['jsl'] """let g:syntastic_python_checkers = ['flake8', 'pylint-3'] """let g:syntastic_c_compiler = 'clang' """let g:syntastic_c_check_header = 1 """let g:syntastic_c_auto_refresh_includes = 1 """let g:syntastic_cpp_checkers = ['cppcheck', 'g++'] """let g:syntastic_cpp_cppcheck_args = "--language=c++ --std=c++20 --enable=all --verbose --suppress=unmatchedSuppression --suppress=missingIncludeSystem ./*.{cpp,h}" """let g:syntastic_cpp_compiler = 'g++' """let g:syntastic_cpp_compiler_options = ' -std=c++20 -Wall -Wextra' """let g:syntastic_cpp_check_header = 1 """let g:syntastic_cpp_no_include_search = 0 """let g:syntastic_cpp_remove_include_errors = 1 """let g:syntastic_cpp_auto_refresh_includes = 1 """let g:syntastic_c_cpplint_exec = ['cppcheck', 'clang-check', 'clang-tidy'] """let g:syntastic_go_checkers = ['go', 'gopls', 'golint', 'govet'] """" let g:syntastic_tex_checkers = ['lacheck', 'text/language_check'] """let g:syntastic_tex_checkers = ['text/language_check', 'lacheck'] """let g:syntastic_gitcommit_checkers = ['language_check'] """let g:syntastic_yaml_checkers = ['yamllint'] """let g:syntastic_make_checkers = ['gnumake'] """let g:syntastic_aggregate_errors = 1 " ansible-vim settings let g:ansible_unindent_after_newline=1 let g:ansible_attribute_highlight='ob' let g:terraform_align=1 let g:terraform_fold_sections=1 let g:terraform_fmt_on_save=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' nnoremap '' : let g:ctrlp_map = '' 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 " change cursor shape for different editing modes, neovim does this by default if !has('nvim') if exists('$TMUX') let &t_SI = "\Ptmux;\\e[12 q\\\" let &t_SI = "\Ptmux;\\e[4 q\\\" let &t_SI = "\Ptmux;\\e[2 q\\\" else let &t_SI = "\]12;purple\x7" let &t_SR = "\e[4 q" let &t_EI = "\e[2 q" endif endif " reset cursor when vim exits autocmd VimLeave * silent !echo -ne "\033]112\007" command! W execute 'silent w !sudo tee % >/dev/null' | edit! command! -nargs=* Make write | make! | cwindow command Note execute 'e ~/Sync/notes/' . strftime('%y-%m-%d-%H:%M:%S') . '.md' command LocalNote execute 'e ./' . strftime('%y-%m-%d-%H:%M:%S') . '.md' " 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! " make shortcut nnoremap :term ++hidden ++open make nnoremap :term ++open make nnoremap :TagbarToggle vmap gb :!git blame % -L=line("'<") ,=line("'>") nnoremap gb :!git blame % " ll provided by vimtex nnoremap kk :w! !pdflatex -shell-escape -interaction=nonstopmode $PWD/*.tex :function Pdfpls() :echom "compiling ur tex goodness!" :w! :!pdflatex -shell-escape -interaction=nonstopmode $PWD/*.tex :!bibtex $PWD/*.aux :!pdflatex -shell-escape -interaction=nonstopmode $PWD/*.tex :endfunction nnoremap lb :call Pdfpls() nnoremap l :exec &conceallevel ? "set conceallevel=0" : "set conceallevel=1" " toggle GitGutterLineHighlights nnoremap d :GitGutterLineHighlightsToggle " ALE bindings nmap :ALEPreviousWrap nmap :ALENextWrap nnoremap a :ALEDetail nnoremap :ALEGoToDefinition " [bro]wse [ol]d files nnoremap r :bro ol " easy-way ifndef tmpl nnoremap "%phr_I#ifndef __gUwyypldwidefine yypldwiendif //O " tab switching nnoremap gT nnoremap gt " resize windows map - - map + + "------------------------------------ " 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_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_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 lsp handle connecting to gopls let g:go_gopls_enabled = 0 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) augroup END " go_tags "------------------------------------ exec 'source ' . escape(expand('~/.vim'),' ') . '/' . 'gotags.vimrc.vim' " ------ wayland copy and pasting let s:env = toupper(substitute(system('uname'), '\n', '', '')) if s:env =~# 'LINUX' && executable('wl-copy') xnoremap "+y y:call system("wl-copy", @") xnoremap "*y y:call system("wl-copy", @") endif if s:env =~# 'LINUX' && executable('wl-paste') nnoremap "+p :let @"=substitute(system("wl-paste --no-newline"), '', '', 'g')p nnoremap "*p :let @"=substitute(system("wl-paste --no-newline --primary"), '', '', 'g')p endif inoremap pumvisible() ? "\" : "\" inoremap pumvisible() ? "\" : "\" " ------ autocmd ------ " Enable omni completion. " autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS " autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags " autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS " autocmd FileType python setlocal omnifunc=pythoncomplete#Complete " autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags " Reload changes if file changed outside of vim requires autoread augroup load_changed_file autocmd! autocmd FocusGained,BufEnter * if mode() !=? 'c' | checktime | endif autocmd FileChangedShellPost * echo "Changes loaded from source file" augroup END " when quitting a file, save the cursor position augroup save_cursor_position autocmd! autocmd BufReadPost * call setpos(".", getpos("'\"")) augroup END " when not running in a console or a terminal that doesn't support 256 colors " enable cursorline in the currently active window and disable it in inactive ones if $DISPLAY !=? '' && &t_Co == 256 augroup cursorline autocmd! autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline autocmd WinLeave * setlocal nocursorline augroup END endif " when entering insert mode, relative line " numbers are turned off, leaving absolute line numbers turned on augroup numbertoggle autocmd! autocmd BufEnter,FocusGained,InsertLeave * set number relativenumber autocmd BufLeave,FocusLost,InsertEnter * set number norelativenumber augroup END hi clear CursorLine augroup CLClear autocmd! ColorScheme * hi clear CursorLine augroup END hi CursorLineNR cterm=bold augroup CLNRSet set cursorline autocmd! ColorScheme * hi CursorLineNR cterm=bold augroup END " define indent-based folding, after loading a file switch to manual folding augroup vimrc autocmd! au BufReadPre * setlocal foldmethod=indent au BufWinEnter * if &fdm == 'indent' | setlocal foldmethod=manual | endif augroup END """ autosave and load views au BufWinLeave ?* mkview au BufWinEnter ?* silent loadview au FileType xml setlocal shiftwidth=4 tabstop=4 au FileType html setlocal shiftwidth=4 tabstop=4 au BufNewFile,BufRead *.js \ setlocal shiftwidth=4 tabstop=4 softtabstop=4 expandtab autoindent \ fileformat=unix filetype=js au FileType sway setl textwidth=99 \ tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab autoindent au FileType rust setl \ tabstop=8 shiftwidth=8 softtabstop=8 noexpandtab autoindent ff=unix au BufNewFile,BufRead *.py,*.pyw,*.pyx,?akefil* \ setlocal tabstop=4 shiftwidth=4 noexpandtab autoindent \ fileformat=unix " Linux kernel style tabs - not for cpp " au BufNewFile,BufRead,BufEnter *.c,*.h,*.cpp au BufNewFile,BufRead,BufEnter *.c,*.h \ set tabstop=8 shiftwidth=8 softtabstop=8 noexpandtab autoindent \ textwidth=79 fileformat=unix omnifunc=lsp#complete au BufNewFile,BufRead,BufEnter *.cpp,*.h,*.hpp \ set tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab autoindent \ textwidth=79 fileformat=unix omnifunc=lsp#complete ft=cpp " \ textwidth=79 fileformat=unix au FileType cpp \ set tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab autoindent \ textwidth=79 fileformat=unix omnifunc=lsp#complete " \ textwidth=79 fileformat=unix au FileType tex setlocal tabstop=2 au BufNewFile,BufRead,BufEnter *.tex \ setlocal tabstop=2 shiftwidth=2 softtabstop=2 expandtab autoindent \ textwidth=79 fileformat=unix conceallevel=0 au BufNewFile,BufRead,BufEnter *.bib \ setlocal ft=bib tabstop=2 shiftwidth=2 softtabstop=2 noexpandtab autoindent \ fileformat=unix conceallevel=0 autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab indentkeys-=0# \ indentkeys-=<:> foldmethod=indent nofoldenable au BufNewFile,BufRead,BufEnter *.cs \ setlocal ft=cs tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab autoindent \ textwidth=79 fileformat=unix conceallevel=0 au BufNewFile,BufRead *.cshtml \ setlocal ft=csh tabstop=4 shiftwidth=4 softtabstop=4 noexpandtab autoindent \ textwidth=79 fileformat=unix conceallevel=0 " no autocomments, for example when entering insert mode above or below a " commented line autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o augroup line_too_long autocmd! autocmd winEnter,BufEnter * call clearmatches() | call matchadd('ColorColumn', '\%>80v', 100) augroup END augroup async_plug_load autocmd! " these plugins take the longest to load, let's do it in a semi-non-blocking " fashion autocmd CursorHold,CursorHoldI * call plug#load('vim-clang', 'vim-speeddating') \| autocmd! async_plug_load augroup END if executable('clangd') augroup lsp_clangd autocmd! autocmd User lsp_setup call lsp#register_server({ \ 'name': 'clangd', \ 'cmd': {server_info->['clangd']}, \ 'allowlist': ['c', 'cpp'], \ }) augroup END endif if executable('gopls') augroup lsp_go autocmd! autocmd User lsp_setup call lsp#register_server({ \ 'name': 'gopls', \ 'cmd': ['gopls', '-remote=unix;/tmp/.gopls-daemon.sock'], \ 'allowlist': ['go', 'gomod', 'gosum','gotexttmpl','gohtmltmpl'], \ 'gofumpt': 'true', \ }) augroup END endif if executable('rnix-lsp') augroup lsp_nix autocmd! au User lsp_setup call lsp#register_server({ \ 'name': 'rnix-lsp', \ 'cmd': {server_info->[&shell, &shellcmdflag, 'rnix-lsp']}, \ 'allowlist': ['nix'], \ }) augroup END endif " zig language server if executable('zls') augroup lsp_zig autocmd! au User lsp_setup call lsp#register_server({ \ 'name': 'zls', \ 'cmd': {server_info->[&shell, &shellcmdflag, 'zls']}, \ 'allowlist': ['zig'], \ }) augroup END endif if executable('pyls') " pip install python-language-server au User lsp_setup call lsp#register_server({ \ 'name': 'pyls', \ 'cmd': {server_info->['pyls']}, \ 'allowlist': ['python'], \ }) endif if executable('omnisharp') " https://www.rockyourcode.com/use-vim-for-c-sharp-development-on-linux/ augroup lsp_omnisharp autocmd! autocmd User lsp_setup call lsp#register_server({ \ 'name': 'omnisharp-roslyn', \ 'cmd': {_->[&shell, &shellcmdflag, 'mono $HOME/.bin/omnisharp/omnisharp --languageserver']}, \ 'whitelist': ['cs'] \}) autocmd User lsp_server_init call setup_ls() autocmd BufEnter * call setup_ls() augroup END endif function! s:on_lsp_buffer_enabled() abort setlocal omnifunc=lsp#complete setlocal signcolumn=yes if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif nmap gd (lsp-definition) nmap gs (lsp-document-symbol-search) nmap gS (lsp-workspace-symbol-search) nmap gr (lsp-references) nmap gi (lsp-implementation) " nmap gt (lsp-type-definition) nmap rn (lsp-rename) nmap [g (lsp-previous-diagnostic) nmap ]g (lsp-next-diagnostic) nmap K (lsp-hover) inoremap lsp#scroll(+4) inoremap lsp#scroll(-4) " let g:lsp_format_sync_timeout = 1000 let g:lsp_format_sync_timeout = 700 autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync') " refer to doc to add more commands endfunction augroup lsp_install au! " call s:on_lsp_buffer_enabled only for languages that have the server " registered. autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled() augroup END augroup omnisharp_commands autocmd! " Show type information automatically when the cursor stops moving. " Note that the type is echoed to the Vim command line, and will overwrite " any other messages in this space including e.g. ALE linting messages. autocmd CursorHold *.cs OmniSharpTypeLookup " The following commands are contextual, based on the cursor position. autocmd FileType cs nmap gd (omnisharp_go_to_definition) autocmd FileType cs nmap osfu (omnisharp_find_usages) autocmd FileType cs nmap osfi (omnisharp_find_implementations) autocmd FileType cs nmap ospd (omnisharp_preview_definition) autocmd FileType cs nmap ospi (omnisharp_preview_implementations) autocmd FileType cs nmap ost (omnisharp_type_lookup) autocmd FileType cs nmap osd (omnisharp_documentation) autocmd FileType cs nmap osfs (omnisharp_find_symbol) autocmd FileType cs nmap osfx (omnisharp_fix_usings) autocmd FileType cs nmap (omnisharp_signature_help) autocmd FileType cs imap (omnisharp_signature_help) " Navigate up and down by method/property/field autocmd FileType cs nmap [[ (omnisharp_navigate_up) autocmd FileType cs nmap ]] (omnisharp_navigate_down) " Find all code errors/warnings for the current solution and populate the quickfix window autocmd FileType cs nmap osgcc (omnisharp_global_code_check) " Contextual code actions (uses fzf, vim-clap, CtrlP or unite.vim selector when available) autocmd FileType cs nmap osca (omnisharp_code_actions) autocmd FileType cs xmap osca (omnisharp_code_actions) " Repeat the last code action performed (does not use a selector) autocmd FileType cs nmap os. (omnisharp_code_action_repeat) autocmd FileType cs xmap os. (omnisharp_code_action_repeat) autocmd FileType cs nmap os= (omnisharp_code_format) autocmd FileType cs nmap osnm (omnisharp_rename) autocmd FileType cs nmap osre (omnisharp_restart_server) autocmd FileType cs nmap osst (omnisharp_start_server) autocmd FileType cs nmap ossp (omnisharp_stop_server) augroup END " ------ adv maps ------ " strip trailing whitespace, ss (strip space) nnoremap ss \ :let b:_p = getpos(".") \ let b:_s = (@/ != '') ? @/ : '' \ %s/\s\+$//e \ let @/ = b:_s \ nohlsearch \ unlet b:_s \ call setpos('.', b:_p) \ unlet b:_p match Todo /\s\+$/ set softtabstop=4 set tabstop=4 set shiftwidth=4 set expandtab set smarttab set errorformat+=%.%#PHP:\ %m\ \(in\ %f\ on\ line\ %l\)%.%#, \%E%[0-9]%#.%m:%f?rev=%.%##L%l\ %.%#,%C%.%# set tags=.tags; set incsearch " incrimental search set hlsearch " highlighting when searching set wrapscan " go back to beginning of a buffer once we reach end set ignorecase " searches are case insensitive... set smartcase " ... unless they contain at least one capital letter set autoindent set backspace=2 set splitbelow splitright " splits open at bottom and right set lazyredraw " don't redraw while executing macros (good performance config) 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 " filler lines to keep text position; start diff with vertical splits; don't " ignore case and whitespace changes set diffopt=filler,vertical set scrolloff=5 " scroll offset, min lines above/below cursor "set scrolljump=5 " jump 5 lines when running out of the screen - NO set sidescroll=10 " minimum columns to scroll horizontally set showcmd " show command status set showmatch " flashes matching parenthese when cursor over the other one " Make <,> match pairs, too. " https://github.com/EHartC/dot-vimrc/blob/master/vim%20config/styling.vim set matchpairs+=<:> set matchtime=2 " how many tenths of a second to blink when matching brackets set noshowmode " show editing mode in status (-- INSERT --) set ruler " show cursor position set colorcolumn=80 " Highlight column 80 to get coding horizontal bound. set noerrorbells " bells in vim set viminfo='50,"50 " '=marks for x files, "=registers for x files set foldmethod=manual " manual folding set encoding=utf-8 " important for powerline besides others set fileencoding=utf-8 " set encoding for newly saved files set noscrollbind set cmdheight=2 " lines under {status,air}line set updatetime=250 set termguicolors colo space_vim_theme " new fav highlighting " compensate for lack of theme italics for s in ["Comment", "Constant", "Include", "Define", "Macro", "Delimiter", "Debug", "Identifier", "Boolean", "markdownItalic"] execute "hi " s " cterm=italic" endfor " vimtex highlight groups hi! link texMathEnvArgName texEnvArgName hi! link texMathZone LocalIdent hi! link texMathZoneEnv texMathZone hi! link texMathZoneEnvStarred texMathZone hi! link texMathZoneX texMathZone hi! link texMathZoneXX texMathZone hi! link texMathZoneEnsured texMathZone set conceallevel=0 " for jsons set ttymouse=sgr " tmux mouse behaviour set mouse=a " enable mouse in n,v,i,c,h modes " persistent undo history (even if close buffer) " Save undos after file closes set undofile " where to save undo histories set undodir=~/.vim/undo// " How many undos set undolevels=2000 " save whole buffer for undo on reload if number of lines is smaller than set undoreload=10001 " make folders automatically if they don't already exist 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 laststatus=2 " show powerline status bar set t_Co=256 set guifont=Fira\ Code\ weight=450\ 12 set ballooneval " vim8+ popups let g:netrw_beval = 1 set t_vb= " cursorline optimizations set cursorlineopt=number syntax sync minlines=256 " use +/clipboard as default register set clipboard=unnamedplus " vim help had this to say about 'exrc': " " Enables the reading of .vimrc, .exrc and .gvimrc in the current directory. " Setting this option is a potential security leak. E.g., consider unpacking " a package or fetching files from github, a .vimrc in there might be a trojan " horse. BETTER NOT SET THIS OPTION! " Instead, define an autocommand in your .vimrc to set options for a matching " directory. " " but since it's needed for direnv, we have to enable it. set exrc set secure function! AskQuit (msg, proposed_action) if confirm(a:msg, "&Quit?\n" . a:proposed_action) == 1 exit endif endfunction function! EnsureDirExists () let required_dir = expand('%:h') if !isdirectory(required_dir) call AskQuit('Directory "' . required_dir . '" doesn''t exist.', '&Create it?') try call mkdir( required_dir, 'p' ) catch call AskQuit('Can''t create "' . required_dir . '"', '&Continue anyway?') endtry endif endfunction augroup AutoMkdir autocmd! autocmd BufNewFile * :call EnsureDirExists() augroup END " as per https://stackoverflow.com/a/38775966 function! HeaderToggle() " bang for overwrite when saving vimrc let file_path = expand('%') let file_name = expand('%<') let extension = split(file_path, '\.')[-1] " '\.' is how you really split on dot let err_msg = 'There is no file ' if extension ==# 'cpp' let next_file = join([file_name, '.h'], '') if filereadable(next_file) :e %<.h else echo join([err_msg, next_file], '') endif elseif extension ==# 'h' let next_file = join([file_name, '.cpp'], '') if filereadable(next_file) :e %<.cpp else echo join([err_msg, next_file], '') endif endif endfunction nnoremap hh :call HeaderToggle() if(&filetype ==# 'c') || (&filetype ==# 'cpp') if isdirectory('include') set path+=include elseif isdirectory('inc') set path+=inc elseif isdirectory('src/include') set path+=src/include endif endif silent function! LINUX() return has('unix') && !has('macunix') && !has('win32unix') endfunction " note: this might be outdated at this point, I am not sure. " https://github.com/bling/vim-airline/issues/539 function! RefreshUI() if exists(':AirlineRefresh') AirlineRefresh else " Clear & redraw the screen, then redraw all statuslines. redraw! redrawstatus! endif endfunction " from vim wiki augroup autoReloadVimRC autocmd! " automatically reload vimrc when it's saved autocmd BufWritePost ~/.vimrc so ~/.vimrc | call RefreshUI() augroup END " reload config nnoremap ve :e $MYVIMRC " reload config and call refresh fn nnoremap vr :source $MYVIMRCcall RefreshUI() " https://sw.kovidgoyal.net/kitty/faq/#using-a-color-theme-with-a-background-color-does-not-work-well-in-vim " work wround vim's background colour erase let &t_ut='' " as per https://github.com/direnv/direnv/wiki/Vim if exists('$EXTRA_VIM') for path in split($EXTRA_VIM, ':') exec 'source '.path endfor endif " vim: ft=vim ff=unix expandtab ts=2 sw=2