| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- " 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 'ap/vim-css-color', { 'for': [ 'css', 'scss' ] }
- 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=<F12> "Press <F12> 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
- highlight Pmenu ctermbg=233
- " 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': '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 <space>-o
- map <Space>o :call NERDTreeToggleCustom()<CR>
- " 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'
- let g:ale_php_intelephense_config = { 'storagePath': '/tmp/intelephense-ale' }
- " 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 <C-a>l :ALELint<CR>
- nnoremap <C-a>f :ALEFix<CR>
- nnoremap <C-a>i :ALEInfo<CR>
- nnoremap <C-a>n :ALENext<CR>
- nnoremap <C-a>p :ALEPrevious<CR>
- " 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 <Space>t :TagbarToggle<CR>
- " 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 <Space>T :call Toggle_transparent()<CR>
- " 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 <Space>l :call Toggle_location_list()<CR>
- " 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 <Space>c :call Toggle_quick_list()<CR>
- " 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 <Space>b :call Toggle_git_blame()<CR>
- " Git gutter
- nmap <C-g>n :GitGutterNextHunk<CR>
- nmap <C-g>p :GitGutterPrevHunk<CR>
- " Fuzzy search
- nmap <Space>f :Files<CR>
- nmap <Space>s :Rg<CR>
- nmap <Space>w :Windows<CR>
- " 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 <Space>x :call PrettyXML()<CR>
- nmap <Space>j :call PrettyJSON()<CR>
- " Diff since save
- nmap <Space>d :w !diff -y --suppress-common-lines --color % -<CR>
- " Navigation keymaps
- inoremap <C-h> <Left>
- inoremap <C-l> <Right>
- inoremap <C-j> <Down>
- inoremap <C-k> <Up>
- " Disable bad default keybindings
- inoremap <C-w> <Nop>
- " 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 <C-l>f :LSClientFindReferences<CR>
- nnoremap <C-l>g :tab LSClientGoToDefinitionSplit<CR>
- nnoremap <C-l>G :LSClientGoToDefinition<CR>
- nnoremap <C-l>h :LSClientShowHover<CR>
- nnoremap <C-l>c :LSClientSignatureHelp<CR>
- " 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 },
- \ 'php': { 'command': 'intelephense --stdio', 'message_hooks': {'initialize': { 'initializationOptions': {'storagePath': '/tmp/intelephense'} } }, 'workspace_config': { 'intelephense': s:intelephense_config } },
- \ 'go': { 'command': 'gopls serve', 'log_level': -1, 'suppress_stderr': v:true },
- \}
- " LSP close preview after selecting completion
- autocmd CompleteDone * silent! pclose
- " LSP close quickfix list after selection
- autocmd BufLeave * cclose
- " Auto expand
- inoremap (; (<CR>);<C-c>O
- inoremap (, (<CR>),<C-c>O
- inoremap (<CR> (<CR>)<C-c>O
- inoremap {; {<CR>};<C-c>O
- inoremap {, {<CR>},<C-c>O
- inoremap {<CR> {<CR>}<C-c>O
- inoremap [; [<CR>];<C-c>O
- inoremap [, [<CR>],<C-c>O
- inoremap [<CR> [<CR>]<C-c>O
|