Skip to content

Instantly share code, notes, and snippets.

@tangrui
Created June 29, 2013 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangrui/5889749 to your computer and use it in GitHub Desktop.
Save tangrui/5889749 to your computer and use it in GitHub Desktop.
My Vim config file.
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
if has("win32")
set runtimepath^=$HOME/.vim
endif
" #################### functions ####################
set diffexpr=MyDiff()
function! MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
let eq = ''
if $VIMRUNTIME =~ ' '
if &sh =~ '\<cmd'
let cmd = '""' . $VIMRUNTIME . '\diff"'
let eq = '"'
else
let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
endif
else
let cmd = $VIMRUNTIME . '\diff'
endif
silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
function! ToggleVerbose()
if !&verbose
set verbosefile=$HOME/.vim/vim.log
set verbose=15
else
set verbose=0
set verbosefile=
endif
endfunction
map <leader>verbose :call ToggleVerbose()<CR>
function! ToggleTags()
if !&tags
set tags=$HOME/.vim/tags
else
set tags=
endif
endfunction
function! QfMakeConv()
let qflist = getqflist()
for i in qflist
let i.text = iconv(i.text, "cp936", "utf-8")
endfor
call setqflist(qflist)
endfunction
function! ToggleScratch()
if expand('%') == g:ScratchBufferName
quit
else
Sscratch
endif
endfunction
map <F12> :call ToggleScratch()<CR>
function LessCompile()
let current_file = shellescape(expand('%:p'))
let filename = shellescape(expand('%:r'))
let command = "silent !lessc " . current_file . " " . filename . ".css"
execute command
endfunction
" autocmd BufWritePost,FileWritePost *.less call LessCompile()
" #################### functions ####################
" #################### vundle plugin config ####################
filetype off
set runtimepath+=$HOME/.vim/bundle/vundle
set directory=.,$HOME/.temp
call vundle#rc()
let g:vundle_default_git_proto = 'git'
Bundle 'https://github.com/gmarik/vundle'
Bundle 'https://github.com/tpope/vim-sensible.git'
Bundle 'https://github.com/MarcWeber/vim-addon-mw-utils'
Bundle 'https://github.com/tomtom/tlib_vim'
Bundle 'https://github.com/vim-scripts/genutils.git'
" Syntax
Bundle 'https://github.com/vim-scripts/groovyindent.git'
Bundle 'https://github.com/vim-scripts/groovy.vim.git'
Bundle 'https://github.com/vim-scripts/jQuery.git'
Bundle 'https://github.com/vim-scripts/Arduino-syntax-file.git'
Bundle 'https://github.com/nono/vim-handlebars'
Bundle 'https://github.com/leshill/vim-json.git'
Bundle 'https://github.com/pangloss/vim-javascript.git'
Bundle 'https://github.com/vim-scripts/jsbeautify.git'
Bundle 'https://github.com/kchmck/vim-coffee-script.git'
Bundle 'https://github.com/chaquotay/ftl-vim-syntax.git'
Bundle 'https://github.com/plasticboy/vim-markdown.git'
Bundle 'https://github.com/othree/html5.vim'
Bundle 'https://github.com/lepture/vim-css'
Bundle 'https://github.com/groenewege/vim-less.git'
" Tools
Bundle 'https://github.com/vim-scripts/bufexplorer.zip.git'
Bundle 'https://github.com/vim-scripts/JavaDecompiler.vim.git'
Bundle 'https://github.com/vim-scripts/matrix.vim--Yang.git'
Bundle 'https://github.com/vim-scripts/taglist.vim.git'
Bundle 'https://github.com/vim-scripts/grep.vim.git'
Bundle 'https://github.com/vim-scripts/scratch.vim.git'
Bundle 'https://github.com/vim-scripts/MatchTag.git'
Bundle 'https://github.com/vim-scripts/TaskList.vim.git'
Bundle 'https://github.com/scrooloose/nerdtree.git'
Bundle 'https://github.com/scrooloose/nerdcommenter.git'
Bundle 'https://github.com/scrooloose/vim-statline.git'
Bundle 'https://github.com/scrooloose/syntastic'
Bundle 'https://github.com/tpope/vim-fugitive.git'
Bundle 'https://github.com/tpope/vim-surround'
Bundle 'https://github.com/tpope/vim-speeddating.git'
Bundle 'https://github.com/tpope/vim-unimpaired.git'
Bundle 'https://github.com/ervandew/supertab.git'
Bundle 'https://github.com/garbas/vim-snipmate'
Bundle 'https://github.com/scrooloose/snipmate-snippets.git'
Bundle 'https://github.com/Lokaltog/vim-easymotion.git'
Bundle 'https://github.com/Raimondi/delimitMate'
Bundle 'https://github.com/nathanaelkane/vim-indent-guides.git'
Bundle 'https://github.com/kien/ctrlp.vim'
Bundle 'https://github.com/sukima/xmledit.git'
Bundle 'https://github.com/mattn/zencoding-vim.git'
" enable filetype plugin
filetype on
filetype plugin on
filetype indent on
" #################### vundle plugin config ####################
" #################### msic ####################
colorscheme desert
syntax on
" autocmd! bufwritepost vimrc source $HOME/.vim/vimrc " when vimrc is edited, reload it
set fileformats=unix,dos,mac
set colorcolumn=80 " mark 80th column with a red line
set linebreak " only wrap when blank
set fo+=mB " support for asian languages
" set showmatch " parentheses match
" set autoindent
set smartindent
set selectmode= " do not use select mode
set mousemodel=popup " enable context menu
set keymodel= " do not use shift + arrow to select text
set selection=inclusive " the text within the cursor is selected too when select text
if (has('gui_running'))
set wrap
"set nowrap
set guioptions+=b " show hscroll
else
set wrap
endif
set autochdir
set number " show line number
set nobackup
set isprint=@,128-255
" tab stops
set shiftwidth=4
set tabstop=4
set softtabstop=4
set expandtab
set wildchar=<TAB> " use tab for auto-expansion in menus
set wildmode=list:longest,list:full " how command line completion works
set wildignore=*.o,*.r,*.so,*.sl,*.tar,*.tgz,*.class,*.jar " ignore some files for filename completion
set suffixes=.h,.bak,~,.o,.info,.swp,.obj " some filetypes got lower priority
set showmode " shows the current status (insert, visual, ...) in statusline
set shortmess=a " use shortest messages
" #################### msic ####################
" #################### ui related config ####################
if has("win32")
autocmd GUIEnter * simalt ~x " auto max vim when start
endif
set guioptions-=T " turn off useless toolbar
set guioptions-=m " turn off menu bar (toggle with CTRL+F11)
" show always statusline of last window
" set laststatus=2
" set statusline=%F%m%r%h%w\ [%{&ff}]\ [%Y]\ %{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\\"}\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [%04l,%04v][%p%%]\ [LEN=%L]\
" #################### ui related config ####################
" #################### key maps ####################
imap <C-h> <LEFT>
imap <C-j> <DOWN>
imap <C-k> <UP>
imap <C-l> <RIGHT>
imap <C-b> <DEL>
imap <C-BS> <ESC>vBc " use C-BS to delete previous word
" CTRL + F11 to toggle the menu bar
nmap <C-F11> :if &guioptions=~'m' \| set guioptions-=m \| else \| set guioptions+=m \| endif<cr>
" CTRL + F7 to toggle the right-hand scroll bar
nmap <C-F7> :if &guioptions=~'r' \| set guioptions-=r \| else \| set guioptions+=r \| endif<cr>
nmap <M-,> :call search ("^". matchstr (getline (line (".")+ 1), '\(\s*\)') ."\\S", 'b')<CR>^
nmap <M-.> :call search ("^". matchstr (getline (line (".")), '\(\s*\)') ."\\S")<CR>^
map <Leader>xml :set filetype=xml<CR>
map <Leader>html :set filetype=html<CR>
map <Leader>js :set filetype=javascript<CR>
map <Leader>ftl :set filetype=ftl<CR>
map <Leader>java :set filetype=java<CR>
map <Leader>utf8 :set encoding=utf8<CR>
map <F10> :TlistToggle<CR>
" use the arrows to something usefull
map <right> :bn<cr>
map <left> :bp<cr>
" rot-13 encode
map <F3> ggVGg?
" #################### key maps ####################
" #################### autocmd ####################
autocmd BufNewFile,BufRead *.xhtml,*.xht setfiletype xhtml
autocmd BufNewFile,BufRead *.mml setfiletype mathml
autocmd BufNewFile,BufRead *.svg setfiletype svg
autocmd BufNewFile,BufRead *.groovy,*.jsonx setfiletype groovy
autocmd BufNewFile,BufRead *.ftl setfiletype ftl
autocmd BufNewFile,BufRead *.handlebars,*.hbs setfiletype handlebars
autocmd BufNewFile,BufRead *.pde,*.ino setfiletype arduino
autocmd BufNewFile,BufRead jquery.*.js set ft=javascript syntax=jquery
" hightlight trailing whitespaces
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
" remove all trailing whitespaces when save
autocmd BufWritePre * :%s/\s\+$//e
" compile CoffeeScript when save
autocmd BufWritePost *.coffee silent CoffeeMake!
nnoremap ,m :w <BAR> !lessc % > %:t:r.css<CR><space>
" #################### autocmd ####################
" #################### encoding related config ####################
if has("multi_byte")
if &termencoding == ""
let &termencoding = &encoding
endif
set encoding=utf-8
setglobal fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,latin1,gbk,gb2312
set nobomb
set langmenu=zh_CN.UTF-8
language messages zh_CN.UTF-8
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
else
echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
endif
" #################### encoding related config ####################
" #################### NERDTree ####################
let NERDTreeDirArrows=1
let g:NERDTreeHijackNetrw=0 " that fixes a problem with NERDTree and vim-bundler
let g:NERDTreeShowBookmarks=1
let g:NERDTreeMouseMode=3
let g:NERDTreeWinSize=30
map <F11> :NERDTreeToggle<cr>
" #################### NERDTree ####################
" #################### other plugin config ####################
let g:js_indent_log = 0
let g:syntastic_enable_signs = 1 " sintastic.vim config
let g:snippets_dir = '$HOME/.vim/bundle/snipmate-snippets' " where to load snipmate snippets
source $HOME/.vim/bundle/snipmate-snippets/support_functions.vim " load support functions
let delimitMate_excluded_ft = "xml,html,xhtml"
let coffee_compile_vert = 1
setl scrollbind
let g:ctrlp_working_path_mode = 'ra'
execute pathogen#infect()
" #################### other plugin config ####################
" tSkeleton
"autocmd BufNewFile *.java TSkeletonSetup template.java
"autocmd BufNewFile *.xml TSkeletonSetup template.xml
"autocmd BufNewFile *.ftl TSkeletonSetup template.ftl
" Create new tag
"if !exists('*TSkeleton_JAVA_PACKAGE') "{{{2
" function! TSkeleton_JAVA_PACKAGE() "{{{3
" let file_path = expand("%:p:h")
" let file_path = substitute(file_path, "\\", ".", "g")
" let file_path = substitute(file_path, "^.*com", "com", "g")
" return file_path
" endf
"endif
"if !exists('*TSkeleton_COMMENT') "{{{2
" function! TSkeleton_COMMENT() "{{{3
" let title = TSkeletonGetVar("tskelTitle", 'input("Please input file comment: ")', '')
" return title
" endf
"endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment