Skip to content

Instantly share code, notes, and snippets.

Created August 18, 2018 01:02
Show Gist options
  • Save ldong/53a8b9d8b5cfa87733836866a76b5b79 to your computer and use it in GitHub Desktop.
Save ldong/53a8b9d8b5cfa87733836866a76b5b79 to your computer and use it in GitHub Desktop.
2018 Vimrc
" ==============================================================================
" Author: Alan Dong
" Version: 0.3.5
" Last Modified Date: 8/17/2018
" Description: My Vim Configuration file
" ==============================================================================
" set shell for bash as default
set shell=/bin/bash
" leader
let mapleader = ','
let g:mapleader = ','
" syntax
syntax on
" manually load syntax highlighter
":set syn=syntax-type
"i.e. :set syn=python
" history : how many lines of history VIM has to remember
set history=10000
" filetype
filetype on
" Enable filetype plugins
filetype plugin on
filetype indent on
" base
set nocompatible " don't bother with vi compatibility
set autoread " reload files when changed on disk, i.e. via `git checkout`
set shortmess=atI
set magic " For regular expressions turn magic on
set title " change the terminal's title
set nobackup " do not keep a backup file
set novisualbell " turn off visual bell
set noerrorbells " don't beep
set visualbell t_vb= " turn off error beep/flash
set t_vb=
set tm=500
" always show report messages
set report=0
" show location
set cursorcolumn
set cursorline
" movement
set scrolloff=7 " keep 3 lines when scrolling
nnoremap k gk
nnoremap gk k
nnoremap j gj
nnoremap gj j
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
cnoremap <C-j> <t_kd>
cnoremap <C-k> <t_ku>
" show
set ruler " show the current row and column
set number " show line numbers
set nowrap
set showcmd " display incomplete commands
set showmode " display current modes
set showmatch " jump to matches when entering parentheses
set matchtime=2 " tenths of a second to show the matching parenthesis
" search
set hlsearch " highlight searches
set incsearch " do incremental searching, search as you type
set smartcase " no ignorecase if Uppercase char present
"set ignorecase " ignore case when searching"
" cancel highlight search
noremap <silent><leader>/ :nohls<CR>
noremap <leade<leader>>hl :set hlsearch! hlsearch?<CR>
" tab
set expandtab " expand tabs to spaces
set smarttab
set shiftround
" indent
set autoindent
set smartindent
set shiftwidth=2
set tabstop=2
set softtabstop=2 " insert mode tab and backspace use 2 spaces
vnoremap < <gv
vnoremap > >gv
" set foldenable
" set foldmethod=indent
" set foldlevel=99
" encoding
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set termencoding=utf-8
set ffs=unix,dos,mac
set formatoptions+=m
" spell check
set spell
set spelllang=en_us
set formatoptions+=B
" select & complete
set selection=inclusive
set selectmode=mouse,key
set completeopt=longest,menu
set wildmenu " show a navigable menu for tab completion"
set wildmode=longest,list,full
set wildignore=*.o,*~,*.pyc,*.class
" if this not work ,make sure .viminfo is writable for you
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" Enable basic mouse behavior such as resizing buffers.
" set mouse=a
hi! link SignColumn LineNr
hi! link ShowMarksHLl DiffAdd
hi! link ShowMarksHLu DiffChange
" status line
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P
set laststatus=2 " Always show the status line - use 2 lines for the status bar
" specific language
augroup myfiletypes
" Clear old autocmds in group
autocmd BufNewFile *.sh,*.py exec ":call AutoSetFileHead()"
autocmd FileType c,python set tabstop=4 shiftwidth=4 expandtab ai
autocmd FileType ruby,eruby,yaml,makrdown set tabstop=2 shiftwidth=2 softtabstop=2 expandtab ai
autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl autocmd BufWritePre <buffer> :call <SID>StripTrailingWhitespaces()
autocmd FileType javascript,js,html set tabstop=2 shiftwidth=2 softtabstop=2 expandtab ai
autocmd BufRead,BufNewFile *.es6 setfiletype javascript
autocmd BufRead,BufNewFile *.js setfiletype javascript
" autocmd BufNewFile,BufRead *.jsx set filetype=javascript.jsx
autocmd FileType javascript setlocal omnifunc=tern#Complete
autocmd FileType javascript.jsx setlocal omnifunc=tern#Complete
" Folding for css
" autocmd BufRead,BufNewFile *.css,*.scss,*.less setlocal foldmethod=marker foldmarker={,}
" autocmd BufNewFile,BufRead *.xml,*.htm,*.html so XMLFolding
" Customized for zmanage to use 4 space indentation
let currDir = getcwd()
let targetSourcePath ="zmanage/web/js"
" let g:z = 1
" using echom g:z
if currDir =~ targetSourcePath
autocmd FileType javascript,js,html,handlebars,hbs set tabstop=4 shiftwidth=4 softtabstop=4 expandtab ai
augroup END
function! AutoSetFileHead()
" .sh
if &filetype == 'sh'
call setline(1, "\#!/bin/bash")
" python
if &filetype == 'python'
call setline(1, "\#!/usr/bin/env python")
call append(1, "\# encoding: utf-8")
normal G
normal o
normal o
" others
set backspace=indent,eol,start " make that backspace key work the way it should
set whichwrap+=<,>,h,l
" suppress python3 warnings
if has('python3')
silent! python3 1
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee >/dev/null %
" F5 paste toggle
set pastetoggle=<F5>
au InsertLeave * set nopaste
" :r! cat and then paste ( shift + insert ) the content, and CTRL+D.
fun! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
call cursor(l, c)
" no ex mode
nnoremap Q <nop>
" remap vim
command! WQ wq
command! Wq wq
command! W w
command! Q q
command! Q1 q!
" Q map to q, to quit vim
command! -bar -bang Q quit<bang>
" update vim on the fly
nmap <leader>v :tabedit $MYVIMRC<CR>
nmap <leader>V :tabedit $MYVIMRC<CR>
autocmd! bufwritepost _vimrc source % " vimrc文件修改之后自动加载。 windows。
autocmd! bufwritepost .vimrc source % " vimrc文件修改之后自动加载。 linux。
" insert date in the following format
iab <expr> dd strftime("%a %b %_d %H:%M:%S %Z %Y")
" resize
nnoremap <leader><left> :vertical resize -5<cr>
nnoremap <leader><down> :resize +5<cr>
nnoremap <leader><up> :resize -5<cr>
nnoremap <leader><right> :vertical resize +5<cr>
" Wrap text
command! -nargs=* Wrap set wrap linebreak nolist
" Set spell check
command! -nargs=* Spell set spell!
" Make <leader>' switch between ' and "
nnoremap <leader>' ""yls<c-r>={'"': "'", "'": '"'}[@"]<cr><esc>
" map <silent> <leader>y :<C-u>silent '<,'>w !pbcopy<CR>
" avoid and recover from accidental Ctrl-U
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
inoremap <silent> <C-W> <C-\><C-O>db
inoremap <silent> <C-U> <C-\><C-O>d0
inoremap <silent> <C-Y> <C-R>"
" ==============================================================================
" Vundle
" ==============================================================================
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" Essentials
Plugin 'gmarik/Vundle.vim'
Plugin 'L9'
Plugin 'vim-ruby/vim-ruby'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-ragtag'
Plugin 'juneedahamed/svnj.vim'
" Airline
Plugin 'bling/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
" Make Vim play nicely
Plugin 'sjl/vitality.vim'
Plugin 'guns/vim-sexp.git'
Plugin 'tpope/vim-sensible'
Plugin 'tpope/vim-speeddating'
Plugin 'tpope/vim-abolish'
Plugin 'tpope/vim-unimpaired'
Plugin 'tpope/vim-eunuch'
Plugin 'tpope/vim-sexp-mappings-for-regular-people'
" File explorer
Plugin 'scrooloose/nerdtree'
Plugin 'ivalkeen/nerdtree-execute'
" Errors, open error list
" lclose, location close
Plugin 'scrooloose/syntastic'
" Async Linter" As
" Plugin 'w0rp/ale'
" show corresponding file
Plugin 'vim-scripts/a.vim'
" syntax highlight
Plugin 'othree/html5.vim'
" Plugin 'othree/vim-coffee-script'
" Plugin 'lukaszkorecki/CoffeeTags'
Plugin 'mustache/vim-mustache-handlebars'
Plugin 'othree/javascript-libraries-syntax.vim'
Plugin 'cakebaker/scss-syntax.vim'
Plugin 'groenewege/vim-less'
" Plugin 'briancollins/vim-jst'
Plugin 'autowitch/hive.vim'
Plugin 'motus/pig.vim'
" ES6 ES2015
Plugin 'othree/yajs.vim'
Plugin 'isRuslan/vim-es6'
" JSX, deprecated
Plugin 'mxw/vim-jsx'
" json
Plugin 'elzr/vim-json'
" TODO list
Plugin 'vim-scripts/TaskList.vim'
" Markdown
Plugin 'plasticboy/vim-markdown'
" Plugin 'mzlogin/vim-markdown-toc'
"python highlight
" Plugin 'hdima/python-syntax'
" Plugin 'derekwyatt/vim-scala'
Plugin 'Konfekt/FastFold'
" JavaScript
Plugin 'vim-scripts/SyntaxComplete'
Plugin 'pangloss/vim-javascript'
" Plugin 'jelera/vim-javascript-syntax'
" Plugin 'burnettk/vim-angular'
" Plugin 'mattn/jscomplete-vim'
Plugin 'marijnh/tern_for_vim'
" JS beautifier, formatting javascript
" require nodejs and npm -g install js-beautify
" Plugin 'einars/js-beautify'
" Plugin 'maksimr/vim-jsbeautify'
" auto format
"Plugin 'Chiel92/vim-autoformat'
" auto complete
" Plugin 'ervandew/supertab'
" Plugin 'Shougo/neocomplcache.vim'
Plugin 'Shougo/neocomplete.vim'
" Plugin 'othree/vim-autocomplpop'
" Plugin 'valloric/YouCompleteMe'
" Plugin 'ldong/vim_youcompleteme'
" Unite, CtrlP
Plugin 'Shougo/vimproc.vim'
Plugin 'Shougo/unite.vim'
Plugin 'yegappan/mru'
" eol
Plugin 'vim-scripts/PreserveNoEOL'
" regex ,/ toggle
Plugin 'othree/eregex.vim'
" remove trailing whitespace by :FixWhitespace
Plugin 'bronson/vim-trailing-whitespace'
" comments
Plugin 'tomtom/tcomment_vim'
" ctags
Plugin 'majutsushi/tagbar'
Plugin 'ramitos/jsctags'
Plugin 'xolox/vim-misc'
Plugin 'xolox/vim-easytags'
" Align
Plugin 'godlygeek/tabular'
" Pairs
Plugin 'vim-scripts/'
Plugin 'jiangmiao/auto-pairs'
" parentheses
Plugin 'kien/rainbow_parentheses.vim'
" Gundo vim undo tree
Plugin 'sjl/gundo.vim'
" Jumps ctrl-i ctrl-o zp zP gf
Plugin 'justinmk/vim-sneak'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'tommcdo/vim-kangaroo'
" mark
Plugin 'kshenoy/vim-signature'
" Calendar plugin
Plugin 'mattn/calendar-vim'
" Zen coding
Plugin 'mattn/emmet-vim'
" CSS coloring
Plugin 'gorodinskiy/vim-coloresque'
Plugin 'guns/xterm-color-table.vim'
" auto save, auto-save
Plugin '907th/vim-auto-save'
" Track the engine.
Plugin 'SirVer/ultisnips'
" Alternative
" Plugin 'garbas/vim-snipmate'
" Snippets are separated from the engine. Add this if you want them:
Plugin 'honza/vim-snippets'
" previewing markdown in browser <Leader>P
Plugin 'greyblake/vim-preview'
" Goyo, distraction free
" Plugin 'junegunn/goyo.vim'
" Plugin 'junegunn/limelight.vim'
" Scratch, :Scratch :Sscratch
Plugin 'duff/vim-scratch'
" multiple cursor, Ctrl-p for prev, Ctrl-n for next, Ctrl-x to skip
Plugin 'terryma/vim-multiple-cursors'
" select regions, Press + to expand the visual selection and _ to shrink it.
Plugin 'terryma/vim-expand-region'
" increment
" Plugin 'vim-scripts/BlockWork'
" Plugin 'qwertologe/nextval.vim'
Plugin 'vim-scripts/VisIncr'
" \as to activate autonumbering
" Plugin 'vim-scripts/autonumbering-in-vim'
"Insert line numbers:
" draw it
" <leader>di to start DrawIt and
" <leader>ds to stop DrawIt.
" uses keboard it overwrites ,v
" Plugin 'vim-scripts/DrawIt'
Plugin 'vim-scripts/sketch.vim' " uses mouse
" Window management
Plugin 'wesQ3/vim-windowswap'
" Latex
" Plugin 'LaTeX-Box-Team/LaTeX-Box'
" Auto detect CJK and Unicode file encodings
Plugin 'mbbill/fencview'
" rst
" Plugin 'rykka/os.vim'
" Plugin 'Rykka/clickable.vim'
" Plugin 'Rykka/clickable-things'
" Plugin 'Rykka/riv.vim'
" Plugin 'nvie/vim-rst-tables'
" Gist
Plugin 'mattn/webapi-vim'
Plugin 'mattn/gist-vim'
" Intent Guides
Plugin 'nathanaelkane/vim-indent-guides'
" colorscheme
Plugin 'altercation/vim-colors-solarized'
Plugin 'sickill/vim-monokai'
Plugin 'tomasr/molokai'
Plugin 'nanotech/jellybeans.vim'
Plugin 'benjaminwhite/Benokai'
Plugin 'romainl/flattened'
" Mini Buffer
" Plugin 'techlivezheng/vim-plugin-minibufexpl'
" using vim as slides
" Plugin 'ingydotnet/vroom-pm'
" split vim into two pane
" Plugin 'vim-voom/VOoM'
" Plugin 'vim-voom/VOoM_extras'
" Split and Join
Plugin 'AndrewRadev/splitjoin.vim'
" ldong
Plugin 'ldong/vim_bclose'
Plugin 'ldong/vim_autohighlight'
Plugin 'ldong/vim_copy_paste'
Plugin 'ldong/vim-listify'
Plugin 'ldong/file-line'
" Games
" Plugin 'ldong/battleship'
" <Leader>te
" Game tetris
" Plugin 'vim-scripts/TeTrIs.vim'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" install Vundle bundles
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
" ==============================================================================
" NeoComplete
" ==============================================================================
"Note: This option must set it in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)!
" Disable AutoComplPop.
let g:acp_enableAtStartup = 0
" Use neocomplete.
let g:neocomplete#enable_at_startup = 1
" Use smartcase.
let g:neocomplete#enable_smart_case = 1
" Set minimum syntax keyword length.
let g:neocomplete#sources#syntax#min_keyword_length = 3
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
" Define dictionary.
let g:neocomplete#sources#dictionary#dictionaries = {
\ 'default' : '',
\ 'vimshell' : $HOME.'/.vimshell_hist',
\ 'scheme' : $HOME.'/.gosh_completions'
\ }
" Define keyword.
if !exists('g:neocomplete#keyword_patterns')
let g:neocomplete#keyword_patterns = {}
let g:neocomplete#keyword_patterns['default'] = '\h\w*'
" Plugin key-mappings.
inoremap <expr><C-g> neocomplete#undo_completion()
inoremap <expr><C-l> neocomplete#complete_common_string()
" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
function! s:my_cr_function()
return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
" For no inserting <CR> key.
"return pumvisible() ? "\<C-y>" : "\<CR>"
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ neocomplete#start_manual_complete()
function! s:check_back_space() "{{{
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
inoremap <expr><Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr><Up> pumvisible() ? "\<C-p>" : "\<Up>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? "\<C-y>" : "\<Space>"
" AutoComplPop like behavior.
"let g:neocomplete#enable_auto_select = 1
" Shell like behavior(not recommended).
"set completeopt+=longest
"let g:neocomplete#enable_auto_select = 1
"let g:neocomplete#disable_auto_complete = 1
"inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<C-x>\<C-u>"
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
let g:neocomplete#sources#omni#input_patterns = {}
"let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
"let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)'
"let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::'
" For perlomni.vim setting.
let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
" ==============================================================================
" Plugins Configuration
" ==============================================================================
" ,nt to open nerdTree
let NERDTreeIgnore=['\~$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr']
" <leader><leader>r rename
nmap <silent> <leader>nt :NERDTreeToggle<CR>
" ,tb to open tagbar
nmap <silent> <leader>tb :TagbarToggle<CR>
" Ctags, check the parent directories for tags, too.
set tags=./.tags;,./tags
let g:easytags_dynamic_files = 1
let g:easytags_file = '~/.vim/tags'
let g:easytags_updatetime_min=12000
let g:easytags_async = 1
" ctags
let g:tagbar_type_javascript = {
\ 'ctagsbin' : '/usr/local/bin/jsctags'
\ }
" fix whitespace
command! F FixWhitespace
" redfine emmet shortcut: ,e,
let g:user_emmet_install_global = 1
let g:user_emmet_leader_key = '<leader>e'
" let g:user_emmet_install_global = 0
" autocmd FileType html,css,eruby,markdown,handlebars,hbs,php EmmetInstall
" Gundo toggle
nnoremap <leader>h :GundoToggle<CR>
" MiniBufExplorer
" let g:miniBufExplCycleArround = 1
" map <Leader>b :MBEToggle<cr>
" map <Leader>p :MBEbn<cr>
" map <leader>P :MBEbp<cr>
" change from tabs
" nnoremap <C-Tab> :tabn<CR>
" nnoremap <C-S-Tab> :tabp<CR>
" change from buffers
" nnoremap <C-Tab> :bn<CR>
" nnoremap <C-S-Tab> :bp<CR>
" Airline
if !exists('g:airline_symbols')
let g:airline_symbols = {}
" use powerline font if installed
" let g:airline_powerline_fonts = 1
" let g:airline#extensions#tabline#enabled = 1
let g:airline_theme = 'powerlineish'
let g:airline#extensions#branch#enable = 1
let g:airline#extensions#syntastic#enabled = 1
let g:airline#extensions#bufferline#enabled= 1
" vim-powerline symbols
let g:airline_left_sep = '▶'
let g:airline_left_alt_sep = '»'
let g:airline_right_sep = '◀'
let g:airline_right_alt_sep = '«'
let g:airline_symbols.branch = '⤴' "➔, ➥, ⎇
let g:airline_symbols.readonly = '⊘'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.whitespace = 'Ξ'
let g:airline_section_b = '%{getcwd()}'
" vim-session autosave
let g:auto_save = 1
let g:auto_save_in_insert_mode = 0
let g:session_autoload = 'no'
let g:session_autosave = 'yes'
let g:session_autosave_periodic = 3
" auto save
autocmd BufLeave,CursorHold,CursorHoldI,FocusLost * silent! wa
" enable indent guides
nmap <silent> <Leader>ig <Plug>IndentGuidesToggle
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=3
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=4
hi IndentGuidesOdd ctermbg=black
hi IndentGuidesEven ctermbg=darkgrey
" eregex regex
let g:eregex_default_enable = 0
nnoremap <leader>r :call eregex#toggle()<CR>
" => UltiSnips
let g:UltiSnipsExpandTrigger="k"
let g:UltiSnipsExpandTrigger="<c-e>"
let g:UltiSnipsListSnippets="<c-l>"
" enable always save with eol at the end of file
let b:PreserveNoEOL = 1
" easy motion
" leader leader w
" leader leader gE
" leader leader t
" => Unite
" <C-x> <C-v> open file in horizontal and vertical split
" <C-t> open file in new tab
" <esc> exit unite window
" <C-j> <C-k> Navigation, keep hands on home row
nnoremap <C-p> :Unite file_rec/async<cr>
nnoremap <Leader>b :Unite buffer<cr>
nnoremap <space>/ :Unite grep:.<cr>
let g:unite_source_history_yank_enable = 1
nnoremap <space>y :Unite history/yank<cr>
nnoremap <space>s :Unite -quick-match buffer<cr>
nnoremap <C-P> :<C-u>Unite -buffer-name=files -start-insert buffer file_rec/async:!<cr>
autocmd FileType unite call s:unite_settings()
function! s:unite_settings()
let b:SuperTabDisabled = 1
imap <buffer> <C-j> <Plug>(unite_select_next_line)
imap <buffer> <C-k> <Plug>(unite_select_previous_line)
imap <silent><buffer><expr> <C-x> unite#do_action('split')
imap <silent><buffer><expr> <C-v> unite#do_action('vsplit')
imap <silent><buffer><expr> <C-t> unite#do_action('tabopen')
nmap <buffer> <ESC> <Plug>(unite_exit)
let g:SuperTabCrMapping = 0
let g:unite_enable_start_insert = 1
let g:unite_split_rule = "botright"
let g:unite_force_overwrite_statusline = 0
let g:unite_source_rec_max_cache_files = 0
let g:ctrlp_max_files = 0
let g:CommandTMaxFiles = 200000
let g:CommandTFileScanner = 'find'
let g:unite_winheight = 10
call unite#filters#sorter_default#use(['sorter_rank'])
call unite#filters#matcher_default#use(['matcher_fuzzy'])
call unite#custom_source('file_rec/async,file_mru,file,buffer,grep',
\ 'ignore_pattern', join([
\ '\.git/',
\ '\.svn/',
\ 'node_modules/',
\ ], '\|'))
call unite#custom_source('file_rec/async', 'converters', [])
call unite#custom_source('file_rec/async', 'sorters', ['sorter_length'])
call unite#custom_source('file_rec/async', 'max_candidates', 1000)
call unite#custom_source('file_rec/async,file_rec/git', 'ignore_globs', [])
call unite#custom#profile('files', 'filters', 'sorter_rank')
if executable('ag')
let g:unite_source_grep_command = 'ag'
let g:unite_source_grep_default_opts = '--nocolor --nogroup -S -C4'
let g:unite_source_grep_recursive_opt = ''
elseif executable('ack-grep')
let g:unite_source_grep_command = 'ack-grep'
let g:unite_source_grep_default_opts = '--no-heading --no-color -a -H'
"let g:unite_source_grep_default_opts = '--no-heading --no-color -a -w'
let g:unite_source_grep_default_opts .= '--exclude ''\.(git|svn|hg|bzr)'''
let g:unite_source_grep_recursive_opt = ''
elseif executable('ack')
let g:unite_source_grep_command = 'ack'
let g:unite_source_grep_default_opts = '--no-heading --no-color -C4'
let g:unite_source_grep_recursive_opt = ''
" Appropriately close the buffer without closing the window
cnoremap <expr> bd (getcmdtype() == ':' ? 'Bclose' : 'bd')
" => Syntastic
" Update Error List, enable lnext, lprev to go back and forth
let g:syntastic_always_populate_loc_list = 1
" :SyntasticInfo
let g:syntastic_java_javac_config_file_enabled = 1
" let g:syntastic_python_checkers = ['pylint', 'flake8', 'python']
let g:syntastic_python_checkers = ['pylint', 'python']
let g:syntastic_python_pylint_args='--ignore=E501'
" let g:syntastic_python_pylint_args='--ignore=W0511,C0321'
" general
"let g:syntastic_check_on_open = 1
"let g:syntastic_quiet_warnings = 0
"let g:syntastic_enable_signs = 1
"let g:syntastic_enable_highlighting = 0
"let g:syntastic_python_checker_args='--ignore=E501,E302,E231,E261,E201,W402,W293'
" highlight python
" let python_highlight_all = 1
" javascript style guide lint checker
let g:syntastic_javascript_checkers = ['eslint']
" let g:syntastic_javascript_checkers = ['jsxhint', 'jscs']
" let g:syntastic_javascript_checkers = []
" let g:syntastic_scss_checkers = ['scss_lint']
let g:syntastic_scss_checkers = []
" Preview latex after compliation
" " \ll compile; \lv view
" let g:LatexBox_viewer = "open /Applications/"
" vim_json settings
let g:vim_json_syntax_conceal = 0
" let g:vim_json_warnings=1
" fugitive shortcuts
noremap \gs :Gstatus<cr>
noremap \gc :Gcommit<cr>
noremap \ga :Gwrite<cr>
noremap \gl :Glog<cr>
noremap \gd :Gdiff<cr>
noremap \gb :Gblame<cr>
"surrounding, shortcuts: ds, cs, yss
nmap <Leader>as ysiw
nmap <Leader>ds ds
" Tabularize
nmap <Leader>a& :Tabularize /&<CR>
vmap <Leader>a& :Tabularize /&<CR>
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:<CR>
vmap <Leader>a: :Tabularize /:<CR>
nmap <Leader>a:: :Tabularize /:\zs<CR>
vmap <Leader>a:: :Tabularize /:\zs<CR>
nmap <Leader>a, :Tabularize /,<CR>
vmap <Leader>a, :Tabularize /,<CR>
nmap <Leader>a,, :Tabularize /,\zs<CR>
vmap <Leader>a,, :Tabularize /,\zs<CR>
nmap <Leader>a<Bar> :Tabularize /<Bar><CR>
vmap <Leader>a<Bar> :Tabularize /<Bar><CR>
" draw ascii using mouse
" map <leader>d :call ToggleSketch()<CR>
" define Goyo shortcut
" nnoremap <Leader>G :Goyo<CR>
let MRU_Max_Entries = 20
let MRU_Exclude_Files = '^/tmp/.*\|^/var/tmp/.*'
let MRU_Window_Height = 5
let MRU_Auto_Close = 1
" SVN Cache location is $HOME/.cache
let g:svnj_browse_cache_all = 1
" Customized Abbreviation
abbr rq require("");<esc>2
" Java Abbreviation
abbr psvm public static void main(String[] args){<CR>}<esc>O
abbr sysout System.out.println("");<esc>2hi
abbr syserr System.err.println("");<esc>2hi
abbr fori for (int i = 0; i < ; i++) {<esc>7hi
abbr tryb try {<CR>} catch (Exception ex) {<CR> ex.printStackTrace();<CR>}<esc>hx3ko
abbr ctm System.currentTimeMillis()
" Vim preview markdown
autocmd BufNewFile,BufRead \*.{md,mdwn,mkd,mkdn,mark\*} set filetype=markdown
" ,hp = html preview
map <silent> <leader>hp :!open -a Safari %<CR><CR>
" windowswap
"1. Navigate to the window you'd like to move
"2. Press <leader>ww
"3. Navigate to the window you'd like to swap with
"4. Press <leader>ww again
" ==============================================================================
" Mappings
" ==============================================================================
" Use single quote as additional range key
noremap ' `
" Rerun previous :command
noremap \' @:
" Underline a line with hyphens (<h2> in Markdown documents)
noremap \- yypVr-
" Underline a line with equals (<h1> in Markdown documents)
noremap \= yypVr=
" Remove white space turds from the ends of lines
noremap \W :FixWhitespace<cr>
noremap \bd :1,999bd<cr>:NERDTree<cr>:NERDTree<cr>
" cd current window to parent directory of file
noremap \cd :lcd %:h<cr>:pwd<cr>
" Copy path of current file to clipboard
noremap \cf :let @+ = expand("%")<cr>
" Copy full path of current file to clipboard
noremap \cp :let @+ = expand("%:p")<cr>
" copy current filename into system clipboard - mnemonic: (c)urrent(f)ilename
" this is helpful to paste someone the path you're looking at
nnoremap <silent> ,cf :let @* = expand("%:~")<CR>
nnoremap <silent> ,cr :let @* = expand("%")<CR>
nnoremap <silent> ,cn :let @* = expand("%:t")<CR>" Generate ctags and cscope
"(v)im (c)ommand - execute current line as a vim command
nmap <silent> <leader>vc yy:<C-f>p<C-c><CR>
"(v)im (r)eload
nmap <silent> <leader>vr :so %<CR>
" Generate ctags and cscope
" "ctags -R
" "cscope -Rbq
noremap \ct :!ctags -R .<cr><cr>
" Sort selection
noremap \s :sort<cr>
" selec the whole line
noremap \v ^v$
" selec the whole line without leading space
noremap \vv 0v$
" Put contents of parentheses on their own newline and reindent (must position
" cursor inside parentheses in normal mode first).
nmap \( ci(<cr><esc>Pa<cr><esc>Vkk=
" Break a comma-delimited list onto new lines
vmap \, :s/,/,\r/g<cr>)
" copy filename and filepath
nmap <leader>cn :let @*=expand("%")<CR>
nmap <leader>cp :let @*=expand("%:p")<CR>
" Error List
noremap <leader>ln :lnext<cr>
noremap <leader>lp :lprev<cr>
" redent
map <leader>= :delmarks z<CR>mzgg=G`zmzk<CR>
" reverse lines
" :g/^/m0
" :100,150g/^/m99
" :%!tac
" :100,150!tac
" Reverse selection
" \rh: mirror image the lines (reverse horizontally)
vnoremap ;rh c<C-O>:set revins<CR><C-R>"<Esc>:set norevins<CR>
" \rv: reverse the order of lines (reverse vertically)
nmap ;rv :set lz<CR>o<Esc>mz'aO<Esc>ma:'a+1,'z-1g/^/m 'a<CR>'addma'zdd:set nolz<CR>
" replace current word select
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/
" pretty print json
nnoremap <leader>J :%!python -m json.tool<CR>
" tidy html
nnoremap <leader>T :%!tidy -qicbn -asxhtml<CR>
" Use numbers to pick the tab you want (like iTerm)
map <silent> <D-1> :tabn 1<cr>
map <silent> <D-2> :tabn 2<cr>
map <silent> <D-3> :tabn 3<cr>
map <silent> <D-4> :tabn 4<cr>
map <silent> <D-5> :tabn 5<cr>
map <silent> <D-6> :tabn 6<cr>
map <silent> <D-7> :tabn 7<cr>
map <silent> <D-8> :tabn 8<cr>
map <silent> <D-9> :tabn 9<cr>
" config backup directory
set backup
set backupdir=~/.vimswap
set backupskip=~/.vimswap/*
set directory=~/.vimswap
set writebackup
" config swap file
set swapfile
set dir=~/.vimswap
" count occurrence of WORD
" %s/pattern-here//gn
" ==============================================================================
" Color Theme
" ==============================================================================
try " Solarized
if has('gui_running')
colorscheme solarized
let g:solarized_termcolors= 256
let g:solarized_termtrans = 0
let g:solarized_degrade = 0
let g:solarized_bold = 1
let g:solarized_underline = 1
let g:solarized_italic = 1
let g:solarized_visibility= "normal"
let g:solarized_contrast = "low"
" set background=light
set guifont=Menlo:h15
set transparency=3
set background=dark
" set t_Co=256
" let g:solarized_termcolors = 256
let g:solarized_termcolors = 16
let g:solarized_visibility = "high"
let g:solarized_contrast = "high"
colorscheme solarized
set background=dark
catch /^Vim\%((\a\+)\)\=:E185/
let g:molokai_original = 1
let g:rehash256 = 1
set background=dark
for scheme in [ 'molokai', 'monokai', 'Benokai' 'desert' ]
execute 'colorscheme '.scheme
" let g:jellybeans_use_lowcolor_black = 0
" colorscheme jellybeans
hi clear SpellBad
hi SpellBad cterm=undercurl,bold
" hi SpellBad cterm=undercurl,bold ctermfg=blue
" set highlight color after 80 regardless of the version of VIM
if exists('+colorcolumn')
" let &colorcolumn="80,".join(range(120,999),",")
let &colorcolumn="80"
highlight ColorColumn ctermbg=9 guibg=#df0000
" fallback for Vim < v7.3
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
" Vim Cheat Sheets
" Folding commands
" fold: zf, zo, zc, za
" zf#j creates a fold from the cursor down # lines.
" zf/string creates a fold from the cursor to string .
" zj moves the cursor to the next fold.
" zk moves the cursor to the previous fold.
" zo opens a fold at the cursor.
" zc closes a fold at the cursor.
" zO opens all folds at the cursor.
" zm increases the foldlevel by one.
" zM closes all open folds.
" zr decreases the foldlevel by one.
" zR decreases the foldlevel to zero -- all folds will be open.
" zd deletes the fold at the cursor.
" zE deletes all folds.
" [z move to start of open fold.
" ]z move to end of open fold.
" fold folding,
" set foldcolumn=3
" set foldmethod=syntax
" set foldlevelstart=3
" let javaScript_fold=1 " JavaScript
" let perl_fold=1 " Perl
" let php_folding=1 " PHP
" let r_syntax_folding=1 " R
" let ruby_fold=1 " Ruby
" let sh_fold_enabled=1 " sh
" let vimsyn_folding='af' " Vim script
" let xml_syntax_folding=1 " XML
" for .hql files
au BufNewFile,BufRead *.hql set filetype=hive expandtab
" for .q files
au BufNewFile,BufRead *.q set filetype=hive expandtab
" ================ Completion =======================
set wildmode=list:longest
set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
set wildignore+=*vim/backups*
set wildignore+=*sass-cache*
set wildignore+=*DS_Store*
set wildignore+=vendor/rails/**
set wildignore+=vendor/cache/**
set wildignore+=*.gem
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=*.png,*.jpg,*.gif
"Go to last edit location with ,.
nnoremap ,. '.
"Move back and forth through previous and next buffers
"with ,z and ,x
nnoremap <silent> ,z :bp<CR>
nnoremap <silent> ,x :bn<CR>
" Create window splits easier. The default
" way is Ctrl-w,v and Ctrl-w,s. I remap
" this to vv and ss
nnoremap <silent> vv <C-w>v
nnoremap <silent> ss <C-w>s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment