| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- " Run the following git commands to get the plugins
- " 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
- " Pre-plugin calls
- let g:ale_completion_enabled = 1
- let g:ale_hover_to_floating_preview = 1
- let g:ale_floating_preview = 1
- " Plugins
- call plug#begin('~/.vim/plugged')
- Plug 'preservim/nerdtree'
- Plug 'tpope/vim-fugitive'
- Plug 'tpope/vim-commentary'
- 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'
- call plug#end()
-
- filetype plugin indent on
- syntax on
- set autoindent
- set backspace=2
- set background=dark
- set completeopt=menu,popup
- 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 termguicolors
- set tabstop=2
- set whichwrap+=<,>,[,],h,l
- set undofile
- set undodir=~/.vim/undo
- " ALE
- let g:ale_use_global_executables = 1
- let g:ale_linters_explicit = 1
- let g:ale_linters = {}
- let g:ale_linters.javascript = [ 'eslint', 'tsserver' ]
- let g:ale_fixers = {}
- let g:ale_fixers.javascript = [ 'prettier', 'eslint' ]
- " ALE completion
- let g:ale_completion_autoimport = 1
- set omnifunc=ale#completion#OmniFunc
- " Ale keymaps
- nnoremap <C-a>g :ALEGoToDefinition -tab<CR>
- nnoremap <C-a>G :ALEGoToDefinition<CR>
- nnoremap <C-a>h :ALEHover<CR>
- nnoremap <C-a>f :ALEFindReferences<CR>
- " ALE navigation
- nmap <silent> <C-k> <Plug>(ale_previous_wrap)
- nmap <silent> <C-j> <Plug>(ale_next_wrap)
- let g:material_theme_style = 'darker'
- let g:material_terminal_italics = 1
- colorscheme material
- " Lightline
- set laststatus=2
- set noshowmode
- let g:lightline = {
- \ 'colorscheme': 'material_vim',
- \ 'active': {
- \ 'left': [
- \ [ 'mode', 'paste' ],
- \ [ 'gitbranch', 'readonly', 'filename', 'tagbar', 'modified' ]
- \ ],
- \ 'right': [
- \ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ],
- \ [ 'percent', 'lineinfo', 'offset' ],
- \ [ 'fileformat', 'fileencoding', 'filetype' ]
- \ ]
- \ },
- \ 'component': {
- \ 'tagbar': '%{tagbar#currenttag("%s", "", "f", "nearest-stl")}',
- \ },
- \ 'component_function': {
- \ 'gitbranch': 'FugitiveHead',
- \ 'offset': 'FileOffset'
- \ },
- \ 'component_expand': {
- \ '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_checking': 'right',
- \ 'linter_infos': 'right',
- \ 'linter_warnings': 'warning',
- \ 'linter_errors': 'error',
- \ 'linter_ok': 'right'
- \ }
- \ }
- function! FileOffset()
- return line2byte(line('.')) + col('.') - 1
- endfunction
- " NERDtree
- " Close NERDTree on opening file
- let NERDTreeQuitOnOpen=1
- " Show hidden files
- let NERDTreeShowHidden=1
- function! NERDTreeToggleCustom()
- " If NERDTree is open in the current buffer
- if (exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1)
- exe ":NERDTreeClose"
- elseif bufname('%') != ""
- exe ":NERDTreeFind"
- else
- exe ":NERDTreeCWD"
- endif
- endfunction
- " Toggle NERDTree on <space>-o
- map <Space>o :call NERDTreeToggleCustom()<CR>
- " Tagbar
- let g:tagbar_autoclose = 1
- let g:tagbar_autofocus = 1
- let g:tagbar_map_showproto = ''
- " 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
- autocmd BufEnter * if !exists("b:location_list") | let b:location_list = 0 | endif
- let b:location_list = 0
- function! Toggle_location_list()
- if b:location_list == 0
- lopen
- let b:location_list = 1
- else
- lclose
- let b:location_list = 0
- endif
- endfunction
- nnoremap <Space>l :call Toggle_location_list()<CR>
- " Location list
- autocmd BufEnter * if !exists("b:quick_list") | let b:quick_list = 0 | endif
- let b:quick_list = 0
- function! Toggle_quick_list()
- if b:quick_list == 0
- copen
- let b:quick_list = 1
- 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
- :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>
- " Key mappings
- map <C-l>n :cnext<CR>
- map <C-l>p :cprevious<CR>
- nnoremap <C-l>c :cclose<CR>
- nmap <Space>t :TagbarToggle<CR>
- nmap <Space>f :Files<CR>
- nmap <Space>r :Rg<CR>
- nmap <Space>n :GitGutterNextHunk<CR>
- nmap <Space>p :GitGutterPrevHunk<CR>
- " Setting title to enable better tmux titling
- if exists('$TMUX')
- autocmd BufReadPost,FileReadPost,BufNewFile,BufEnter * call system("tmux rename-window 'vim | " . expand("%:t") . "'")
- autocmd VimLeave * call system("tmux setw automatic-rename")
- endif
- function! PrettyXML()
- set filetype=xml
- silent %!xmllint --format --encode UTF-8 --recover - 2>/dev/null
- endfunction
- function! PrettyJSON()
- set filetype=json
- silent %!python3 -m json.tool
- endfunction
- command! PrettyXml call PrettyXML()
- command! PrettyJson call PrettyJSON()
- nmap <Space>x :call PrettyXML()<CR>
- nmap <Space>j :call PrettyJSON()<CR>
- " Disable bad default keybindings
- inoremap <C-w> <Nop>
|