" Plugin manager 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 " Plugins call plug#begin('~/.vim/plugged') Plug 'preservim/nerdtree' Plug 'tpope/vim-fugitive' Plug 'tpope/vim-commentary' Plug 'junegunn/vim-peekaboo' Plug 'itchyny/lightline.vim' Plug 'dikiaap/minimalist' Plug 'kaicataldo/material.vim' " Plug 'dense-analysis/ale' Plug 'ssh://git@gogs.viktorgrahn.com:2022/viktor/ale.git' Plug 'maximbaz/lightline-ale' Plug 'preservim/tagbar' Plug 'vim-php/tagbar-phpctags.vim' Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } Plug 'junegunn/fzf.vim' Plug 'airblade/vim-gitgutter' Plug 'mxw/vim-jsx' Plug 'pangloss/vim-javascript' Plug 'natebosch/vim-lsc' Plug 'tpope/vim-surround' Plug 'nordtheme/vim' Plug 'ap/vim-css-color', { 'for': [ 'css', 'scss' ] } Plug 'pearofducks/ansible-vim' call plug#end() filetype plugin indent on syntax on set autoindent set backspace=2 set background=dark set completeopt=menu,popup,noselect set cursorcolumn set cursorline set expandtab set history=1000 set hlsearch set incsearch set nowrap set number set numberwidth=4 set pastetoggle= "Press when paste-alot set preserveindent set ruler set shiftround set shiftwidth=2 set shortmess=atI set showcmd set showmatch set smartindent set smarttab set splitright set switchbuf+=usetab,newtab set termguicolors set tabstop=2 set whichwrap+=<,>,[,],h,l set undofile set undodir=~/.vim/undo " Colorscheme " colorscheme minimalist colorscheme nord highlight Comment cterm=italic highlight Pmenu ctermbg=233 set background=dark " Lightline set laststatus=2 set noshowmode " Source lightline theme if empty(glob('~/.vim/source/minimalist.vim')) silent !curl -fLO --create-dirs --output-dir ~/.vim/source https://public.viktorgrahn.com/minimalist.vim endif source ~/.vim/source/minimalist.vim let g:lightline = { \ 'colorscheme': 'nord', \ 'tabline_subseparator': { 'left': '', 'right': '' }, \ 'active': { \ 'left': [ \ [ 'mode', 'paste' ], \ [ 'filestate' ], \ [ 'gitbranch', 'tagbar' ], \ ], \ 'right': [ \ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ], \ [ 'fileformat', 'fileencoding', 'filetype', 'percent', 'lineinfo', 'offset' ], \ ] \ }, \ 'tabline': { \ 'left': [ [ 'tabs' ] ], \ 'right': [ ], \ }, \ 'component': { \ 'tagbar': '%{tagbar#currenttag("%s", "", "f", "nearest-stl")}', \ }, \ 'component_function': { \ 'filestate': 'LightlineFileState', \ 'offset': 'LightlineFileOffset', \ }, \ 'component_expand': { \ 'gitbranch': 'FugitiveHead', \ 'linter_checking': 'lightline#ale#checking', \ 'linter_infos': 'lightline#ale#infos', \ 'linter_warnings': 'lightline#ale#warnings', \ 'linter_errors': 'lightline#ale#errors', \ 'linter_ok': 'lightline#ale#ok', \ }, \ 'component_type': { \ 'linter_warnings': 'warning', \ 'linter_errors': 'error', \ 'linter_ok': 'ok', \ 'linter_infos': 'info', \ } \ } " Lightline helper (concatenate readonly state, filename and modified state) function! LightlineFileState() if @% == "" | return "[No name]" | endif let s = expand('%:t') if &modified | let s = s . "+" | endif if &readonly | let s = "[RO] " . s | endif return s endfunction " Lightline helper (get cursor line and character position in file) function! LightlineFileOffset() return line2byte(line('.')) + col('.') - 1 endfunction " NERDtree let NERDTreeQuitOnOpen=1 let NERDTreeShowHidden=1 " NERDTree helper (toggle in current buffer) function! NERDTreeToggleCustom() if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1) exe ":NERDTreeClose" elseif bufname('%') != "" exe ":NERDTreeFind" else exe ":NERDTreeCWD" endif endfunction " NERDTREE Toggle NERDTree on -o map o :call NERDTreeToggleCustom() " NERDTree fix for menu bug let g:NERDTreeMinimalMenu=1 " ALE Configuration let g:ale_completion_enabled = 0 let g:ale_sign_column_always = 1 let g:ale_set_signs = 1 let g:ale_set_highlights = 0 " QD for intelephense stubs let s:intelephense_config = { \ 'stubs': [ 'apache', 'bcmath', 'bz2', 'calendar', 'com_dotnet', 'Core', 'ctype', 'curl', 'date', 'dba', 'dom', 'enchant', 'exif', 'FFI', 'fileinfo', 'filter', 'fpm', 'ftp', 'gd', 'gettext', 'gmp', 'hash', 'iconv', 'imap', 'intl', 'json', 'ldap', 'libxml', 'mbstring', 'meta', 'mongodb', 'mysqli', 'oci8', 'odbc', 'openssl', 'pcntl', 'pcre', 'PDO', 'pdo_ibm', 'pdo_mysql', 'pdo_pgsql', 'pdo_sqlite', 'pgsql', 'Phar', 'posix', 'pspell', 'readline', 'Reflection', 'session', 'shmop', 'SimpleXML', 'snmp', 'soap', 'sockets', 'sodium', 'SPL', 'sqlite3', 'standard', 'superglobals', 'sysvmsg', 'sysvsem', 'sysvshm', 'tidy', 'tokenizer', 'xml', 'xmlreader', 'xmlrpc', 'xmlwriter', 'xsl', 'ZendOPcache', 'zip', 'zlib' ], \ 'files': { \ 'maxSize': 2000000 \ }, \} if exists("*ale#linter#Define") " Custom intelephense call ale#linter#Define('php', { \ 'name': 'intelephense-debug', \ 'lsp': 'stdio', \ 'initialization_options': function('ale_linters#php#intelephense#GetInitializationOptions'), \ 'executable': {b -> ale#path#FindExecutable(b, 'php_intelephense', [])}, \ 'command': '%e --stdio', \ 'project_root': function('ale_linters#php#intelephense#GetProjectRoot'), \ 'lsp_config': s:intelephense_config, \}) endif " ALE linters let g:ale_use_global_executables = 1 let g:ale_linters_explicit = 1 let g:ale_linters = {} let g:ale_linters.javascript = [ 'eslint' ] let g:ale_linters.php = [ 'intelephense-debug', 'phpcs', 'phpmd' ] let g:ale_linters.go = [ 'gopls', 'gofmt', 'gobuild' ] let g:ale_linters.json = [ 'jsonlint', 'jq' ] let g:ale_history_log_output = 1 let g:ale_virtualtext_cursor = 'current' let g:ale_phpcs_standard = "PSR2" let g:ale_php_phpmd_ruleset = 'cleancode' let g:ale_php_intelephense_executable = 'debugIntelephense.sh' " ALE fixers let g:ale_fixers = { '*': [ 'remove_trailing_lines', 'trim_whitespace' ] } let g:ale_fixers.javascript = [ 'prettier', 'eslint' ] let g:ale_fixers.json = [ 'prettier' ] let g:ale_fixers.go = [ 'gofmt', 'goimports' ] " ALE message should include responsible linter let g:ale_echo_msg_format = '[%linter%] %s' " Ale keymaps nnoremap l :ALELint nnoremap f :ALEFix nnoremap i :ALEInfo nnoremap n :ALENext nnoremap p :ALEPrevious " ALE styling highlight ALEErrorSign ctermbg=237 ctermfg=167 highlight ALEWarningSign ctermbg=237 ctermfg=215 highlight ALEInfoign ctermbg=237 ctermfg=117 " ALE Configuration end " Tagbar let g:tagbar_autoclose = 1 let g:tagbar_autofocus = 1 let g:tagbar_map_showproto = '' nmap t :TagbarToggle " Toggle transparent background let g:is_transparent = 0 function! Toggle_transparent() echo g:is_transparent if g:is_transparent == 0 hi Normal guibg=NONE ctermbg=NONE hi NonText guibg=NONE ctermbg=NONE let g:is_transparent = 1 else set background=dark let g:is_transparent = 0 endif endfunction nnoremap T :call Toggle_transparent() " Location list toggle function! Toggle_location_list() if get(b:, 'location_list', 0) == 0 silent! lopen if get(getloclist(0, { 'winid': 0 }), 'winid') let b:location_list = 1 endif else lclose let b:location_list = 0 endif endfunction nnoremap l :call Toggle_location_list() " Quickfix list toggle function! Toggle_quick_list() if get(b:, 'quick_list', 0) == 0 silent! copen if get(getqflist(0, { 'winid': 0 }), 'winid') let b:quick_list = 1 endif else cclose let b:quick_list = 0 endif endfunction nnoremap c :call Toggle_quick_list() " Git blame autocmd BufEnter * if !exists("b:git_blame") | let b:git_blame = 0 | endif function! Toggle_git_blame() if b:git_blame == 0 :silent! Git blame let b:git_blame = 1 else let winIndex = 1 let winCnt = winnr('$') while winIndex <= winCnt if expand('%:e') == "fugitiveblame" :close else :wincmd w endif let winIndex += 1 endwhile let b:git_blame = 0 endif endfunction nnoremap b :call Toggle_git_blame() " Git gutter nmap n :GitGutterNextHunk nmap p :GitGutterPrevHunk " Fuzzy search nmap f :Files nmap s :Rg nmap w :Windows " Setting title to enable better tmux titling if exists('$TMUX') autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call UpdateTmuxWindow() autocmd VimLeave * call system("tmux setw automatic-rename") endif function UpdateTmuxWindow() let excludedFiletypes = [ 'help', 'qf', 'nerdtree' ] if index(excludedFiletypes, &filetype) < 0 let title = @% == "" ? "vim" : "vim (" . expand("%:t") . ")" call system("tmux rename-window '" . title . "'") endif endfunction " Format XML pretty function! PrettyXML() set filetype=xml silent %!xmllint --format --encode UTF-8 --recover - 2>/dev/null endfunction " Format json pretty function! PrettyJSON() set filetype=json silent %!python3 -m json.tool endfunction nmap x :call PrettyXML() nmap j :call PrettyJSON() " Diff since save nmap d :w !diff -y --suppress-common-lines --color % - " Navigation keymaps inoremap inoremap inoremap inoremap " Disable bad default keybindings inoremap " LSP configuration let g:lsc_enable_diagnostics = v:false let g:lsc_auto_map = v:true let g:lsc_autocomplete_length=1 set omnifunc=lsc#complete#complete " LSP keymappings nnoremap f :LSClientFindReferences nnoremap g :tab LSClientGoToDefinitionSplit nnoremap G :LSClientGoToDefinition nnoremap h :LSClientShowHover nnoremap s :LSClientSignatureHelp inoremap s :LSClientSignatureHelp " LSP servers let lsc_server_defaults = { 'log_level': -1, 'suppress_stderr': v:true } let g:lsc_server_commands = { \ 'javascript': extend({ 'command': 'typescript-language-server --stdio'}, lsc_server_defaults), \ 'javascript.jsx': extend({ 'command': 'typescript-language-server --stdio'}, lsc_server_defaults), \ 'go': extend({ 'command': 'gopls serve' }, lsc_server_defaults), \ 'php': extend({ 'command': 'intelephense --stdio', 'message_hooks': {'initialize': { 'initializationOptions': {'storagePath': '/tmp/intelephense'} } } }, lsc_server_defaults), \ 'yaml.ansible': extend({ 'command': 'ansible-language-server --stdio'}, lsc_server_defaults}, \} " LSP close preview after selecting completion autocmd CompleteDone * silent! pclose " LSP close quickfix list after selection autocmd BufLeave * cclose " Auto expand inoremap (; ();O inoremap (, (),O inoremap ( ()O inoremap {; {};O inoremap {, {},O inoremap { {}O inoremap [; [];O inoremap [, [],O inoremap [ []O