Skip to content

Instantly share code, notes, and snippets.

@kolach
Last active December 25, 2016 15:45
Show Gist options
  • Save kolach/c6149ec4aefc658ab1ce to your computer and use it in GitHub Desktop.
Save kolach/c6149ec4aefc658ab1ce to your computer and use it in GitHub Desktop.
" Set 'nocompatible' to ward off unexpected things that your distro might
" have made, as well as sanely reset options when re-sourcing .vimrc
set nocompatible
filetype off " required
scriptencoding utf-8
set encoding=utf-8
" Clear mapping
mapclear
function! BuildYCM(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.force
!./install.py
endif
endfunction
function! InstallTypescript(info)
" info is a dictionary with 3 fields
" - name: name of the plugin
" - status: 'installed', 'updated', or 'unchanged'
" - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.force
!npm install -g typescript
endif
endfunction
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
Plug 'jlanzarotta/bufexplorer'
Plug 'jstemmer/gotags', { 'for': 'go' }
Plug 'morhetz/gruvbox'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
"Plug 'scrooloose/syntastic'
Plug 'majutsushi/tagbar'
Plug 'Valloric/ListToggle'
Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') }
Plug 'SirVer/ultisnips'
"Plug 'honza/vim-snippets'
"Plug 'bling/vim-airline'
Plug 'powerline/powerline', { 'branch': 'develop', 'rtp': 'powerline/bindings/vim' }
"Plug 'bling/vim-bufferline'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries', 'for': 'go' }
Plug 'AndrewRadev/splitjoin.vim', { 'for': 'go' }
Plug 'tpope/vim-unimpaired'
Plug 'stephpy/vim-yaml', { 'for': 'yaml' }
Plug 'rhysd/devdocs.vim'
Plug 'kshenoy/vim-signature'
Plug 'Matt-Deacalion/vim-systemd-syntax', { 'for': 'systemd' }
Plug 'editorconfig/editorconfig-vim'
Plug 'vim-scripts/dbext.vim', { 'for': 'sql' }
Plug 'rust-lang/rust.vim', { 'for': 'rust' }
Plug 'racer-rust/vim-racer', { 'for': 'rust', 'do': 'cargo install racer' }
Plug 'ctrlpvim/ctrlp.vim'
Plug 'ryanoasis/vim-devicons'
Plug 'CoatiSoftware/vim-coati'
Plug 'Shougo/vimproc.vim', { 'do': 'make' }
Plug 'Quramy/tsuquyomi', { 'do': function('InstallTypescript'), 'for': 'typescript' }
Plug 'leafgarland/typescript-vim', { 'for': 'typescript' }
Plug 'HerringtonDarkholme/yats.vim', { 'for': 'typescript' }
Plug 'ternjs/tern_for_vim', { 'for': 'javascript' }
Plug 'Quramy/vim-js-pretty-template', { 'for': ['javascript', 'typescript'] }
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'mhinz/vim-grepper'
Plug 'sjl/gundo.vim'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-git'
Plug 'Yggdroot/indentLine'
" Add plugins to &runtimepath
call plug#end()
" Enable syntax highlighting
syntax enable
syntax on
filetype plugin indent on " required
" Fixing backspace issue
set backspace=2
set hidden
set showcmd " show command in bottom bar"
set cursorline " highlight current line"
set wildmenu " visual autocomplete for command menu
set lazyredraw " redraw only when we need to
set incsearch " search as characters are entered
set hlsearch " highlight matches
" turn off search highlight
nnoremap <leader><space> :nohlsearch<CR>
" Writes the content of the file automatically if you call :make
set autowrite
" Tab, space and end of line symbols
" use `:set list' command to enable
" use `:set nolist' command to disable
set listchars=eol:⏎,tab:\┆\ ,trail:␠,nbsp:⎵
" Yank to system clipboard
set clipboard=unnamed
" Automatically removing all trailing whitespace
autocmd BufWritePre *.cpp call StripTrailingWhitespaces()
autocmd BufWritePre *.hpp call StripTrailingWhitespaces()
autocmd BufWritePre *.h call StripTrailingWhitespaces()
autocmd BufWritePre *.c call StripTrailingWhitespaces()
autocmd BufWritePre *.java call StripTrailingWhitespaces()
autocmd BufWritePre *.js call StripTrailingWhitespaces()
autocmd BufWritePre *.ts call StripTrailingWhitespaces()
autocmd BufWritePre *.yml call StripTrailingWhitespaces()
autocmd BufWritePre *.conf call StripTrailingWhitespaces()
autocmd BufWritePre *.cfg call StripTrailingWhitespaces()
autocmd BufWritePre *.sql call StripTrailingWhitespaces()
autocmd BufWritePre *.go call StripTrailingWhitespaces()
autocmd BufWritePre *.rs call StripTrailingWhitespaces()
"autocmd BufWritePre *.* call StripTrailingWhitespaces()
" strips trailing whitespace at the end of files. this
" is called on buffer write in the autogroup above.
function! StripTrailingWhitespaces()
" save last search & cursor position
let _s=@/
let l = line(".")
let c = col(".")
%s/\s\+$//e
let @/=_s
call cursor(l, c)
endfunction
" Store swap files in this directory
" set dir=~/.vim/swap
" Set zsh shell
set shell=/bin/zsh
" This option forces vim to source .vimrc file if it present in working directory,
" thus providing a place to store project-specific configuration
set exrc
" This option will restrict usage of some commands in non-default .vimrc files;
" commands that write to file or execute shell commands are not allowed and
" map commands are displayed.
set secure
" Set line numbers
nmap <C-L> :call ToggleNumber()<CR>
" toggle between number and relativenumber
function! ToggleNumber()
if (&number == 1)
if (&relativenumber != 1)
set relativenumber
else
set norelativenumber
set nonumber
endif
else
set number
endif
endfunc
" CTRL+Q exit
map Q :q<CR>
" Windows splitting
map <C-w>- :split<CR>
map <C-w>\ :vsplit<CR>
" Bubble single lines
" requires tpope's vim-unimpaired installed
" https://github.com/tpope/vim-unimpaired
nmap <C-k> [e
nmap <C-j> ]e
" Bubble multiple lines
vmap <C-k> [egv
vmap <C-j> ]egv
" Save your backup files to a less annoying place than the current directory.
" If you have .vim-backup in the current directory, it'll use that.
" Otherwise it saves it to ~/.vim/backup or .
if isdirectory($HOME . '/.vim/backup') == 0
:silent !mkdir -p ~/.vim/backup >/dev/null 2>&1
endif
set backupdir-=.
set backupdir+=.
set backupdir-=~/
set backupdir^=~/.vim/backup/
set backupdir^=./.vim-backup/
set backup
" Save your swap files to a less annoying place than the current directory.
" If you have .vim-swap in the current directory, it'll use that.
" Otherwise it saves it to ~/.vim/swap, ~/tmp or .
if isdirectory($HOME . '/.vim/swap') == 0
:silent !mkdir -p ~/.vim/swap >/dev/null 2>&1
endif
set directory=./.vim-swap//
set directory+=~/.vim/swap//
set directory+=~/tmp//
set directory+=.
" viminfo stores the the state of your previous editing session
set viminfo+=n~/.vim/viminfo
if exists("+undofile")
" undofile - This allows you to use undos after exiting and restarting
" This, like swap and backup files, uses .vim-undo first, then ~/.vim/undo
" :help undo-persistence
" This is only present in 7.3+
if isdirectory($HOME . '/.vim/undo') == 0
:silent !mkdir -p ~/.vim/undo > /dev/null 2>&1
endif
set undodir=./.vim-undo//
set undodir+=~/.vim/undo//
set undofile
endif
" Allows cursor change in tmux mode
" Without these lines, tmux always uses block cursor mode
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" move vertically by visual line
" if there's a very long line that gets visually wrapped to two lines, j won't
" skip over the "fake" part of the visual line in favor of the next "real" line
nnoremap j gj
nnoremap k gk
" highlight last inserted text
nnoremap gV `[v`]
" *****************************************************************************
" Folding
" *****************************************************************************
set foldenable " enable folding
set foldlevelstart=10 " open most folds by default
set foldnestmax=10 " 10 nested fold max
" space open/closes folds
nnoremap <space> za
set foldmethod=indent " fold based on indent level
" *****************************************************************************
" Syntastic plugin settings
" *****************************************************************************
" let statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
let g:syntastic_debug=0
"let g:syntastic_cpp_compiler = 'clang++'
"let g:syntastic_cpp_compiler_options = ' -std=c++14 -stdlib=libc++'
let g:syntastic_cpp_check_header = 1
let g:syntastic_error_symbol = ""
let g:syntastic_warning_symbol = ""
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_html_checkers=['jshint']
" *****************************************************************************
" NERDTree
" https://github.com/scrooloose/nerdtree
" *****************************************************************************
let g:NERDTreeDirArrows = 1
let g:NERDTreeDirArrowExpandable = ""
let g:NERDTreeDirArrowCollapsible = ""
" Open a NERDTree automatically when vim starts up if no files were specified
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | end
map <F2> :NERDTreeToggle<CR>
nmap ,n :NERDTreeFind<CR>
" NERDTress File highlighting
function! NERDTreeHighlightFile(extension, fg, bg, guifg, guibg)
exec 'autocmd FileType nerdtree highlight ' . a:extension .' ctermbg='. a:bg .' ctermfg='. a:fg .' guibg='. a:guibg .' guifg='. a:guifg
exec 'autocmd FileType nerdtree syn match ' . a:extension .' #^\s\+.*'. a:extension .'$#'
endfunction
" To have different file types collor differently
call NERDTreeHighlightFile('css', 'cyan', 'none', 'cyan', '#151515')
call NERDTreeHighlightFile('less', 'cyan', 'none', 'cyan', '#151515')
call NERDTreeHighlightFile('scss', 'cyan', 'none', 'cyan', '#151515')
call NERDTreeHighlightFile('html', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('json', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('js', 'Red', 'none', '#ffa500', '#151515')
" Exclude this directories from tree view
let NERDTreeIgnore = ['node_modules']
" *****************************************************************************
" gruvbox color chema
" *****************************************************************************
colorscheme gruvbox
set background=dark " Setting dark mode
nnoremap <silent> [oh :call gruvbox#hls_show()<CR>
nnoremap <silent> ]oh :call gruvbox#hls_hide()<CR>
nnoremap <silent> coh :call gruvbox#hls_toggle()<CR>
nnoremap * :let @/ = ""<CR>:call gruvbox#hls_show()<CR>*
nnoremap / :let @/ = ""<CR>:call gruvbox#hls_show()<CR>/
nnoremap ? :let @/ = ""<CR>:call gruvbox#hls_show()<CR>?
" Clear vertical split character
set fillchars+=vert:\
" Comments in italic font
" http://www.eddieantonio.ca/blog/2015/04/16/iterm-italics/
"
" To make it work in tmux > v2.1 on Mac OSX:
" download http://invisible-island.net/datafiles/current/terminfo.src.gz
" mkdir ~/.terminfo
" gunzip terminfo.src.gz
" export TERMINFO=~/.terminfo
" tic -x -e tmux terminfo.src
" tic -x -e tmux-256color terminfo.src
"
" in ~/.tmux.conf:
" set -g default-terminal "tmux-256color"
highlight Comment cterm=italic
" *****************************************************************************
" Ctrlp plugin settings
" *****************************************************************************
let g:ctrlp_cmd = 'CtrlP'
" To order matching files top to bottom with
let g:ctrlp_match_window = 'bottom,order:ttb'
" lets us change the working directory during a Vim session and make CtrlP
" respect that change
let g:ctrlp_working_path_mode = 0
" To make CtrlP wicked fast
" g:ctrlp_show_hidden and g:ctrlp_custom_ignore do not work with custom user commands.
" ag has it's own convention for ignore files: a .agignore file that follows
" the same conventions as .gitignore
if executable("ag")
let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'
endif
" Use ripgrep if it's available to make it even faster
" https://github.com/BurntSushi/ripgrep
if executable("rg")
let g:ctrlp_user_command = 'rg %s --files --color=never'
endif
" Exclude some directories and files
"let g:ctrlp_custom_ignore = {
"\ 'dir': 'node_modules'
"\ }
" *****************************************************************************
" Tagbar
" https://github.com/majutsushi/tagbar
" *****************************************************************************
nmap <F8> :TagbarToggle<CR>
" *****************************************************************************
" Buffer Explorer
" *****************************************************************************
" https://github.com/jlanzarotta/bufexplorer
" map <C-t> \be
" *****************************************************************************
" powerline plugin settings
" *****************************************************************************
let g:Powerline_symbols = "fancy"
" Show status even for only 1 window open
" 0: never
" 1: only if there are at least two windows (this one is the default)
" 2: always
set laststatus=2
" *****************************************************************************
" vim-gitgutter settings
" *****************************************************************************
nmap <F9> :GitGutterLineHighlightsToggle<CR>
" *****************************************************************************
" gundo plugin settings
" *****************************************************************************
" http://sjl.bitbucket.org/gundo.vim
nnoremap <F6> :GundoToggle<CR>
" *****************************************************************************
" YCM plugin
" *****************************************************************************
"
" do not ask to evaluate extra conf file on buffer open
let g:ycm_confirm_extra_conf = 0
"let g:ycm_show_diagnostics_ui = 1
let g:ycm_always_populate_location_list = 1
let g:ycm_server_log_level = 'info'
nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>
nnoremap <Leader>] :YcmCompleter GoTo<CR>
" YCM will auto-close the 'preview' window after the user leaves insert mode
let g:ycm_autoclose_preview_window_after_completion = 1
" *****************************************************************************
" Typescript
" *****************************************************************************
" Typescript settings
" Typescript specific key mapping
autocmd FileType typescript map <buffer> <Leader>t :YcmCompleter GoToType<CR>
autocmd FileType typescript map <buffer> <Leader>d :YcmCompleter GoToDefinition<CR>
autocmd FileType typescript map <buffer> <Leader>r :YcmCompleter GoToReferences<CR>
autocmd FileType typescript map <buffer> <Leader>i :TsuImport<CR>
" Typescript semantic code completion
if !exists("g:ycm_semantic_triggers")
let g:ycm_semantic_triggers = {}
endif
let g:ycm_semantic_triggers['typescript'] = ['.']
let g:tagbar_type_typescript = {
\ 'ctagstype': 'typescript',
\ 'kinds': [
\ 'c:classes',
\ 'n:modules',
\ 'f:functions',
\ 'v:variables',
\ 'v:varlambdas',
\ 'm:members',
\ 't:methods',
\ 'i:interfaces',
\ 'e:enums',
\ ]
\ }
" *****************************************************************************
" devdocs.vim plugin
" *****************************************************************************
" open doc under cursor
nmap K <Plug>(devdocs-under-cursor)
" to override K mapping in specific filetypes
"augroup plugin-devdocs
"autocmd!
"autocmd FileType c,cpp,rust,ruby,javascript,python nmap <buffer>K <Plug>(devdocs-under-cursor)
"augroup END
" *****************************************************************************
" Go Language
" *****************************************************************************
"
" set tab size 4 for Go files
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
" run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#cmd#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <leader>r <Plug>(go-run)
autocmd FileType go nmap <leader>t <Plug>(go-test)
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)
" Tell vim-go to use goimports when saving the file
let g:go_fmt_command = "goimports"
" Call MetaLinter whenever you save a file
let g:go_metalinter_autosave = 1
" Additional Highlighting
let g:go_highlight_types = 1
let g:go_highlight_fields = 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
" Navigation
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
" Tagbar Go using gotags
" https://github.com/jstemmer/gotags
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
" *****************************************************************************
" Rust
" *****************************************************************************
let g:racer_cmd = "$HOME/.cargo/bin/racer"
let $RUST_SRC_PATH="/usr/local/rust/rustc-1.10.0/src"
let g:ycm_rust_src_path = '/usr/local/rust/rustc-1.10.0/src'
" *****************************************************************************
" UltiSnips
" *****************************************************************************
let g:UltiSnipsSnippetDirectories = ['~/.vim/UltiSnips', 'UltiSnips']
let g:UltiSnipsExpandTrigger="<c-e>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
" *****************************************************************************
" ListToggle
" *****************************************************************************
let g:lt_location_list_toggle_map = '<leader>l'
let g:lt_quickfix_list_toggle_map = '<leader>q'
" *****************************************************************************
" Quickfix list buffer mapping
" *****************************************************************************
" Map nn and pp to go next/previous on quickfix buffer.
" Map . command to repeat (using vim-repeat)
nmap <silent> <Plug>NextQuickfixItem :cnext<CR>:call repeat#set("\<Plug>NextQuickfixItem")<CR>
nmap <silent> <Plug>PrevQuickfixItem :cprevious<CR>:call repeat#set("\<Plug>PrevQuickfixItem")<CR>
nmap <leader>n <Plug>NextQuickfixItem
nmap <leader>p <Plug>PrevQuickfixItem
" *****************************************************************************
" Vertical ident line
" *****************************************************************************
let g:indentLine_char = ''
" *****************************************************************************
" Disable arrow keys
" *****************************************************************************
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment