Skip to content

Instantly share code, notes, and snippets.

@anthony2025
Created December 29, 2017 14:53
Show Gist options
  • Save anthony2025/2272e4192149e214b12e7750dc435bc5 to your computer and use it in GitHub Desktop.
Save anthony2025/2272e4192149e214b12e7750dc435bc5 to your computer and use it in GitHub Desktop.
Vim config
" no compatible at the very start
set nocompatible
" VIM-PLUG Setup
" Automatic installation {{{
if empty(glob('~/.vim/autoload/plug.vim'))
silent !mkdir -p ~/.vim/autoload
silent !curl -fLo ~/.vim/autoload/plug.vim
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
au VimEnter * PlugInstall
endif
" }}}
call plug#begin('~/.vim/plugged')
" Vim navigation, commands, settings
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'scrooloose/nerdcommenter'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-surround'
Plug 'Raimondi/delimitMate'
Plug 'tpope/vim-fugitive'
Plug 'qpkorr/vim-bufkill'
Plug 'SirVer/ultisnips'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'easymotion/vim-easymotion'
" Linting and code completion
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable'}
Plug 'w0rp/ale'
Plug 'ludovicchabant/vim-gutentags'
" Language Support
Plug 'fatih/vim-go', {
\ 'do': ':GoInstallBinaries',
\ 'for': ['go']
\ }
Plug 'AndrewRadev/splitjoin.vim'
Plug 'pangloss/vim-javascript'
Plug 'jelera/vim-javascript-syntax'
Plug 'MaxMEllon/vim-jsx-pretty'
Plug 'alexbyk/vim-ultisnips-js-testing'
Plug 'leshill/vim-json', {
\'for': ['json']
\ }
" Cosmetics
Plug 'flazz/vim-colorschemes'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'dikiaap/minimalist'
Plug 'kien/rainbow_parentheses.vim'
Plug 'hashivim/vim-terraform'
Plug 'fatih/vim-hclfmt'
call plug#end()
" Global config
filetype off
let &runtimepath.='~/.vim/bundle/ale'
silent! helptags ALL
filetype plugin indent on
" Force vim-sensible to load and allow override of options
runtime! plugin/sensible.vim
set completeopt-=preview
set encoding =utf-8
set hidden " buffers don't need to be saved to switch
set nowrap " don't wrap lines
set shiftround " use multiple of sw when indenting with '<' and '>'
set showmatch " set show matching parenthesis
set number " line numbers
set relativenumber " relative line numbers, hybrid mode with both!
set ignorecase " ignore case when searching
set smartcase " ignore case if all lowercase, case-sensitive otherwise
set hlsearch " highlight search terms
set incsearch " show search matches as you type
set undolevels =1000 " use many muchos levels of undo
set title " change the terminal's title
set novisualbell " don't flash
set noerrorbells " don't beep
set pastetoggle=<F2>
set diffopt+=vertical
" dangerous, disable swap files
set noswapfile
autocmd BufWritePre * %s/\s\+$//e
if &t_Co > 2 || has('gui_running')
" switch syntax highlighting on, when the terminal has colors
syntax on
endif
let g:mapleader=',' " change the mapleader from \ to ,
" Useful commands
nmap <leader>delw :%s/\s\+$//<CR>
" CtrlP Settings
let g:ctrlp_custom_ignore = 'coverage\|node_modules\|DS_Store\|git|'
map <C-l> :CtrlPMRU<CR>
" NERDTree setting stuff
nmap <silent> <leader>e :NERDTreeToggle<CR>
function! StartUp()
if 0 == argc()
NERDTree
end
endfunction
autocmd VimEnter * call StartUp()
" Quickly edit the vimrc file
nmap <silent> <leader>ev :e ~/.vimrc<CR>
" Quivkly reload the vimrc file
nmap <silent> <leader>sv :so ~/.vimrc<CR>
" turn off highlighting after compeleting a search
nmap <silent> <leader>/ :nohlsearch<CR>
" delimate cursor positioning after parens
imap <C-c> <CR><Esc>O
" map escape to a more comfortable position
imap jj <Esc>
" close buffer without killing window
map <C-c> :BD<cr>
" navigate next and previous buffers
map <a-right> :BF<cr>
map <a-left> :BB<cr>
" Auto-completion settings
" Allow Enter to select and entry
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" open omni completion menu closing previous if open and opening new menu without changing the text
inoremap <expr> <C-Space> (pumvisible() ? (col('.') > 1 ? '<Esc>i<Right>' : '<Esc>i') : '') .
\ '<C-x><C-o><C-r>=pumvisible() ? "\<lt>C-n>\<lt>C-p>\<lt>Down>" : ""<CR>'
" open user completion menu closing previous if open and opening new menu without changing the text
inoremap <expr> <S-Space> (pumvisible() ? (col('.') > 1 ? '<Esc>i<Right>' : '<Esc>i') : '') .
\ '<C-x><C-u><C-r>=pumvisible() ? "\<lt>C-n>\<lt>C-p>\<lt>Down>" : ""<CR>'
" Tab Settings
set preserveindent " Preserve indent structure when changing indent level
set copyindent " Copy the indent level of previous lines
set tabstop =2 " The width of a \t is to 4.
set shiftwidth =2 " Indents will have a width of 4
set softtabstop =2 " Sets the number of columns for a \t
set mouse=a " I think it activates mouse mode for all something
set autoread
" Vim airline settings
let g:airline_powerline_fonts = 1
" Vim Airline Ale settings
let g:airline#extensions#ale#enabled = 1 " Ale airline extension
" Airline tabline settings
let g:airline#extensions#tabline#enabled = 0
let g:airline#extensions#tabline#buffer_nr_show = 0
" let g:airline#extensions#tabline#buffer_idx_mode = 1
" nmap <leader>1 <Plug>AirlineSelectTab1
" nmap <leader>2 <Plug>AirlineSelectTab2
" nmap <leader>3 <Plug>AirlineSelectTab3
" nmap <leader>4 <Plug>AirlineSelectTab4
" nmap <leader>5 <Plug>AirlineSelectTab5
" nmap <leader>6 <Plug>AirlineSelectTab6
" nmap <leader>7 <Plug>AirlineSelectTab7
" nmap <leader>8 <Plug>AirlineSelectTab8
" nmap <leader>9 <Plug>AirlineSelectTab9
" nmap <leader>- <Plug>AirlineSelectPrevTab
" nmap <leader>+ <Plug>AirlineSelectNextTab
" Airline fugitive integration settings
let g:airline#extensions#branch#enabled = 0 " Vim fugitive activated
let g:airline#extensions#branch#empty_message = '' " If no changes, no mesages
" Airline CSV settings
let g:airline#extensions#csv#enabled = 1
" Trailing whitespace and mixed tabs syntax enforcement
let g:airline#extensions#whitespace#enabled = 1
let g:airline#extensions#whitespace#mixed_indent_algo = 2
let g:airline#extensions#whitespace#checks = [ 'trailing' ]
let g:airline#extensions#whitespace#show_message = 1
let g:airline#extensions#whitespace#trailing_format = 'trailing[%s]'
let g:airline#extensions#c_like_langs = [
\ 'c', 'cpp', 'cuda',
\ 'go', 'javascript', 'ld',
\ 'php', 'js'
\ ]
" YCM config
let g:ycm_path_to_python_interpreter = '/usr/bin/python2'
let g:ycm_confirm_extra_conf=0
let g:ycm_complete_in_comments = 1
let g:ycm_seed_identifiers_with_syntax = 1
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_filetype_specific_completion_to_disable = {
\ 'gitcommit': 1
\}
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
" Utilisnips config
let g:UltiSnipsExpandTrigger='<c-j>'
let g:UltiSnipsJumpForwardTrigger='<c-j>'
let g:UltiSnipsJumpBackwardTrigger='<c-k>'
let g:UltiSnipsListSnippets='<c-h>'
" ALE config
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 0
let g:ale_sign_error = '>>'
let g:ale_sign_warning = '--'
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
nmap <silent> <c-,> <Plug>(ale_previous_wrap)
nmap <silent> <c-.> <Plug>(ale_next_wrap)
" NERD commenter settings
let g:NERDSpaceDelims = 1
let g:NERDTrimTrailingWhitespace = 1
" Misc commands
autocmd FileType c, cpp autocmd BufWritePre <buffer> %s/\s\+$//e
autocmd FileType javascript autocmd BufWritePre <buffer> %s/\s\+$//e
autocmd FileType html autocmd BufWritePre <buffer> %s/\s\+$//e
autocmd FileType java, sbt, scala autocmd BufWritePre <buffer> %s/\s\+$//e
" Syntax specific stuff
" Javascript
let g:jsx_ext_required = 0
let g:javascript_plugin_jsdoc = 1
let g:javascript_plugin_flow = 1
let g:xml_syntax_folding = 0
augroup Javascript
" Tab Settings
autocmd FileType javascript set ts=2 sts=2 sw=2 cole=1 et
augroup END
" Code Folding Settings
" set foldmethod=syntax
" set foldlevelstart=2
" set foldlevel=99
" set foldnestmax=100
" vim-go config
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
augroup Golang
au FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <leader>c <Plug>(go-coverage-toggle)
au FileType go nmap <Leader>i <Plug>(go-info)
au BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
augroup END
map <leader>n :cnext<CR>
map <leader>p :cprevious<CR>
nnoremap <leader>a :cclose<CR>
autocmd FileType go set autowrite
let g:go_list_type = "quickfix"
let g:go_fmt_command = "goimports"
let g:go_metalinter_autosave = 1
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
let g:go_snippet_case_type = "camelcase"
let g:go_highlight_types = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_auto_type_info = 1
let g:go_auto_sameids = 1
" Global colorization
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_start_level = 2
let g:indent_guides_auto_colors = 1
let g:indent_guides_guide_size = 1
set t_Co=256
set background =dark
if &t_Co >= 256 || has('gui_running')
colorscheme minimalist
endif
" Rainbow Parens, Brackets, Braces
let g:rbpt_colorpairs = [
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['brown', 'firebrick3'],
\ ['gray', 'RoyalBlue3'],
\ ['black', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
\ ['Darkblue', 'firebrick3'],
\ ['darkgreen', 'RoyalBlue3'],
\ ['darkcyan', 'SeaGreen3'],
\ ['darkred', 'DarkOrchid3'],
\ ['red', 'firebrick3'],
\ ]
augroup rainbowParens
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
augroup END
" EasyMotion
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" Jump to anywhere you want with minimal keystrokes, with just one key binding. `s{char}{label}`
nmap s <Plug>(easymotion-overwin-f)
" or `s{char}{char}{label}`
" Need one more keystroke, but on average, it may be more comfortable.
nmap s <Plug>(easymotion-overwin-f2)
" Turn on case insensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
" workaround for X11 clipboard
" function Func2X11()
" :call system('xclip -selection c', @r)
" endfunction
" vnoremap <F9> "ry:call Func2X11()<cr>
" vnoremap <m-c> "ry:call Func2X11()<cr>
" vnoremap <ESC-c> "ry:call Func2X11()<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment