相應的安裝部分見上篇文章:vim學習筆記html
1.基於YcmCompleteMe、taglist.vim、The-NERD-tree等配置,F2調出目錄樹窗口,F3調出變量、函數窗口,有點IDE的樣子,呵呵!
2.定義了一些基本的快捷鍵:C-a 全選,C-c 選中狀態下複製,F5 編譯及運行,F8 調試,gb 跳到定義處。
3.Syntastic部分必需正確配置C++ include的目錄。
4.剛有個哥們問怎樣代表就成功了,我定義了F4爲:YcmDiags命令,按F4就會執行,若是代碼正確而運行不出錯就成功了,若代碼不正確運行就會出現Quickfix窗口,給出錯誤提示,這也代表配置已經成功。但這個配置其實沒多大用處,由於只要一存盤,就會自動調用該命令,呵呵!java
"******************************************************** " 通常性配置 * "******************************************************** "關閉vim一致性原則 set nocompatible "顯示行號 set number "設置在編輯過程當中右下角顯示光標的行列信息 set ruler "在狀態欄顯示正在輸入的命令 set showcmd "設置歷史記錄條數 set history=1000 "設置取消備份 禁止臨時文件的生成 set nobackup set noswapfile "設置匹配模式 set showmatch "設置C/C++方式自動對齊 set autoindent set cindent "開啓語法高亮功能 syntax enable syntax on "指定配色方案爲256色 set t_Co=256 "設置搜索時忽略大小寫 set ignorecase "配置backspace的工做方式 set backspace=indent,eol,start "選中高亮 set hls "高亮光標所在行 "set cul "cursorline "set cuc "set go= " 不要圖形按鈕 "color desert " 設置背景主題 color ron " 設置背景主題 "color torte " 設置背景主題 set guifont=Courier_New:h10:cANSI " 設置字體 "autocmd InsertLeave * se nocul " 用淺色高亮當前行 "autocmd InsertEnter * se cul " 用淺色高亮當前行 "set whichwrap+=<,>,h,l " 容許backspace和光標鍵跨越行邊界(不建議) " 光標移動到buffer的頂部和底部時保持3行距離 set scrolloff=3 " 老是顯示狀態行 " set cmdheight=1 set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} set laststatus=1 " 啓動顯示狀態行(1),老是顯示狀態行(2) set foldenable " 容許摺疊 "set foldmethod=manual " 手動摺疊 "set magic " 設置魔術 "set guioptions-=T " 隱藏工具欄 "set guioptions-=m " 隱藏菜單欄 let g:indentLine_char = '┊' "啓動時不顯示幫助烏干達兒童提示 set shortmess=atI "設置在vim中可使用鼠標 set mouse=a "設置tab寬度 set tabstop=4 "設置自動對齊空格數 set shiftwidth=4 "設置退格鍵時能夠刪除4個空格 set smarttab set softtabstop=4 "將tab鍵自動轉換爲空格 set expandtab "設置編碼方式 set encoding=utf-8 "自動判斷編碼時 依次嘗試如下編碼 set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1 "檢測文件類型 filetype on "針對不一樣的文件採起不一樣的縮進方式 filetype indent on "容許插件 filetype plugin on "啓動智能補全 filetype plugin indent on "********************************************************* " vundle 配置 * "********************************************************* set rtp+=~/.vim/bundle/vundle/ call vundle#rc() " let Vundle manage Vundle Bundle 'gmarik/vundle' " My Bundles here: Bundle 'tpope/vim-fugitive' Bundle 'Lokaltog/vim-easymotion' Bundle 'Yggdroot/indentLine' Bundle 'rstacruz/sparkup', {'rtp': 'vim/'} Bundle 'tpope/vim-rails.git' Bundle 'taglist.vim' Bundle 'The-NERD-tree' Bundle 'Syntastic' Bundle 'L9' Bundle 'FuzzyFinder' Bundle 'Lokaltog/vim-powerline' Bundle 'Valloric/YouCompleteMe' "***************************************************** " taglist配置 * "***************************************************** "不顯示"press F1 to display help" let Tlist_Compact_Format=1 "窗口在左側顯示 let Tlist_Use_Right_Window=1 "只顯示當前文件的tags let Tlist_Show_One_File=1 "高亮顯示 let Tlist_Auto_Highlight_tag=1 "隨文件自動更新 let Tlist_Auto_Update=1 "設置寬度 let Tlist_WinWidth=30 "taglist窗口是最後一個窗口,則退出vim let Tlist_Exit_OnlyWindow=1 "單擊跳轉 let Tlist_Use_SingClick=1 "打開關閉快捷鍵 nnoremap <silent> <F3> :TlistToggle<CR> "******************************************************** " NERD_Tree 配置 * "******************************************************** "顯示加強 let NERDChristmasTree=1 "自動調整焦點 let NERDTreeAutoCenter=1 "鼠標模式:目錄單擊,文件雙擊 let NERDTreeMouseMode=2 "打開文件後自動關閉 let NERDTreeQuitOnOpen=0 "顯示文件 let NERDTreeShowFiles=1 "顯示隱藏文件 let NERDTreeShowHidden=0 "高亮顯示當前文件或目錄 let NERDTreeHightCursorline=1 "顯示行號 let NERDTreeShowLineNumbers=1 "窗口位置 let NERDTreeWinPos='left' "窗口寬度 let NERDTreeWinSize=31 "不顯示'Bookmarks' label 'Press ? for help' let NERDTreeMinimalUI=1 "快捷鍵 nnoremap <silent> <F2> :NERDTreeToggle<CR> "當打開vim且沒有文件時自動打開NERDTree autocmd vimenter * if !argc() | NERDTree | endif "只剩 NERDTree時自動關閉 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif " 設置當文件被改動時自動載入 " set autoread "***************************************************** " YouCompleteMe配置 * "***************************************************** "leader映射爲逗號「,」 let mapleader = "," "配置默認的ycm_extra_conf.py "let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py' "按gb 會跳轉到定義 nnoremap <silent> gb :YcmCompleter GoToDefinitionElseDeclaration<CR> "打開vim時再也不詢問是否加載ycm_extra_conf.py配置 let g:ycm_confirm_extra_conf=0 "使用ctags生成的tags文件 let g:ycm_collect_identifiers_from_tag_files = 1 map <F4> : YcmDiags<CR> "***************************************************** " Syntastic配置 * "***************************************************** let g:syntastic_check_on_open = 1 let g:syntastic_cpp_include_dirs = ['/usr/include/'] let g:syntastic_cpp_remove_include_errors = 1 let g:syntastic_cpp_check_header = 1 let g:syntastic_cpp_compiler = 'clang++' let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libstdc++' "set error or warning signs let g:syntastic_error_symbol = '✗' let g:syntastic_warning_symbol = '⚠' "whether to show balloons let g:syntastic_enable_balloons = 1 "***************************************************** "C,C++ 按F5編譯運行 * "***************************************************** map <F5> :call CompileRunGcc()<CR> func! CompileRunGcc() exec "w" if &filetype == 'c' exec "!gcc % -o %<" exec "! ./%<" elseif &filetype == 'cpp' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'java' exec "!javac %" exec "!java %<" elseif &filetype == 'sh' :!./% endif endfunc "***************************************************** "C,C++的調試 F8 * "***************************************************** map <F8> :call Rungdb()<CR> func! Rungdb() exec "w" exec "!g++ % -g -o %<" exec "!gdb ./%<" endfunc "***************************************************** "鍵盤命令 * "***************************************************** nmap <leader>w :w!<cr> nmap <leader>f :find<cr> " 映射全選+複製 ctrl+a map <C-A> ggVGY map! <C-A> <Esc>ggVGY " 選中狀態下 Ctrl+c 複製 vmap <C-c> "+y "***************************************************** "新文件標題 * "***************************************************** "新建.c,.h,.sh,.java文件,自動插入文件頭 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()" ""定義函數SetTitle,自動插入文件頭 func SetTitle() "若是文件類型爲.sh文件 if &filetype == 'sh' call setline(1,"\#!/bin/bash") call append(line("."), "") elseif &filetype == 'python' call setline(1,"#!/usr/bin/env python") call append(line("."),"# coding=utf-8") call append(line(".")+1, "") elseif &filetype == 'ruby' call setline(1,"#!/usr/bin/env ruby") call append(line("."),"# encoding: utf-8") call append(line(".")+1, "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name : ".expand("%")) call append(line(".")+1, " > Author : zhoutk") call append(line(".")+2, " > Mail : zhoutk@189.cn") call append(line(".")+3, " > Created Time: ".strftime("%c")) call append(line(".")+4, " ************************************************************************/") call append(line(".")+5, "") endif if expand("%:e") == 'cpp' call append(line(".")+6, "#include<iostream>") call append(line(".")+7, "using namespace std;") call append(line(".")+8, "") endif if &filetype == 'c' call append(line(".")+6, "#include<stdio.h>") call append(line(".")+7, "") endif if expand("%:e") == 'h' call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H") call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H") call append(line(".")+8, "#endif") endif if &filetype == 'java' call append(line(".")+6,"public class ".expand("%:r")) call append(line(".")+7,"") endif "新建文件後,自動定位到文件末尾 endfunc autocmd BufNewFile * normal G "***************************************************** "代碼格式優化化 * "***************************************************** map <F6> :call FormartSrc()<CR><CR> "定義FormartSrc() func FormartSrc() exec "w" if &filetype == 'c' exec "!astyle --style=ansi -a --suffix=none %" elseif &filetype == 'cpp' || &filetype == 'hpp' exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1" elseif &filetype == 'perl' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'py'||&filetype == 'python' exec "r !autopep8 -i --aggressive %" elseif &filetype == 'java' exec "!astyle --style=java --suffix=none %" elseif &filetype == 'jsp' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'xml' exec "!astyle --style=gnu --suffix=none %" else exec "normal gg=G" return endif exec "e! %" endfunc "結束定義FormartSrc "下面兩個試驗沒成功,註釋後留在這作個記錄,去空行如果定義爲F4是成功的。 "去空行 "nnoremap <C-F4> :g/^\s*$/d<CR> "比較文件 "nnoremap <C-F2> :vert diffsplit
拷貝模板~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py到~/
下,主要有兩點改動:
1.flags增長對c++相關目錄的配置,我把針對OS X的配置刪除了。
2.配置文檔的倒數8到10註釋掉。python
# This file is NOT licensed under the GPLv3, which is the license for the rest # of YouCompleteMe. # # Here's the license text for this file: # # This is free and unencumbered software released into the public domain. # # Anyone is free to copy, modify, publish, use, compile, sell, or # distribute this software, either in source code form or as a compiled # binary, for any purpose, commercial or non-commercial, and by any # means. # # In jurisdictions that recognize copyright laws, the author or authors # of this software dedicate any and all copyright interest in the # software to the public domain. We make this dedication for the benefit # of the public at large and to the detriment of our heirs and # successors. We intend this dedication to be an overt act of # relinquishment in perpetuity of all present and future rights to this # software under copyright law. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # # For more information, please refer to <http://unlicense.org/> import os import ycm_core # These are the compilation flags that will be used in case there's no # compilation database set (by default, one is not set). # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. flags = [ '-Wall', '-Wextra', '-Werror', '-Wc++98-compat', '-Wno-long-long', '-Wno-variadic-macros', '-fexceptions', '-DNDEBUG', # You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM # source code needs it. '-DUSE_CLANG_COMPLETER', # THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which # language to use when compiling headers. So it will guess. Badly. So C++ # headers will be compiled as C headers. You don't want that so ALWAYS specify # a "-std=<something>". # For a C project, you would set this to something like 'c99' instead of # 'c++11'. '-std=c++11', # ...and the same thing goes for the magic -x option which specifies the # language that the files to be compiled are written in. This is mostly # relevant for c++ headers. # For a C project, you would set this to 'c' instead of 'c++'. '-x', 'c++', '-isystem', '../BoostParts', '-isystem', '/usr/include', '-isystem', '/usr/include/c++/', '-isystem', '/usr/include/c++/5.2.1', ] # Set this to the absolute path to the folder (NOT the file!) containing the # compile_commands.json file to use that instead of 'flags'. See here for # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html # # You can get CMake to generate this file for you by adding: # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) # to your CMakeLists.txt file. # # Most projects will NOT need to set this to anything; you can just change the # 'flags' list of compilation flags. Notice that YCM itself uses that approach. compilation_database_folder = '' if os.path.exists( compilation_database_folder ): database = ycm_core.CompilationDatabase( compilation_database_folder ) else: database = None SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] def DirectoryOfThisScript(): return os.path.dirname( os.path.abspath( __file__ ) ) def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): if not working_directory: return list( flags ) new_flags = [] make_next_absolute = False path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] for flag in flags: new_flag = flag if make_next_absolute: make_next_absolute = False if not flag.startswith( '/' ): new_flag = os.path.join( working_directory, flag ) for path_flag in path_flags: if flag == path_flag: make_next_absolute = True break if flag.startswith( path_flag ): path = flag[ len( path_flag ): ] new_flag = path_flag + os.path.join( working_directory, path ) break if new_flag: new_flags.append( new_flag ) return new_flags def IsHeaderFile( filename ): extension = os.path.splitext( filename )[ 1 ] return extension in [ '.h', '.hxx', '.hpp', '.hh' ] def GetCompilationInfoForFile( filename ): # The compilation_commands.json file generated by CMake does not have entries # for header files. So we do our best by asking the db for flags for a # corresponding source file, if any. If one exists, the flags for that file # should be good enough. if IsHeaderFile( filename ): basename = os.path.splitext( filename )[ 0 ] for extension in SOURCE_EXTENSIONS: replacement_file = basename + extension if os.path.exists( replacement_file ): compilation_info = database.GetCompilationInfoForFile( replacement_file ) if compilation_info.compiler_flags_: return compilation_info return None return database.GetCompilationInfoForFile( filename ) def FlagsForFile( filename, **kwargs ): if database: # Bear in mind that compilation_info.compiler_flags_ does NOT return a # python list, but a "list-like" StringVec object compilation_info = GetCompilationInfoForFile( filename ) if not compilation_info: return None final_flags = MakeRelativePathsInFlagsAbsolute( compilation_info.compiler_flags_, compilation_info.compiler_working_dir_ ) # NOTE: This is just for YouCompleteMe; it's highly likely that your project # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT. # try: # final_flags.remove( '-stdlib=libc++' ) # except ValueError: # pass else: relative_to = DirectoryOfThisScript() final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) return { 'flags': final_flags, 'do_cache': True }
function! WrapForTmux(s) if !exists('$TMUX') return a:s endif let tmux_start = "\<Esc>Ptmux;" let tmux_end = "\<Esc>\\" return tmux_start . substitute(a:s, "\<Esc>", "\<Esc>\<Esc>", 'g') . tmux_end endfunction let &t_SI .= WrapForTmux("\<Esc>[?2004h") let &t_EI .= WrapForTmux("\<Esc>[?2004l") function! XTermPasteBegin() set pastetoggle=<Esc>[201~ set paste return "" endfunction inoremap <special> <expr> <Esc>[200~ XTermPasteBegin() if exists('$ITERM_PROFILE') if exists('$TMUX') let &t_SI = "\<Esc>[3 q" let &t_EI = "\<Esc>[0 q" else let &t_SI = "\<Esc>]50;CursorShape=1\x7" let &t_EI = "\<Esc>]50;CursorShape=0\x7" endif end "******************************************************** " 通常性配置 * "******************************************************** "關閉vim一致性原則 set nocompatible "顯示行號 set number "設置在編輯過程當中右下角顯示光標的行列信息 set ruler "在狀態欄顯示正在輸入的命令 set showcmd "設置歷史記錄條數 set history=1000 "設置取消備份 禁止臨時文件的生成 set nobackup set noswapfile "設置匹配模式 set showmatch "設置C/C++方式自動對齊 set autoindent set cindent "開啓語法高亮功能 syntax enable syntax on "指定配色方案爲256色 set t_Co=256 "設置搜索時忽略大小寫 set ignorecase "配置backspace的工做方式 set backspace=indent,eol,start "選中高亮 set hls "高亮光標所在行 "set cul "cursorline "set cuc "set go= " 不要圖形按鈕 "color desert " 設置背景主題 color ron " 設置背景主題 "color torte " 設置背景主題 set guifont=Courier_New:h10:cANSI " 設置字體 "autocmd InsertLeave * se nocul " 用淺色高亮當前行 "autocmd InsertEnter * se cul " 用淺色高亮當前行 "set whichwrap+=<,>,h,l " 容許backspace和光標鍵跨越行邊界(不建議) " 光標移動到buffer的頂部和底部時保持3行距離 set scrolloff=3 " 老是顯示狀態行 set cmdheight=1 set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} set laststatus=2 " 啓動顯示狀態行(1),老是顯示狀態行(2) set foldenable " 容許摺疊 "set foldmethod=manual " 手動摺疊 "set magic " 設置魔術 "set guioptions-=T " 隱藏工具欄 "set guioptions-=m " 隱藏菜單欄 let g:indentLine_char = '┊' "啓動時不顯示幫助烏干達兒童提示 set shortmess=atI "設置在vim中可使用鼠標 set mouse=a "設置tab寬度 set tabstop=4 "設置自動對齊空格數 set shiftwidth=4 "設置退格鍵時能夠刪除4個空格 set smarttab set softtabstop=4 "將tab鍵自動轉換爲空格 set expandtab "設置編碼方式 set encoding=utf-8 "自動判斷編碼時 依次嘗試如下編碼 set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1 "檢測文件類型 filetype on "針對不一樣的文件採起不一樣的縮進方式 filetype indent on "容許插件 filetype plugin on "簡化+寄存器操做 set clipboard=unnamedplus "啓動智能補全 filetype plugin indent on cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%' "********************************************************* " vundle 配置 * "********************************************************* set rtp+=~/.vim/bundle/vundle/ call vundle#rc() " let Vundle manage Vundle Bundle 'gmarik/vundle' " My Bundles here: Bundle 'SuperTab' Bundle 'Vim-JavaScript' Bundle 'a.vim' Bundle 'c.vim' Bundle 'Align' Bundle 'L9' Bundle 'vim-javacompleteex' Bundle 'tpope/vim-fugitive' Bundle 'Lokaltog/vim-easymotion' Bundle 'Yggdroot/indentLine' Bundle 'rstacruz/sparkup', {'rtp': 'vim/'} Bundle 'ctags.vim' Bundle 'taglist.vim' Bundle 'The-NERD-tree' Bundle 'Syntastic' Bundle 'std_c.zip' Bundle 'FuzzyFinder' Bundle 'tpope/vim-commentary' Bundle 'tpope/vim-surround' Bundle 'Lokaltog/vim-powerline' Bundle 'Valloric/YouCompleteMe' Bundle 'Valloric/MatchTagAlways' "***************************************************** " MatchTagAlways配置 * "***************************************************** let g:mta_use_matchparen_group = 1 "***************************************************** " FuzzyFinder配置 * "***************************************************** map <leader>F :FufFile<CR> map <leader>f :FufTaggedFile<CR> map <leader>g :FufTag<CR> map <leader>b :FufBuffer<CR> "***************************************************** " taglist配置 * "***************************************************** "不顯示"press F1 to display help" let Tlist_Compact_Format=1 "窗口在左側顯示 let Tlist_Use_Right_Window=1 "只顯示當前文件的tags let Tlist_Show_One_File=1 "高亮顯示 let Tlist_Auto_Highlight_tag=1 "隨文件自動更新 let Tlist_Auto_Update=1 "設置寬度 let Tlist_WinWidth=30 "taglist窗口是最後一個窗口,則退出vim let Tlist_Exit_OnlyWindow=1 "單擊跳轉 let Tlist_Use_SingClick=1 "打開關閉快捷鍵 nnoremap <silent> <F3> :TlistToggle<CR> "******************************************************** " NERD_Tree 配置 * "******************************************************** "顯示加強 let NERDChristmasTree=1 "自動調整焦點 let NERDTreeAutoCenter=1 "鼠標模式:目錄單擊,文件雙擊 let NERDTreeMouseMode=2 "打開文件後自動關閉 let NERDTreeQuitOnOpen=0 "顯示文件 let NERDTreeShowFiles=1 "顯示隱藏文件 let NERDTreeShowHidden=0 "高亮顯示當前文件或目錄 let NERDTreeHightCursorline=1 "顯示行號 let NERDTreeShowLineNumbers=1 "窗口位置 let NERDTreeWinPos='left' "窗口寬度 let NERDTreeWinSize=31 "不顯示'Bookmarks' label 'Press ? for help' let NERDTreeMinimalUI=1 "快捷鍵 nnoremap <silent> <F2> :NERDTreeToggle<CR> "當打開vim且沒有文件時自動打開NERDTree autocmd vimenter * if !argc() | NERDTree | endif "只剩 NERDTree時自動關閉 autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif " 設置當文件被改動時自動載入 " set autoread "***************************************************** " YouCompleteMe配置 * "***************************************************** "leader映射爲逗號「,」 let mapleader = "," "配置默認的ycm_extra_conf.py "let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py' "按gb 會跳轉到定義 nnoremap <silent> gb :YcmCompleter GoToDefinitionElseDeclaration<CR> "打開vim時再也不詢問是否加載ycm_extra_conf.py配置 let g:ycm_confirm_extra_conf=0 "使用ctags生成的tags文件 let g:ycm_collect_identifiers_from_tag_files = 1 map <F4> : YcmDiags<CR> "***************************************************** " Syntastic配置 * "***************************************************** let g:syntastic_check_on_open = 1 let g:syntastic_cpp_include_dirs = ['/usr/include/'] let g:syntastic_cpp_remove_include_errors = 1 let g:syntastic_cpp_check_header = 1 let g:syntastic_cpp_compiler = 'clang++' let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libstdc++' "set error or warning signs let g:syntastic_error_symbol = '✗' let g:syntastic_warning_symbol = '⚠' "whether to show balloons let g:syntastic_enable_balloons = 1 "***************************************************** "C,C++ 按F5編譯運行 * "***************************************************** map <F5> :call CompileRunGcc()<CR> func! CompileRunGcc() exec "w" if &filetype == 'c' exec "!gcc % -o %<" exec "! ./%<" elseif &filetype == 'cpp' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'java' exec "!javac %" exec "!java %<" elseif &filetype == 'sh' :!./% endif endfunc "***************************************************** "C,C++的調試 F8 * "***************************************************** map <F8> :call Rungdb()<CR> func! Rungdb() exec "w" exec "!g++ % -g -o %<" exec "!gdb ./%<" endfunc "***************************************************** "新文件標題 * "***************************************************** "新建.c,.h,.sh,.java文件,自動插入文件頭 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()" ""定義函數SetTitle,自動插入文件頭 func SetTitle() "若是文件類型爲.sh文件 if &filetype == 'sh' call setline(1,"\#!/bin/bash") call append(line("."), "") elseif &filetype == 'python' call setline(1,"#!/usr/bin/env python") call append(line("."),"# coding=utf-8") call append(line(".")+1, "") elseif &filetype == 'ruby' call setline(1,"#!/usr/bin/env ruby") call append(line("."),"# encoding: utf-8") call append(line(".")+1, "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name : ".expand("%")) call append(line(".")+1, " > Author : zhoutk") call append(line(".")+2, " > Mail : zhoutk@189.cn") call append(line(".")+3, " > Created Time: ".strftime("%c")) call append(line(".")+4, " ************************************************************************/") call append(line(".")+5, "") endif if expand("%:e") == 'cpp' call append(line(".")+6, "#include<iostream>") call append(line(".")+7, "using namespace std;") call append(line(".")+8, "") endif if &filetype == 'c' call append(line(".")+6, "#include<stdio.h>") call append(line(".")+7, "") endif if expand("%:e") == 'h' call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H") call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H") call append(line(".")+8, "#endif") endif if &filetype == 'java' call append(line(".")+6,"public class ".expand("%:r")) call append(line(".")+7,"") endif "新建文件後,自動定位到文件末尾 endfunc autocmd BufNewFile * normal G "***************************************************** "代碼格式優化化 * "***************************************************** map <F6> :call FormartSrc()<CR><CR> "定義FormartSrc() func FormartSrc() exec "w" if &filetype == 'c' exec "!astyle --style=ansi -a --suffix=none %" elseif &filetype == 'cpp' || &filetype == 'hpp' exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1" elseif &filetype == 'perl' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'py'||&filetype == 'python' exec "r !autopep8 -i --aggressive %" elseif &filetype == 'java' exec "!astyle --style=java --suffix=none %" elseif &filetype == 'jsp' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'xml' exec "!astyle --style=gnu --suffix=none %" else exec "normal gg=G" return endif exec "e! %" endfunc "結束定義FormartSrc