以前就買過java,c++的書,但是因爲懶惰,一直沒看,丟在那裏5年了。(以上廢話)。php
如今linux下尚未好的C++ IDE。網絡上的朋友都推薦eclipse和 code::block。粗略的看了下code::block,建工程,管理工程,功能不少,準備之後學習下。 學習C++,目前仍是用Vim比較好,輕量。各類豐富的插件支持。html
開發環境:java
系統:ubuntu 14.04LTS。python
工具:Vim7.4linux
編譯,連接,運行:g++c++
如今貼上Vim的配置:(這是這篇隨筆的主要內容,也是爲了我的保存配置。層次低,但願看官不要笑話。)git
set nocompatible " be iMproved filetype off " required! set rtp+=~/.vim/bundle/vundle/ call vundle#rc() " let Vundle manage Vundle " required! Bundle 'gmarik/vundle' " My bundles here: " " original repos on GitHub Plugin 'SirVer/ultisnips' Plugin 'honza/vim-snippets' Bundle 'tpope/vim-fugitive' Bundle 'Lokaltog/vim-easymotion' Bundle 'rstacruz/sparkup', {'rtp': 'vim/'} Bundle 'tpope/vim-rails.git' " vim-scripts repos Bundle 'L9' Bundle 'FuzzyFinder' " non-GitHub repos Bundle 'git://git.wincent.com/command-t.git' Bundle 'https://github.com/scrooloose/nerdtree' Bundle 'https://github.com/majutsushi/tagbar' Bundle 'https://github.com/tpope/vim-commentary' Bundle 'https://github.com/scrooloose/syntastic' Bundle 'https://github.com/altercation/vim-colors-solarized' Bundle 'https://github.com/kien/ctrlp.vim' Bundle 'https://github.com/Raimondi/delimitMate' Bundle 'https://github.com/tpope/vim-surround' Bundle 'https://github.com/vim-scripts/bufexplorer.zip' Bundle 'https://github.com/Valloric/YouCompleteMe' Bundle 'https://github.com/scrooloose/nerdcommenter' Plugin 'exvim/ex-tagbar' " Git repos on your local machine (i.e. when working on your own plugin) " Bundle 'file:///Users/gmarik/path/to/plugin' " ... filetype plugin indent on " required! " " Brief help " :BundleList - list configured bundles " :BundleInstall(!) - install (update) bundles " :BundleSearch(!) foo - search (or refresh cache first) for foo " :BundleClean(!) - confirm (or auto-approve) removal of unused bundles " " see :h vundle for more details or wiki for FAQ " NOTE: comments after Bundle commands are not allowed. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " GVIM自身的設置 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" language messages zh_CN.utf-8 " 解決consle輸出亂碼 syntax enable set background=dark colorscheme solarized "colorscheme blue " 灰褐色主題 "colorscheme delek "colorscheme evening "colorscheme murphy "colorscheme slate "colorscheme darkblue "colorscheme desert "colorscheme koehler "colorscheme pablo "colorscheme anotherdark "colorscheme elflord "colorscheme asmanian2 "colorscheme Dark "colorscheme peachpuff "colorscheme torte "colorscheme bensday "colorscheme zellner "colorscheme morning "colorscheme ron "colorscheme corn "colorscheme shine set guioptions-=T " 隱躲工具欄 "set guifont=DejaVu\ Sans\ mono\ 11 " 字體 && 字號 if has("gui_gtk2") set guifont=Bitstream\ Vera\ Sans\ Mono\ 12,Fixed\ 12 set guifontwide=Microsoft\ Yahei\ 12,WenQuanYi\ Zen\ Hei\ 12 endif set noerrorbells " 封閉錯誤提示音 set nobackup " 不要備份文件 set linespace=0 " 字符間插進的像素行數目 set shortmess=atI " 啓動的時候不顯示那個援助索馬里兒童的提示 set novisualbell " 不要閃爍 set scrolloff=3 " 光標移動到buffer的頂部和底部時保持3行間隔 set mouse=a " 能夠在buffer的任何地方 -> set selection=exclusive " 使用鼠標(相似office中 -> set selectmode=mouse,key " 在工做區雙擊鼠標定位) set cursorline " 突出顯示當前行 set nu " 顯示行號 set whichwrap+=<,>,h,l " 答應backspace和光標鍵跨越行邊界 set completeopt=longest,menu "按Ctrl+N進行代碼補全 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 文本格式和排版 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set list " 顯示Tab符,-> set listchars=tab:\|\ , " 使用一高亮豎線代替 set tabstop=4 " 製表符爲4 set autoindent " 自動對齊(繼續前一行的縮進方式) set smartindent " 智能自動縮進(以c程序的方式) set softtabstop=4 set shiftwidth=4 " 換行時行間交錯使用4個空格 set noexpandtab " 不要用空格代替製表符 set cindent " 使用C樣式的縮進 set smarttab " 在行和段開始處使用製表符 set nowrap " 不要換行顯示一行 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 狀態行(命令行)的顯示 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set cmdheight=2 " 命令行(在狀態行下)的高度,默覺得1,這裏是2 set ruler " 右下角顯示光標位置的狀態行 set laststatus=2 " 開啓狀態欄信息 set wildmenu " 加強模式中的命令行自動完成操縱 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 文件相關 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set fenc=utf-8 set encoding=utf-8 " 設置vim的工做編碼爲utf-8,假如源文件不是此編碼,vim會進行轉換後顯示 set fileencoding=utf-8 " 讓vim新建文件和保存文件使用utf-8編碼 set fileencodings=utf-8,gbk,cp936,latin-1 filetype on " 偵測文件類型 filetype indent on " 針對不一樣的文件類型採用不一樣的縮進格式 filetype plugin on " 針對不一樣的文件類型加載對應的插件 syntax on " 語法高亮 filetype plugin indent on " 啓用自動補全 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 查找 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set hlsearch " 開啓高亮顯示結果 set nowrapscan " 搜索到文件兩端時不從新搜索 set incsearch " 開啓實時搜索功能 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 實用功能 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 設置NerdTree map <F3> :NERDTreeMirror<CR> map <F3> :NERDTreeToggle<CR> "clang-complete let g:clang_complete_copen=1 let g:clang_periodic_quickfix=1 let g:clang_snippets=1 let g:clang_close_preview=1 let g:clang_use_library=1"let g:clang_user_options='-stdlib=libc++ -std=c++11 -I /usr/include/c++/4.9.2'
let g:clang_user_options='-fexceptions -I /usr/include -I /usr/local/include' let g:neocomplcache_enable_at_startup = 1 """"""""""""YCM"""""""""""""""""""" let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/.ycm_extra_conf.py' let g:ycm_collect_identifiers_from_tags_files = 1 let g:ycm_seed_identifiers_with_syntax = 1 let g:ycm_confirm_extra_conf = 0 let g:ycm_cache_omnifunc=0 let g:ycm_complete_in_comments=1 let g:ycm_min_num_of_chars_for_completion=1 let g:ycm_use_ultisnips_completer=0 let g:ycm_key_invoke_completion = '<S-Space>' "設置跳轉的快捷鍵,能夠跳轉到definition和declaration nnoremap <leader>gc :YcmCompleter GoToDeclaration<CR> nnoremap <leader>gf :YcmCompleter GoToDefinition<CR> nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR> "nmap <F4> :YcmDiags<CR> """""""""""""NERDCommenter"""""""""""""""""" let mapleader = "," " NERD_commenter.vim " http://www.vim.org/scripts/script.php?script_id=1218 " Toggle單行註釋/「性感」註釋/註釋到行尾/取消註釋 map <leader>cc ,c<space> map <leader>cs ,cs map <leader>c$ ,c$ map <leader>cu ,cu " UltiSnips 的 tab 鍵與 YCM 衝突,從新設定 let g:UltiSnipsExpandTrigger="<leader><tab>" let g:UltiSnipsJumpForwardTrigger="<leader><tab>" let g:UltiSnipsJumpBackwardTrigger="<leader><s-tab>" """"""""""""""""""tagbar"""""""""""""""""""""""""""" nmap <F4> :TagbarToggle<CR> """""""""""""""""""編譯和運行"""""""""""""""""""""""""""""""" " <F5> 編譯和運行C map <F5> :call CompileRunGcc()<CR> func! CompileRunGcc() exec "w" exec "!gcc % -o %<" exec "! ./%<" endfunc "< F6> 編譯和運行C++ map <F6> :call CompileRunGpp()<CR> func! CompileRunGpp() exec "w" exec "!g++ % -o %<" exec "! ./%<" endfunc """""""""""""""""""代碼塊"""""""""""""""""""""""""""""""" " Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe. let g:UltiSnipsSnippetsDir = '~/.vim/bundle/vim-snippets/UltiSnips' let g:UltiSnipsSnippetDirectories = ['UltiSnips'] let g:UltiSnipsExpandTrigger="<c-j>" let g:UltiSnipsJumpForwardTrigger="<c-b>" let g:UltiSnipsJumpBackwardTrigger="<c-z>" "let g:UltiSnipsEditSplit="vertical"
ycm的配置文件: github
# 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', '-stdlib=libc++', # ...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', # This path will only work on OS X, but extra paths that don't exist are not # harmful '/System/Library/Frameworks/Python.framework/Headers', '-isystem', '../llvm/include', '-isystem', '../llvm/tools/clang/include', '-I', '.', '-I', './ClangCompleter', '-isystem', './tests/gmock/gtest', '-isystem', './tests/gmock/gtest/include', '-isystem', './tests/gmock', '-isystem', './tests/gmock/include', '-isystem', '/usr/include', '-isystem', '/usr/include/c++/4.9.2', ] # 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 }
開發中,代碼補全和快速插入代碼塊,這兩個是必用的。誰也不想把時間花費在敲一些垃圾代碼上。配置中使用YCM來補全代碼,json
UltiSnips來快速插入代碼塊。之後插件會慢慢加入。
人人都說Vim是神器。可我用起來很是艱難。常常裝了個插件各類問題,處理插件的問題,耗費大量的時間。我常常在懷疑是否本身選對了編輯器。我喜歡Vim的快捷鍵來編輯代碼。可因爲年代久遠,各類插件多而不全。我以爲Vim只適合用於學習C++的開發,讓它來創建工程什麼的。。。。仍是不要想了。老老實實用Eclipse和CB了。
插入一段代碼,來開始個人C++之路:
開發路上,你我同行。。。