"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Environment
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
"behave mswin
set fileencodings=utf-8,gb2312,ucs-bom,euc-cn,euc-tw,gb18030,gbk,cp936
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let g:mapleader = ","
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700
"set colorcolumn=80
set number
set cursorline
"set cursorcolumn
" Enable filetype plugin
filetype on
filetype plugin on
filetype indent on
" Set to auto read when a file is changed from the outside
set autoread
" Fast saving
nmap <leader>w :w!<cr>
" Fast quiting
nmap <leader>q :q<cr>
" system clipboard
set clipboard+=unnamed
" Maximize window
autocmd GUIEnter * simalt ~x
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" Mouse enable
set mouse=a
" folder enable with space
set foldenable
set foldmethod=manual
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
" 启动时不显示援助索马里儿童的提示
set shortmess=atI
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the curors - when moving vertical..
set so=7
set wildmenu "Turn on WiLd menu
set ruler "Always show current position
set cmdheight=2 "The commandbar height
set hid "Change buffer - without saving
" Set backspace config
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set ignorecase "Ignore case when searching
set smartcase
set hlsearch "Highlight search things
set incsearch "Make search act like search in modern browsers
set nolazyredraw "Don't redraw while executing macros
set magic "Set magic on, for regular expressions
set showmatch "Show matching bracets when text indicator is over them
set mat=2 "How many tenths of a second to blink
" No sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
set listchars=tab:>.,trail:.,extends:#,nbsp:. " Highlight problematic whitespace
if has('statusline')
" Always show the statusline
set laststatus=2
" Broken down into easily includeable segments
set statusline=%<%f\ " Filename
set statusline+=%w%h%m%r " Options
"set statusline+=%{fugitive#statusline()} " Git Hotness
set statusline+=\ [%{&ff}/%Y] " filetype
set statusline+=\ [%{getcwd()}%h\] " current dir
set statusline+=\ [A=\%03.3b/H=\%02.2B] " ASCII / Hexadecimal value of char
set statusline+=%=%-16.(%l/%L,%c%V%)\ %p%% " Right aligned file nav info
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax enable "Enable syntax hl
if has("gui_running")
set guioptions-=m
set guioptions-=T
map <silent> <F11> :if &guioptions =~# 'T' <Bar>
\set guioptions-=T <Bar>
\set guioptions-=m <bar>
\else <Bar>
\set guioptions+=T <Bar>
\set guioptions+=m <Bar>
\endif<CR>
set t_Co=256
colorscheme desert
else
colorscheme zellner
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git anyway...
set nobackup
set nowb
set noswapfile
"Persistent undo
try
if MySys() == "windows"
set undodir=C:\Windows\Temp
else
set undodir=~/.vim_runtime/undodir
endif
set undofile
catch
endtry
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set expandtab
set shiftwidth=4
set tabstop=4
set smarttab
set lbr
set tw=500
set ai "Auto indent
set si "Smart indet
set wrap "Wrap lines
" Remove trailing whitespaces and ^M chars
autocmd FileType c,cpp,java,php,js,python,twig,xml,yml autocmd BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
""""""""""""""""""""""""""""""
" => Visual mode related
""""""""""""""""""""""""""""""
" Really useful!
" In visual mode when you press * or # to search for the current selection
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>
" When you press gv you vimgrep after the selected text
vnoremap <silent> gv :call VisualSearch('gv')<CR>
map <leader>g :vimgrep // **/*<left><left><left><left><left><left>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Other's Key Mappings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Yank from the cursor to the end of the line, to be consistent with C and D.
nnoremap Y y$
nnoremap noah :call SetCompany("NOAH")<cr>
nnoremap fj :call SetCompany("FJ")<cr>
noremap <S-tab> :call TabToSpace()<cr><esc>
"noremap <C-P> :hardcopy<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Smart way to move btw. 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,300 bd!<cr>
" Tab configuration
"nmap <C-S-tab> :tabprevious<cr>
"nmap <C-tab> :tabnext<cr>
imap <C-S-tab> <ESC>:tabprevious<cr>a
imap <C-tab> <ESC>:tabnext<cr>a
"nmap <C-t> :tabnew<cr>
imap <C-t> <ESC>:tabnew<cr>a
"map <C-w> :tabclose<cr>
imap <C-w> <esc>:tabclose<cr>a
" When pressing <leader>cd switch to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>
" Specify the behavior when switching between buffers
try
set switchbuf=usetab
set stal=2
catch
endtry
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugin Setteing
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Minibuffer {
let g:miniBufExplModSelTarget = 1
let g:miniBufExplorerMoreThanOne = 2
let g:miniBufExplModSelTarget = 0
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplVSplit = 25
let g:miniBufExplSplitBelow=1
let g:bufExplorerSortBy = "name"
autocmd BufRead,BufNew :call UMiniBufExplorer
map <leader>u :TMiniBufExplorer<cr>
" }
" NerdTree {
map <C-e> :NERDTreeToggle<CR>
"nmap <leader>nt :NERDTreeFind<CR>
let NERDTreeShowBookmarks=1
let NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr']
let NERDTreeChDirMode=0
let NERDTreeQuitOnOpen=1
let NERDTreeShowHidden=1
let NERDTreeKeepTreeInNewTab=1
" }
" FencView {
let g:fencview_autodetect=0
nmap <silent> <leader>fe :FencAutoDetect<CR>
nmap <silent> <leader>fv :FencView<CR>
" }
" winmanager {
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>
" }
" A {
nnoremap <silent> <F12> :A<CR>
" }
" Grep {
nnoremap <silent> <F3> :Grep<CR>
" }
" Ctags {
set tags=tags;
" Sort by name
let Tlist_Sort_Type = "name"
" list in right side
let Tlist_Use_Right_Window = 1
let Tlist_Compart_Format = 1
let Tlist_Exist_OnlyWindow = 1
" 不要关闭其他文件的tags
let Tlist_File_Fold_Auto_Close = 0
" 不要显示折叠树
let Tlist_Enable_Fold_Column = 0
" }
" MRU {
let MRU_Max_Entries = 400
map <leader>f :MRU<CR>
" }
" Yankring {
map <leader>y :YRShow<cr>
" }
" bufExplorer {
let g:bufExplorerDefaultHelp=0
let g:bufExplorerShowRelativePath=1
nmap <leader>b :BufExplorer<CR>
" }
" Calendar {
"let calendar_diary = "D:\diary"
" }
" FuzzyFinder {
"nnoremap <unique> <leader>fb :FufBuffer!<CR>
nnoremap <leader>ff :FufFile!<CR>
"nnoremap <unique> <leader>fc :FufRenewCache<CR>
"autocmd FileType fuf nmap <C-c> <ESC>
"let g:fuf_patternSeparator = ' '
"let g:fuf_modesDisable = ['mrucmd']
"let g:fuf_mrufile_exclude = '\v\.DS_Store|\.git|\.swp|\.svn'
"let g:fuf_mrufile_maxItem = 100
"let g:fuf_enumeratingLimit = 20
"let g:fuf_file_exclude = '\v\.DS_Store|\.git|\.swp|\.svn'
" }
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Functions
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
fun! MySys()
return "linux"
endfun
function! CurDir()
let curdir = getcwd()
return curdir
endfunction
function! SetCompany(name)
let s:lineno=line(".")
let s:linestr = getline(".")
if strlen(s:linestr) < 70
for i in range(strlen(s:linestr)+1, 70, 1)
let s:linestr.=" "
endfor
let s:linestr.=a:name
:+1
return setline (s:lineno, s:linestr)
endif
:+1
endfunction
function! TabToSpace()
:set ts=4
:set expandtab
:%retab! "加!是用于处理非空白字符之后的TAB,即所有的TAB,若不加!,则只处理行首的TAB。
endfunction
function! VisualSearch(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction