" 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 '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' 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 highlight Comment cterm=italic " Lightline set laststatus=2 set noshowmode let g:lightline = { \ 'colorscheme': 'minimalist', \ '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() " 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 let g:ale_disable_lsp = 1 " 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', 'phpcs' ] let g:ale_linters.go = [ 'gopls', 'gofmt', 'gobuild' ] let g:ale_phpcs_standard = "PSR2" " ALE fixers let g:ale_fixers = { '*': [ 'remove_trailing_lines', 'trim_whitespace' ] } let g:ale_fixers.javascript = [ 'prettier', 'eslint' ] let g:ale_fixers.go = [ 'gofmt' ] " 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 " 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 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(getqfist(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() " Fuzzy search nmap f :Files nmap s :Rg " Git gutter nmap n :GitGutterNextHunk nmap p :GitGutterPrevHunk " 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 title = @% == "" ? "vim" : "vim | " . expand("%:t") call system("tmux rename-window '" . title . "'") 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() " 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 " LSP servers let g:lsc_server_commands = {} let g:lsc_server_commands = { \ 'javascript': { 'command': 'typescript-language-server --stdio', 'log_level': -1, 'suppress_stderr': v:true }, \ 'javascript.jsx': { 'command': 'typescript-language-server --stdio', 'log_level': -1, 'suppress_stderr': v:true }, \ 'go': { 'command': 'gopls serve', 'log_level': -1, 'suppress_stderr': v:true }, \ 'php': { 'command': 'intelephense --stdio', 'message_hooks': {'initialize': { 'initializationOptions': {'storagePath': '/tmp/intelephense'} } } }, \} " LSP close preview after selecting completion autocmd CompleteDone * silent! pclose " LSP close quickfix list after selection autocmd BufLeave * cclose