##工具栏、菜单栏、状态栏
set guioptions-=T “ 隐藏工具栏
set guioptions-=m “ 隐藏菜单栏
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
"总是显示状态栏"
set laststatus=2
set statusline+=%1*%-52F\
set statusline+=%2*\ %{&ff=='unix'?'\\n':(&ff=='mac'?'\\r':'\\r\\n')}\
set statusline+=%3*\ %{&fenc!=''?&fenc:&enc}\
set statusline+=%1*\ %Y\
set statusline+=%4*\ %04l/%03c\
set statusline+=%5*\ %r%{getcwd()}%h\
hi User1 guifg=#112605 guibg=#aefe7B gui=bold
hi User2 guifg=#391100 guibg=#d3905c gui=bold
hi User3 guifg=#292b00 guibg=#f4f597 gui=bold
hi User4 guifg=#051d00 guibg=#7dcc7d gui=bold
hi User5 guifg=#002600 guibg=#67ab6e gui=bold
"让标题显示当前的函数或者类"
set title titlestring=%<%f\ %([%{Tlist_Get_Tag_Prototype_By_Line()}]%)
##小Tips
“With a map leader it’s possible to do extra key combinations
“like w saves the current file
let mapleader = ","
let g:mapleader = ","
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 自定义
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"set tags+=C:/Program\\\ Files/Microsoft\\\ SDKs/Windows/v6.1/Include/tags
"set tags+=C:/Program\\\ Files\\\ (x86)/Microsoft\\\ Visual\\\ Studio\\\ 9.0/VC/include/tags
set tags+=./tags
" 自动显示行号
set nu
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sets how many lines of history VIM has to remember
set history=700
" Enable filetype plugins
set nocp
"自动补全的显示方式,longest在<C-N>时有异常"
"不需要preview窗口“
""set completeopt=longest,menu
set completeopt=menu
filetype plugin on
filetype 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>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the cursor - when moving vertically using j/k
" 当使用j/k往上/下翻滚时,光标距离的边距(除非到了文件的首尾)
set so=7
" Turn on the WiLd menu
set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,*.pyc
"Always show current position
set ruler
" 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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => 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
" Linebreak on 500 characters
set lbr
set tw=500
set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines
set autoindent
set smartindent
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlighting
syntax enable
" 配色方案
colorscheme desert
set background=dark
" Set extra options when running in GUI mode
if has("gui_running")
set guioptions-=T
set guioptions+=e
set t_Co=256
set guitablabel=%M\ %t
endif
" Set gbk as standard encoding and en_US as the standard language
if has("win32")
set encoding=gbk
" 如果你要打开的文件编码不在此列,那就添加进去
set fileencodings=utf-8,gbk,gb2312,gb18030,ucs-bom,cp936,latin1
set termencoding=gbk
else
set encoding=utf-8
" 如果你要打开的文件编码不在此列,那就添加进去
set fileencodings=utf-8,gbk,gb2312,gb18030,ucs-bom,cp936,latin1
set termencoding=utf-8
endif
" Use Unix as the standard file type
set ffs=unix,dos,mac
" 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^=%
" Returns true if paste mode is enabled
function! HasPaste()
if &paste
return 'PASTE MODE '
en
return ''
endfunction
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
"总是显示状态栏"
set laststatus=2
set statusline+=%1*%-52F\
set statusline+=%2*\ %{&ff=='unix'?'\\n':(&ff=='mac'?'\\r':'\\r\\n')}\
set statusline+=%3*\ %{&fenc!=''?&fenc:&enc}\
set statusline+=%1*\ %Y\
set statusline+=%4*\ %04l/%03c\
set statusline+=%5*\ %r%{getcwd()}%h\
hi User1 guifg=#112605 guibg=#aefe7B gui=bold
hi User2 guifg=#391100 guibg=#d3905c gui=bold
hi User3 guifg=#292b00 guibg=#f4f597 gui=bold
hi User4 guifg=#051d00 guibg=#7dcc7d gui=bold
hi User5 guifg=#002600 guibg=#67ab6e gui=bold
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Misc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" Quickly open a buffer for scripbble
"map <leader>q :e ~/buffer<cr>
" Toggle paste mode on and off
"map <leader>pp :setlocal paste!<cr>
if has("win32")
au GUIEnter * simalt ~x " 窗口最大化
endif
"空格快速切换fold"
"nnoremap <silent> <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
""set foldmethod=syntax " 用语法高亮来定义折叠
"set foldmethod=indent " 更多的缩进表示更高级别的折叠(这个似乎效果好一些)
"set fillchars=fold:\
"set foldtext=MyFoldText()
"function MyFoldText()
"return "+" . v:foldlevel . " -->>>"
"endfunction
"显示括号配对情况
set showmatch
"高亮当前行
set cursorline
set guioptions-=T " 隐藏工具栏
set guioptions-=m " 隐藏菜单栏
"Ctrl+N 自动搜索补全函数或变量等。如果习惯shell的tab补全功能只需要在vimrc里面加入如下代码
""function! CleverTab()
"" if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
"" return "\<Tab>"
"" else
"" return "\<C-N>"
""endfunction
""inoremap <Tab> <C-R>=CleverTab()<CR>
"自动补全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
":inoremap { {<CR>}<ESC>O
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
autocmd BufReadPost *.sh inoremap { {}<ESC>i
autocmd BufReadPost *.c inoremap { {<CR>}<ESC>O
autocmd BufReadPost *.cc inoremap { {<CR>}<ESC>O
autocmd BufReadPost *.cpp inoremap { {<CR>}<ESC>O
autocmd BufReadPost *.h inoremap { {<CR>}<ESC>O
autocmd WinEnter * set laststatus=1
"80列
if exists('+colorcolumn')
set colorcolumn=80
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
""""""""""""""""""""""""""""""
" Tag list (ctags)
""""""""""""""""""""""""""""""
" Platform
function! MySys()
if has("win32")
return "windows"
else
return "linux"
endif
endfunction
if MySys() == "windows" "设定windows系统中ctags程序的位置
let Tlist_Ctags_Cmd = 'ctags'
elseif MySys() == "linux" "设定linux系统中ctags程序的位置
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
endif
"F8用于开启/关闭 Taglist窗口"
nnoremap <silent> <F3> :TlistToggle<CR>
nmap <silent> <leader>tl :TlistToggle<cr>
"选择P跳到指定的位置,并且将焦点切换到最近的窗口"
"选择p跳到指定的位置,但不切换焦点"
let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,只显示当前文件的"
let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim"
let Tlist_Use_Right_Window = 1 "在右侧窗口中显示taglist窗口"
let Tlist_GainFocus_On_ToggleOpen = 1 "窗口打开之后,立即获得焦点"
let Tlist_Process_File_Always = 1 "总是处理taglist"
let Tlist_WinWidth = 20
"让标题显示当前的函数或者类"
set title titlestring=%<%f\ %([%{Tlist_Get_Tag_Prototype_By_Line()}]%)
""""""""""""""""""""""""""""""
" netrw setting
""""""""""""""""""""""""""""""
"let g:netrw_winsize = 30
"let g:netrw_preview = 1 "预览窗口时,打开竖型窗口"
"nmap <silent> <leader>fe :Sexplore!<cr>
""""""""""""""""""""""""""""""
" NERDTree setting
""""""""""""""""""""""""""""""
nmap <silent> <leader>fe :NERDTreeToggle<cr>
nnoremap <silent> <F4> :NERDTreeToggle<cr>
let NERDTreeDirArrows=0
" 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
""""""""""""""""""""""""""""""
" BufExplorer
""""""""""""""""""""""""""""""
""let g:bufExplorerDefaultHelp=0 " Do not show default help.
""let g:bufExplorerShowRelativePath=1 " Show relative paths.
""let g:bufExplorerSortBy='mru' " Sort by most recently used.
""let g:bufExplorerSplitRight=0 " Split left.
""let g:bufExplorerSplitVertical=1 " Split vertically.
""let g:bufExplorerSplitVertSize = 30 " Split width
""let g:bufExplorerUseCurrentWindow=1 " Open in new window.
""let g:winManagerWindowLayout='BufExplorer|FileExplorer'
""let g:defaultExplorer = 0 "使用默认explorer的行为"
""let g:winManagerWidth = 30
""let g:persistentBehaviour = 0 "当所有文件退出之后,就自行退出"
""nmap <silent> <leader>wm :WMToggle<cr>
""""""""""""""""""""""""""""""
" MiniBufExplorer
""""""""""""""""""""""""""""""
"<Enter> 打开tab"
"d 删除tab"
let g:miniBufExplMapCTabSwitchBufs = 1
nmap <silent> <leader>a <C-TAB><cr>
nmap <silent> <leader>e <C-S-TAB><cr>
""""""""""""""""""""""""""""""
" 生成findupfile.tag
"http://blog.csdn.net/luocm/article/details/2503016"
"http://www.newsmth.net/bbsanc.php?path=%2Fgroups%2Fcomp.faq%2FVIM%2FpluginRecommend%2Fcode_aid%2Fproject%2FM.1177477015.g0&ap=1554"
""""""""""""""""""""""""""""""
" Lookup File
" Author: happyvim
" Function: ProjectTagUpdateLookupFile
" Args:
" Description: regenerate lookupfile tags
function! ProjectTagUpdateLookupFile()
echo "generate lookupfile.tag"
if filereadable(g:project_lookup_file)
call delete(g:project_lookup_file)
endif
execute "cd " . g:this_project_base_dir
let l:lookup_tags = ["!_TAG_FILE_SORTED 2 //2=foldcase//"]
if has("win32")
let l:this_project_base_dir = substitute(g:this_project_base_dir, "/", "\\", "g") . "\\"
else
let l:this_project_base_dir = g:this_project_base_dir
endif
let l:lookup_tags_file_string = system(g:project_find_program . " " . g:project_find_param)
let l:lookup_tags_file_list = split(l:lookup_tags_file_string, '\n')
let l:lookup_tags_file_list = sort(l:lookup_tags_file_list)
let l:item = ""
let l:count = 0
for l:item in l:lookup_tags_file_list
let l:item = fnamemodify(l:item, ':t') . "\t" . l:item . "\t" . "1"
let l:lookup_tags_file_list[l:count] = l:item
let l:count = l:count + 1
endfor
call extend(l:lookup_tags, l:lookup_tags_file_list)
call writefile(l:lookup_tags, g:project_lookup_file)
echo "generate lookupfile tag done"
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"#!/bin/sh
"echo -e "!_TAG_FILE_SORTED\t2\t/2=foldcase/" > "${1}"
"find . \( -name "*.c" -o -name "*.cpp" -o -name "*.cc" -o -name "*.h" -o -name "*.sh" \) \
" -type f -printf "%f\t%p\t1\n" | sort -f >> "${1}"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! ProjectTagUpdateLookupFileLinux()
echo "generate lookupfile.tag"
if filereadable(g:project_lookup_file)
call delete(g:project_lookup_file)
endif
let l:lookup_tags_file_string = system("lookup_vi.sh" . " " . g:project_lookup_file)
echo "generate lookupfile tag done"
endfunction
let g:project_lookup_file = "findupfile.tag"
let g:project_find_program = "dir /B /S /A-D /ON"
let g:project_find_param = "*.c *.cpp *.h *.hpp *.cc"
let g:this_project_base_dir = "."
"映射LookupFile为,ff
if has("win32")
nmap <silent> <leader>bf :call ProjectTagUpdateLookupFile()<CR><CR>
else
nmap <silent> <leader>bf :call ProjectTagUpdateLookupFileLinux()<CR><CR>
endif
"ctags"
"-h= 过滤文件类型"
nmap <silent> <leader>bt :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --languages=C++ --langmap=C++:+.inl.c --exclude=svn .<CR><CR>
""""""""""""""""""""""""""""""
" lookupfile setting
""""""""""""""""""""""""""""""
let g:LookupFile_MinPatLength = 2 "最少输入2个字符才开始查找
let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串
let g:LookupFile_PreservePatternHistory = 1 "保存查找历史
let g:LookupFile_AlwaysAcceptFirst = 1 "回车打开第一个匹配项目
let g:LookupFile_AllowNewFiles = 0 "不允许创建不存在的文件
"使用自定义tag文件(注意双层括号,不能省略)"
let g:LookupFile_TagExpr = '"findupfile.tag"'
""""""""""""""""""""""""""""""
" NERD_commenter setting
""""""""""""""""""""""""""""""
"禁用默认的map"
let NERDCreateDefaultMappings = 0
"使用,c"
nmap <silent> <leader>c <plug>NERDCommenterInvert
vmap <silent> <leader>c <plug>NERDCommenterInvert
"设置VI字体,"
if has("win32")
set guifont=Courier_New:h11:cANSI
endif
"搜索文件"
nmap <silent> <leader>f :LookupFile<CR>
"切换C/H文件"
nmap <silent> <leader>h :AV<CR>
"快速定位tag"
nmap <silent> <leader>g <C-]><CR>
nmap <silent> <F12> <C-]><CR>
"去掉高亮"
" Key mapping to stop the search highlight
nmap <silent> <F2> :nohlsearch<CR>
"列出当前目录文件
"map <F3> :tabnew .<CR>
"默认C++语法"
"set syntax=cpp
"设置超时响应"
set timeout timeoutlen=3000 ttimeoutlen=100
""""""""""""""""""""""""""""""
" grep setting
""""""""""""""""""""""""""""""
"默认搜索文件类型"
let Grep_Default_Filelist = '*.c *.cpp *.cc *.h *.hpp'
"默认忽略大小写"
"let Grep_Default_Options = '-i'
"map"
nmap <silent> <leader>s :Grep<CR>
"快速关闭窗口"
nmap <silent> <leader>q :q<CR>
"处理Ctrl+V,Gvim被粘贴占用了
nmap <silent> <leader>v <C-Q>
"快速去掉Windows文件中的^M"
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" 启动的时候不显示那个援助索马里儿童的提示
set shortmess=atI
" 自动切换行数
nmap <silent> <leader>l :set invnumber<cr>
map <silent> <F11> :set invnumber<cr>
" 切换paste/nopaste
set pastetoggle=<F10>
" 剪贴板
if has("win32")
set clipboard=unnamed
endif