Skip to content

Instantly share code, notes, and snippets.

@imzhi
Last active August 18, 2016 08:09
Show Gist options
  • Save imzhi/9634585 to your computer and use it in GitHub Desktop.
Save imzhi/9634585 to your computer and use it in GitHub Desktop.
.vimrc 加强配置
"""""""""""""""""""""""""""""""""
" Refer to https://github.com/amix/vimrc
"""""""""""""""""""""""""""""""""
let g:isWindows = has('win32') || has('win64')
let g:isGUI = has('gui_running')
set nocompatible " be iMproved
filetype off " required!
if g:isWindows
set directory=.,$TEMP
set guifont=Consolas:h10.5,Courier\ New:h10.5
source $VIM/plugins.rc.vim
else
source ~/.vim/plugins.rc.vim
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Show line numbers
set number
" Sets how many lines of history VIM has to remember
set history=700
" Enable filetype plugins/indent settings
filetype plugin indent on
" Set to auto read when a file is changed from the outside
set autoread
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
" Fast saving
nmap <leader>w :w!<cr>
" :W sudo saves the file
" (useful for handling the permission-denied error)
command W w !sudo tee % > /dev/null
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7
" Avoid garbled characters in Chinese language windows OS
let $LANG='en'
set langmenu=en
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
" Turn on the WiLd menu
set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,,*.dll,*.obj,*.bak,*.exe,*.pyc,*.jpg,*.gif,*.png
if g:isWindows
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
else
set wildignore+=.git\*,.hg\*,.svn\*
endif
" turn on wild mode huge list
" set wildmode=longest,full
"Always show current position
set ruler
" Height of the command bar
set cmdheight=2
" A buffer becomes hidden when it is abandoned
set hid
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" Don't redraw while executing macros (good performance config)
set lazyredraw
" For regular expressions turn magic on
set magic
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Add a bit extra margin to the left
set foldcolumn=1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlighting
syntax enable
try
colorscheme default
catch
endtry
" set background=dark
" Set extra options when running in GUI mode
if g:isGUI
set guioptions-=e
" 隐藏工具栏
set guioptions-=T
" 隐藏菜单栏
" set guioptions-=m
set t_Co=256
set guitablabel=%M\ %t
try
colorscheme desert
catch
endtry
endif
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8
set bomb
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set fileencoding=utf8
set termencoding=utf8
" Use Unix as the standard file type
set ffs=unix,dos,mac
set fileformat=unix
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs ;)
set smarttab
" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4
set sts=4
" Linebreak on 500 characters
set lbr
set tw=500
set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs, windows and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk
" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search)
map <space> /
map <c-space> ?
" Disable highlight when <leader><cr> is pressed
map <silent> <leader><cr> :noh<cr>
" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Close the current buffer
map <leader>bd :Bclose<cr>
" Close all the buffers
map <leader>ba :1,1000 bd!<cr>
" Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
map <leader>te :tabnext
" Let 'tl' toggle between this and the last accessed tab
let g:lasttab = 1
nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Specify the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
" 何时显示带标签页标签的行,0-永远不 1-至少有两个 2-永远有
set stal=1
catch
endtry
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
" Avoid the escape key
" refrence http://vim.wikia.com/wiki/Avoid_the_escape_key
imap ii <Esc>
" Switch to alternate file
map <C-Tab> :bnext<CR>
map <C-S-Tab> :bprevious<CR>
" Switch to buffers
nmap <Leader>bb :ls<CR>:buffer<Space>
" Map ctrl-movement keys to window switching
map <C-k> <C-w><Up>
map <C-j> <C-w><Down>
map <C-h> <C-w><Left>
map <C-l> <C-w><Right>
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
" Format the status line
set statusline=
set statusline +=%1*\ %n\ %* "buffer number
set statusline +=%5*%{&ff}%* "file format
set statusline +=%7*[%{strlen(&fenc)?&fenc:&enc}]%* "encoding
set statusline +=%3*%y%* "file type
set statusline +=%4*\ %<%F%* "full path
set statusline +=%2*%m%* "modified flag
set statusline +=%1*%=%5l%* "current line
set statusline +=%2*/%L%* "total lines
set statusline +=%1*%4v\ %* "virtual column number
set statusline +=%2*0x%04B\ %* "character under cursor
hi User1 guifg=#eea040 guibg=#222222
hi User2 guifg=#dd3333 guibg=#222222
hi User3 guifg=#ff66ff guibg=#222222
hi User4 guifg=#a0ee40 guibg=#222222
hi User5 guifg=#eeee40 guibg=#222222
hi User6 guifg=#5D90DB guibg=#222222
hi User7 guifg=#DA12CA guibg=#222222
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Parenthesis/bracket
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
vnoremap $1 <esc>`>a)<esc>`<i(<esc>
vnoremap $2 <esc>`>a]<esc>`<i[<esc>
vnoremap $3 <esc>`>a}<esc>`<i{<esc>
vnoremap $$ <esc>`>a"<esc>`<i"<esc>
vnoremap $q <esc>`>a'<esc>`<i'<esc>
vnoremap $e <esc>`>a"<esc>`<i"<esc>
" Map auto complete of (, ", ', [
inoremap $1 ()<esc>i
inoremap $2 []<esc>i
inoremap $3 {}<esc>i
inoremap $4 {<esc>o}<esc>O
inoremap $5 ''<esc>i
inoremap $6 ""<esc>i
inoremap $7 <><esc>i
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General abbreviations
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Fast editing and reloading of vimrc configs
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if g:isWindows
map <leader>e :e! $VIM/_vimrc<cr>
else
map <leader>e :e! ~/.vimrc<cr>
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => others
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" share windows clipboard
set clipboard+=unnamed
" use mouse everywhere
set mouse=a
" use project-specific tags files
" view http://vim.wikia.com/wiki/Single_tags_file_for_a_source_tree
set tags=./tags;
" always switch to the current file directory
set autochdir
" don't insert any extra pixel lines betweens rows
set linespace=0
" tell us when anything is changed via :...
set report=0
" we do what to show tabs, to ensure we get them out of my files
set list
" show tabs and trailing
set lcs=tab:\|\ ,nbsp:%,trail:-
" Turn on folding
set foldenable
" Fold on the indent (damn you python)
set foldmethod=indent
" Don't autofold anything (but I can still fold manually)
set foldlevel=100
" what movements open folds
set foldopen=block,hor,mark,percent,quickfix,tag
" end of line
set eol
" 在处理未保存或只读文件的时候,弹出确认
set confirm
" 设定行首tab为灰色
highlight LeaderTab guifg=#666666
" 匹配行首tab
match LeaderTab /^\t/
" show command in statusline
set showcmd
" always show command or insert mode
set showmode
" 代码补全
" set completeopt=preview,longest,menu
" 突出显示当前行。会影响性能,注释掉
" set cursorline
" 不记得
" set selection=exclusive
" set selectmode=mouse,key
" Toggle Vexplore with Ctrl-E
" 来源:http://modal.us/blog/2013/07/27/back-to-vim-with-nerdtree-nope-netrw/
function! ToggleVExplorer()
if exists("t:expl_buf_num")
let expl_win_num = bufwinnr(t:expl_buf_num)
if expl_win_num != -1
let cur_win_nr = winnr()
exec expl_win_num . 'wincmd w'
close
exec cur_win_nr . 'wincmd w'
unlet t:expl_buf_num
else
unlet t:expl_buf_num
endif
else
exec '1wincmd w'
Vexplore
let t:expl_buf_num = bufnr("%")
endif
endfunction
map <silent> <C-E> :call ToggleVExplorer()<CR>
" Hit enter in the file browser to open the selected
" file with :vsplit to the right of the browser.
let g:netrw_browse_split = 4
let g:netrw_altv = 1
" Default to tree mode
let g:netrw_liststyle=3
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" <empty>
if g:isWindows
set rtp+=$VIM/vimfiles/bundle/Vundle.vim/
call vundle#begin('$VIM/vimfiles/bundle/')
else
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin('~/.vim/bundle/')
endif
" let Vundle manage Vundle
" required!
Plugin 'gmarik/Vundle.vim'
" My bundles here:
Plugin 'vim-scripts/grep.vim'
Plugin 'vim-scripts/Align'
Plugin 'vim-scripts/taglist.vim'
Plugin 'kien/ctrlp.vim'
Plugin 'tpope/vim-commentary'
Plugin 'mattn/emmet-vim'
Plugin 'asins/vimcdoc'
Plugin 'leafgarland/typescript-vim'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins configuration
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => grep
nnoremap <silent><F3> :Grep<CR>
let Grep_Default_Options="-r -i"
let Grep_Skip_Dirs=".git .svn"
let Grep_Skip_Files=".bak *~ .swp .swo"
let Grep_Shell_Quote_Char="'"
let Grep_Shell_Escape_Char="'"
" => grep end
" => vimcdoc
set helplang=cn
" => vimcdoc end
" => taglist
nnoremap <silent> <F8> :TlistToggle<CR>
let Tlist_Show_One_File=1
let Tlist_Use_Right_Window=1
let Tlist_Exit_OnlyWindow=1
let Tlist_WinWidth=20
" disable the fold column
let Tlist_Enable_Fold_Column=0
" => taglist end
@imzhi
Copy link
Author

imzhi commented Mar 19, 2014

在 windows 下 安装 vundle,应该是在 Vim\vimfiles\bundle 目录下 运行 git clone https://github.com/gmarik/Vundle.vim.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment