Skip to content

Instantly share code, notes, and snippets.

@zhuzhichao
Last active August 29, 2015 14:26
Show Gist options
  • Save zhuzhichao/0a2c368ac887c5a5f710 to your computer and use it in GitHub Desktop.
Save zhuzhichao/0a2c368ac887c5a5f710 to your computer and use it in GitHub Desktop.
VIM
"mapleader
let mapleader = ","
let g:mapleader = ","
"----
" Manage .vimrc
"----
"Fast reloading of the .vimrc
map <silent> <leader>ss :source ~/.vimrc<cr>
"Fast editing of .vimrc
map <silent> <leader>ee :e ~/.vimrc<cr>
"When .vimrc is edited, reload it
autocmd! bufwritepost .vimrc source ~/.vimrc
"----
" Vundle Plugin
"----
source ~/.vim/plugin.vim
" encoding dectection
set fileencoding=utf-8
set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1
" enable filetype dectection and ft specific plugin/indent
call vundle#end() " required
filetype plugin indent on " required
" enable syntax hightlight and completion
syntax on
"--------
" Vim user interface
"--------
" color scheme
"set background=dark
set background=light
colorscheme solarized
set guifont=PowerlineSymbols:h14
set linespace=11
let g:molokai_original = 0
set guioptions-=T " Removes top toolbar
set guioptions-=r " Removes right hand scroll bar
set go-=L " Removes left hand scroll bar
" For showmarks plugin
hi ShowMarksHLl ctermbg=Yellow ctermfg=Black guibg=#FFDB72 guifg=Black
hi ShowMarksHLu ctermbg=Magenta ctermfg=Black guibg=#FFB3FF guifg=Black
" highlight current line
"au WinLeave * set nocursorline nocursorcolumn
"au WinEnter * set cursorline cursorcolumn
set cursorline "cursorcolumn
" search
set incsearch
set ignorecase
set smartcase
" editor settings
set history=1000
set nocompatible
set nofoldenable " disable folding"
set confirm " prompt when existing from an unsaved file
set t_Co=256 " Explicitly tell vim that the terminal has 256 colors "
set mouse=a " use mouse in all modes
set report=0 " always report number of lines changed "
set nowrap " dont wrap lines
set scrolloff=5 " 5 lines above/below cursor when scrolling
set number " show line numbers
set showmatch " show matching bracket (briefly jump)
set showcmd " show typed command in status bar
set title " show file in titlebar
set laststatus=2 " use 2 lines for the status bar
set matchtime=2 " show matching bracket for 0.2 seconds
set matchpairs+=<:> " specially for html
" set clipboard=unnamed " yank and paste with the system clipboard
set hidden
set timeout timeoutlen=200 ttimeoutlen=100
set visualbell " don't beep
set noerrorbells " don't beep
set autowrite "Save on buffer switch
set mouse=a
set tags=tags
" Default Indentation
set autoindent
set smartindent " indent when
set tabstop=4 " tab width
set softtabstop=4 " backspace
"set shiftwidth=4 " indent width
"set expandtab " expand tab to space
set autoindent " always set autoindenting on
set copyindent " copy the previous indentation on autoindenting
set backspace=indent,eol,start " More powerful backspacing
autocmd FileType ruby setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=120
autocmd FileType php setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=120
autocmd FileType coffee,javascript setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=120
autocmd FileType python setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=120
autocmd FileType html,htmldjango,xhtml,haml,tpl setlocal tabstop=2 shiftwidth=2 softtabstop=2 textwidth=0
autocmd FileType sass,scss,css setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=120
" syntax support
"autocmd Syntax javascript set syntax=jquery " JQuery syntax support
"tpl support
au BufNewFile,BufRead *.tpl set ft=html
"au FileType javascript call JavaScriptFold()
" js
let g:html_indent_inctags = "html,body,head,tbody"
let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"
" highlight tabs and trailing spaces
"set list
"set listchars=tab:>-,trail:-,extends:>,precedes:<
"------
" keymap settings
"------
"nmap <D-/> :
imap <c-f> <Right>
imap <c-b> <Left>
imap <c-p> <Up>
imap <c-n> <Down>
nmap <leader>s :w!<cr>
" Down is really the next line
nnoremap j gj
nnoremap k gk
"Easy escaping to normal model
imap jj <esc>
"Auto change directory to match current file ,cd
nnoremap ,cd :cd %:p:h<CR>:pwd<CR>
"easier window navigation
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
"Resize vsplit
nmap <C-v> :vertical resize +5<cr>
nmap 25 :vertical resize 40<cr>
nmap 50 <c-w>=
nmap 75 :vertical resize 120<cr>
"Load the current buffer in Chrome
nmap ,c :!open -a Google\ Chrome<cr>
"Show (partial) command in the status line
set showcmd
" Create split below
"nmap :sp :rightbelow sp<cr>
" Quickly go forward or backward to buffer
"nmap :bp :BufSurfBack<cr>
"nmap :bn :BufSurfForward<cr>
highlight Search cterm=underline
" Swap files out of the project root
set backupdir=~/.vim/backup//
set directory=~/.vim/swap//
autocmd cursorhold * set nohlsearch
autocmd cursormoved * set hlsearch
" Remove search results
command! H let @/=""
" Abbreviations
abbrev gm !php artisan generate:model
abbrev gc !php artisan generate:controller
abbrev gmig !php artisan generate:migration
" Auto-remove trailing spaces
autocmd BufWritePre *.php :%s/\s\+$//e
" Edit todo list for project
nmap ,todo :e todo.txt<cr>
" Laravel framework commons
nmap <leader>lr :e app/routes.php<cr>
nmap <leader>lca :e app/config/app.php<cr>
nmap <leader>lcd :e app/config/database.php<cr>
nmap <leader>lc :e composer.json<cr>
" Concept - load underlying class for Laravel
function! FacadeLookup()
let facade = input('Facade Name: ')
let classes = {
'Form': 'Html/FormBuilder.php',
'Html': 'Html/HtmlBuilder.php',
'File': 'Filesystem/Filesystem.php',
'Eloquent': 'Database/Eloquent/Model.php'
}
execute ":edit vendor/laravel/framework/src/Illuminate/" . classes[facade]
endfunction
nmap ,lf :call FacadeLookup()<cr>
" Familiar commands for file/symbol browsing
map <C-r> :CtrlPBufTag<cr>
map <F13> :CtrlP<cr>
map <D-y> :redo<cr>
" I don't want to pull up these folders/files when calling CtrlP
set wildignore+=*/vendor/**
set wildignore+=*/public/forum/**
" Open splits
nmap vs :vsplit<cr>
nmap sp :split<cr>
" Create/edit file in the current directory
nmap :ed :edit %:p:h/
"-----------------
" Plugin settings
"-----------------
nnoremap <leader>a :CtrlSF
let g:agprg="/usr/local/bin/ag --column"
""" emmet
let g:user_emmet_leader_key='<C-Y>'
""" UltiSnipsEdit
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<S-Space>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
let g:snips_author="zhuzhichao"
"
"""IndentGuides
let g:indent_guides_enable_on_vim_startup = 0
"""airline
let g:airline#extensions#tabline#enabled = 1
let g:airline_theme='solarized'
let g:airline_powerline_fonts = 1
"""tabular
let g:tabular_loaded = 1
"""buffer
map <S-tab> :bp<cr>
map <tab> :bn<cr>
map <Leader>w :bd<cr>
map <Leader>f :tabnext<cr>
"""easymotion
" Gif config
map / <Plug>(easymotion-sn)
omap / <Plug>(easymotion-tn)
map n <Plug>(easymotion-next)
map N <Plug>(easymotion-prev)
" Gif config
" Require tpope/vim-repeat to enable dot repeat support
" Jump to anywhere with only `s{char}{target}`
" `s<CR>` repeat last find motion.
nmap s <Plug>(easymotion-s)
" Bidirectional & within line 't' motion
omap t <Plug>(easymotion-bd-tl)
" Use uppercase target labels and type as a lower case
let g:EasyMotion_use_upper = 1
" type `l` and match `l`&`L`
let g:EasyMotion_smartcase = 1
" Smartsign (type `3` and match `3`&`#`)
let g:EasyMotion_use_smartsign_us = 1
let g:EasyMotion_leader_key = '<Leader>'
""" youdao translate
vnoremap <silent> <C-T> <Esc>:Ydv<CR>
nnoremap <silent> <C-T> <Esc>:Ydc<CR>
noremap <leader>yd :Yde<CR>
"""gitgutter
nmap ]h <Plug>GitGutterNextHunk
nmap [h <Plug>GitGutterPrevHunk
"""syntastic
let g:syntastic_check_on_open=1
let g:syntastic_php_checkers = ['php', 'phpcs', 'phpmd']
"""phpcomplete-extended
"let g:phpcomplete_index_composer_command="composer"
""""" Nerd Tree
" 在 vim 启动的时候默认开启 NERDTree(autocmd 可以缩写为 au)
"autocmd VimEnter * NERDTree
let NERDChristmasTree=0
let NERDTreeWinSize=30
let NERDTreeChDirMode=2
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
" let NERDTreeSortOrder=['^__\.py$', '\/$', '*', '\.swp$', '\~$']
let NERDTreeShowBookmarks=1
let NERDTreeWinPos = "left"
" nerdcommenter
let NERDSpaceDelims=1
"nmap <D-/> :NERDComToggleComment<cr>
let NERDCompactSexyComs=1
""" SuperTab
let g:SuperTabDefaultCompletionType = "<c-x><c-o>"
let g:SuperTabRetainCompletionType=2
"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 = {}
endif
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 neocomplete#close_popup() . "\<CR>"
" For no inserting <CR> key.
"return pumvisible() ? neocomplete#close_popup() : "\<CR>"
endfunction
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" <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>"
inoremap <expr><C-y> neocomplete#close_popup()
inoremap <expr><C-e> neocomplete#cancel_popup()
" Close popup by <Space>.
"inoremap <expr><Space> pumvisible() ? neocomplete#close_popup() : "\<Space>"
" For cursor moving in insert mode(Not recommended)
"inoremap <expr><Left> neocomplete#close_popup() . "\<Left>"
"inoremap <expr><Right> neocomplete#close_popup() . "\<Right>"
"inoremap <expr><Up> neocomplete#close_popup() . "\<Up>"
"inoremap <expr><Down> neocomplete#close_popup() . "\<Down>"
" Or set this.
"let g:neocomplete#enable_cursor_hold_i = 1
" Or set this.
"let g:neocomplete#enable_insert_char_pre = 1
" 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
"autocmd FileType php setlocal omnifunc=phpcomplate#CompletePhp
" Enable heavy omni completion.
if !exists('g:neocomplete#sources#omni#input_patterns')
let g:neocomplete#sources#omni#input_patterns = {}
endif
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.
" https://github.com/c9s/perlomni.vim
let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'
" other keybindings for plugin toggle
map <c-r> :TagbarToggle<CR>
nmap <D-B> :NERDTreeToggle<cr>
nmap <c-m> :GundoToggle<cr>
nmap <c-t> :IndentGuidesToggle<cr>
"------------------
" Useful Functions
"------------------
"
" Turn persistent undo on
" means that you can undo even when you close a buffer/VIM
try
set undodir=~/.vim/temp_dirs/undodir
set undofile
catch
endtry
" Platform
function! MySys()
if has("win32")
return "windows"
else
return "linux"
endif
endfunction
function! SwitchToBuf(filename)
"let fullfn = substitute(a:filename, "^\\~/", $HOME . "/", "")
" find in current tab
let bufwinnr = bufwinnr(a:filename)
if bufwinnr != -1
exec bufwinnr . "wincmd w"
return
else
" find in each tab
tabfirst
let tab = 1
while tab <= tabpagenr("$")
let bufwinnr = bufwinnr(a:filename)
if bufwinnr != -1
exec "normal " . tab . "gt"
exec bufwinnr . "wincmd w"
return
endif
tabnext
let tab = tab + 1
endwhile
" not exist, new tab
exec "tabnew " . a:filename
endif
endfunction
"Fast edit vimrc
if MySys() == 'linux'
"Fast reloading of the .vimrc
map <silent> <leader>ss :source ~/.vimrc<cr>
"Fast editing of .vimrc
map <silent> <leader>ee :call SwitchToBuf("~/.vimrc")<cr>
"When .vimrc is edited, reload it
autocmd! bufwritepost .vimrc source ~/.vimrc
elseif MySys() == 'windows'
" Set helplang
set helplang=cn
"Fast reloading of the _vimrc
map <silent> <leader>ss :source ~/_vimrc<cr>
"Fast editing of _vimrc
map <silent> <leader>ee :call SwitchToBuf("~/_vimrc")<cr>
"When _vimrc is edited, reload it
autocmd! bufwritepost _vimrc source ~/_vimrc
endif
" For windows version
if MySys() == 'windows'
source $VIMRUNTIME/mswin.vim
behave mswin
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment