Vim configuration C + + development environment __c++

Source: Internet
Author: User
Tags class definition function definition function prototype imap rewind set background


from:http://blog.csdn.net/klarclm/article/details/7932558






1. Install Vim and basic plugin



$sudo apt-get Install vim vim-scripts






2. Vim configuration file



Vim system configuration files under the/usr/share/vim and/etc/vim, we do not change the system configuration, only to change their user home configuration on the line. Enter your home directory, create a file named. VIMRC, and copy the following configuration to this file:





 "This line should is removed as it ensures that various options are" properly set to work with the vim-related
     Packages available in Debian. Debian.vim "Uncomment the next line to make vim more vi-compatible" NOTE:debian.vim sets ' nocompatible '.
    Setting ' compatible ' changes numerous options, so the other options should is set after Setting ' compatible '. Set Nocompatible "VIM5 and later versions support syntax.
    Uncommenting the "following enables syntax highlighting by default. If has ("syntax") syntax on "syntax highlighting endif colorscheme Ron" Elflord Ron Peachpuff default settings Color scheme, VIM's own color scheme is saved in the/usr/share/vim/vim72/colors directory "detect file type filetype on filetype plugin on" If Using a dark background within the editing area and syntax highlighting ' turn on ' this option as a.
    Nd=dark "Uncomment the following to have Vim jump"Reopening a file if has (" autocmd ") au bufreadpost * If line (" ' \ ") > 1 && line (" ' "") <= Line ("$ ") | EXE "normal! G ' \ ' "| endif "have Vim load indentation rules and plugins according to the detected filetype filetype plugin indent o N endif "The following are commented out as they cause vim to behave a lot" differently from regular Vi.

    They are highly recommended though. The "Set ignorecase" search mode ignores case "set Smartcase" if the search pattern contains uppercase characters, the ' ignorecase ' option is not used.
    Used only if you enter the search mode and open the ' ignorecase ' option. Set Autowrite "Automatically writes the content back to the file: If the file has been modified, at each: Next,: Rewind,: Last,: I,:p revious,: Stop,: Suspend,: Tag,:!,: Make, Ctrl] and
    ctrl-^ when the command is used: The buffer, Ctrl-o, Ctrl-i, ' {a-z0-9}, or ' {a-z0-9} ' command is transferred to another file. Set Autoindent sets automatic alignment (indentation): That is, the indentation value of each row is equal to the previous line; Noautoindent set smartindent smart Alignment set TabStop
   =4 sets the width of the tab (tab) Set softtabstop=4 sets the width of the Soft tab set shiftwidth=4 (Automatic) Indent 4 spaces Set Cindent "Set CINOPTIONS={0,1S,T0,N-2,P2S using the automatic indentation method of the C + + language," (03s,=.5s,>1s,=1s,:1s) setting up a C + + language Body Indent mode "set backspace=2" sets the backspace key to use set Showmatch "setting match mode, displaying matching parentheses set linebreak" whole word newline set            whichwrap=b,s,<,>,[,] "the cursor jumps from the beginning and end of the line to the other row to the" set hidden "Hide buffers when they are abandoned set mouse=a The Enable mouse usage (all modes) uses the mouse set number "Enable line numbers" to display row numbering set preview  Window "Identity Preview window set history=50" SET command history to 50 "History 50"--state line setting--Set laststatus=2 "Always displays the status line of the last window; 1 if the number of Windows is more than one, displays the status line of the last window; 0 does not display the last window's status line set ruler ruler, which displays the line number and column number of the cursor position, separated by commas. Each window has its own ruler. If the window has a status row, the ruler appears there.

    Otherwise, it appears on the last line of the screen. "--Command line Settings--set showcmd" command line display input command set showmode "command line displays vim current mode"--find setting--set I         Ncsearch "Input string displays the matching point set Hlsearch"This line should not be removed as it ensures that various options are
    "Properly set to work with the Vim-related packages available in Debian.
     debian.vim

    "Uncomment the next line to make Vim more Vi-compatible
    "NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
    "options, so any other options should be set AFTER setting 'compatible'.
    set nocompatible

    "Vim5 and later versions support syntax highlighting. Uncommenting the
    "following enables syntax highlighting by default.
    if has ("syntax")
      syntax on "syntax on
    endif
    colorscheme ron "elflord ron peachpuff default set color scheme, vim's own color scheme is saved in the / usr / share / vim / vim72 / colors directory

    "detect file type
    filetype on
    filetype plugin on

    "If using a dark background within the editing area and syntax highlighting
    "turn on this option as well
    set background = dark

    "Uncomment the following to have Vim jump to the last position when
    "reopening a file
    if has ("autocmd")
      au BufReadPost * if line ("'\" ")> 1 && line ("' \ "") <= line ("$") | exe "normal! g '\" "| endif
      "have Vim load indentation rules and plugins according to the detected filetype
      filetype plugin indent on
    endif

    "The following are commented out as they cause vim to behave a lot
    "differently from regular Vi. They are highly recommended though.

    "set ignorecase" ignore case in search mode
    "set smartcase" Do not use the 'ignorecase' option if the search pattern contains uppercase characters. Only used when entering search mode and turning on the 'ignorecase' option.
    "set autowrite" automatically writes the content back to the file: if the file has been modified, in each of :: next,: rewind,: last,: first,: previous,: stop,: suspend,: tag,:!,: make, CTRL -] And CTRL- ^ commands; use: buffer, CTRL-O, CTRL-I, '{A-Z0-9} or `{A-Z0-9} command to transfer to another file.
    set autoindent "Set automatic alignment (indentation): that is, the indent value of each line is equal to the previous line; use noautoindent to cancel the setting
    "set smartindent" smart alignment
    set tabstop = 4 "Set the width of tabs (tab keys)
    set softtabstop = 4 "Set softtabstop width
    set shiftwidth = 4 "(automatic) 4 spaces for indentation
    "set cindent" using C / C ++ auto-indentation
    set cinoptions = {0,1s, t0, n-2, p2s, (03s, =. 5s,> 1s, = 1s,: 1s "Set the specific indentation of C / C ++ language
    "set backspace = 2" set backspace available
    set showmatch "Set the match mode, showing matching brackets
    "set linebreak"
    set whichwrap = b, s, <,>, [,] "The cursor can jump to another line from the beginning and end of the line
    "set hidden" Hide buffers when they are abandoned
    set mouse = a "Enable mouse usage (all modes)"
    set number "Enable line number"
    "set previewwindow" identifies the preview window
    set history = 50 "set command history to 50"


    "--Status Line Settings--
    set laststatus = 2 "Always display the status line of the last window; set to 1 to display the status line of the last window when there are more than one window; 0 does not display the status line of the last window
    set ruler "ruler, used to display the line and column numbers of the cursor position, separated by commas. Each window has its own ruler. If the window has a status line, the ruler is displayed there. Otherwise, it is displayed on the last line of the screen .

    "--Command line settings--
    set showcmd "command line to display the entered command
    set showmode "command line shows the current vim mode

    "--find setting--
    set incsearch "Enter matching strings to display matching points
    set hlsearch

3. Ctags


Installation: $sudo apt-get install Ctags



After installation in the source root directory run $ctags-r, generate tags index file.



The basic usage of ctags in VI is as follows:



Ctrl +]: Jumps to the defined position of the label where the cursor is located



Ctrl + O: Back to previous label



Ctrl + T: forward a label



Ctrl + W +]: Opens a new view,view position for the previously defined position of the label






4. Manage VIM Plug-in---vim-addons



Installation: $sudo apt-get install Vim-addon-manager



View current plug-in status: $vim-addons status



We built the plugin subdirectory in our home directory to install the VIM plugin:



$CD ~



$mkdir. Vim



$cd. Vim



$mkdir Plugin



$mkdir doc



After you have established these directories, use the following command to install the appropriate plug-ins



$vim-addons Install [plugin]






5. Automatic completion--omnicppcomplete



Vim auto-complement can be realized through the plug-in Omnicppcomplete



Installation: $vim-addons install Omnicppcomplete



Configure Omnicppcomplete to include the following configuration in the Vim profile ~/.VIMRC:





"-omnicppcomplete setting-
    "Press F3 to complete the code automatically. Note that there can be no other characters after the mapping statement, including tab; otherwise, press F3 will automatically complete some garbled
    imap <F3> <C-X> <C-O>
    "Press F2 to complete based on keywords in the header file
    imap <F2> <C-X> <C-I>
    set completeopt = menu, menuone "Close the preview window during smart completion
    let OmniCpp_MayCompleteDot = 1 "autocomplete with.
    let OmniCpp_MayCompleteArrow = 1 "autocomplete with->
    let OmniCpp_MayCompleteScope = 1 "autocomplete with ::
    let OmniCpp_SelectFirstItem = 2 "select first item (but don't insert)
    let OmniCpp_NamespaceSearch = 2 "search namespaces in this and included files
    let OmniCpp_ShowPrototypeInAbbr = 1 "show function prototype in popup window
    let OmniCpp_GlobalScopeSearch = 1 "enable the global scope search
    let OmniCpp_DisplayMode = 1 "Class scope completion mode: always show all members
    "let OmniCpp_DefaultNamespaces = [" std "]
    let OmniCpp_ShowScopeInAbbr = 1 "show scope in abbreviation and remove the last column
    let OmniCpp_ShowAccess = 1


In Vim, use the following command to add tags



: Set Tags+=/usr/include/tags



Help document



: Help Omnicppcomplete






6. Hint function prototype Echofunc



Echofunc can prompt the current input function prototype on the command line



Download Address: http://www.vim.org/scripts/script.php?script_id=1735



After downloading, put the Echofunc.vim under the ~/.vim/plugin, restart VI



When you type the function name in VI, the input "(" prompts you on the command line, and if the function has multiple prototypes, press ALT +-and ALT + = "Forward and Backward"



Echofunc need tags file support, and when creating tags file to add options "--fields=+is": $ctags-R--fields=+is






7. Tag Browser taglist



Installation: $vim-addons install TagList



Configure TagList



Add the following configuration to the Vim profile ~/.VIMRC:





"--taglist setting-
    let tlist_ctags_cmd= ' Ctags '" because we are in the environment variable, so we can directly execute the Let
    tlist_use_right_window=1 " Let the window display on the right, 0 words is displayed on the left
    let tlist_show_one_file=0 "so that taglist can show multiple files at the same time a list of functions lets
    tlist_file_fold_auto_close=1" Non-current file, function list collapse hide let
    tlist_exit_onlywindow=1 "When TagList is the last partition window, automatically launch vim
    " whether to deal with Tags.1: processing; 0: Do not deal with let
    Tlist_process_file_always=1 "Real-time update tags let
    tlist_inc_winwidth=0

Open vim and enter the command ": tlist" to open/close the TagList window


Help document



: Help TagList






8. File browsing and Buffer manager Winmanager



Installation: $vim-addons install Winmanager



Configure Winmanager to include in the configuration file ~/.VIMRC:





"--winmanager setting--Let
    g:winmanagerwindowlayout= ' fileexplorer| TagList ' "Set the plugin we want to manage
    " let g:persistentbehaviour=0 "if all edit files are turned off, quit Vim
    


Use commands in VIM: Wmtoggle on/off Winmanager, because we have mapped in the configuration file, use directly: The VM can be turned on/off



<enter> or double-click to enter directory or open file



<tab> Enter the directory, or open the file in a new window



<F5> Refresh List



-Return to the previous level



Helping: Help Winmanager






9. Buffer Manager Minibufferexplorer



After you open multiple files in vim, you can use Minibufferexplorer to manage them



Installation: $vim-addons install Minibufexplorer



Configuration: Add the following configuration to the ~/VIMRC:





"--minibufferexplorer-let
    g:minibufexplmapwindownavvim = 1" Press CTRL+H/J/K/L, you can switch to the top and bottom window of the current window let
    g: Minibufexplmapwindownavarrows = 1 "Press CTRL + ARROW to switch to the top and bottom window of the current window let
    g:minibufexplmapctabswitchbufs = 1" The following two features are enabled: Ctrl+tab moves to the next buffer and opens in the current window; Ctrl+shift+tab moves to the previous buffer and opens in the current window; Ubuntu does not seem to support let
    g: Minibufexplmapctabswitchwindows = 1 "Enables the following two features: Ctrl+tab move to the next window; Ctrl+shift+tab to the previous window; Ubuntu doesn't seem to support let
    g: Minibufexplmodseltarget = 1    "Do not open the selected buffer in a window (such as a taglist window) that is not editable content

Common commands:


<Tab> move to previous buffer



<Shift-Tab> move to next buffer



<Enter> Open Cursor Buffer



D delete the cursor at buffer






10. Code Folding Fold



Add the following configuration to the Vim profile ~/.VIMRC:





"--fold setting--
    set Foldmethod=syntax" uses syntax highlighting to define a collapsed
    set foldlevel=100 "Do not automatically collapse code set foldcolumn=5 when starting Vim
    " Set the width of the collapse bar
Common commands:


Za open/Close the folding under the cursor



ZA loop turn on/off folding under cursor



Zo the folding under the open cursor



ZO loops Open all folds under the cursor



ZC Close the cursor under the collapse



ZC Loop closes all folds under the cursor



ZM closes all collapsed



ZR Open All Folding



Helping: Help fold






11. Project Directory Tree Manager project



Project is used to display the directory tree for the item, which is saved by default in the ~/.vimprojects file



Installation: $vim-addons Install Project



Project directory tree Generation:



A. Open vim, type the command:P roject, and the Project box appears on the left



B. Enter \c in command mode, and the information to create project will be filled in.






Quickfix command Set



Through the Quickfix command set, you can compile the program in Vim, if there are errors can jump directly to the wrong location to modify, and then recompile, accelerate the development speed



In the configuration file, add the following configuration:





"--QuickFix setting--
    " Press F6, execute make clean
    map <F6>: Make clean<cr><cr><cr>
    "Press F7 , execute the Make compiler and open the Quickfix window to display the compilation information
    map <F7>:make<cr><cr><cr>: COPEN<CR><CR >
    Press F8, the cursor moves to the row
    map <F8>:cp<cr> of the previous error
    , and the cursor moves to the row map of the next error F9
    <F9>: CN<CR >
    "The above mapping is to enable the above shortcut key in the Insert mode can also use
    IMAP <F6> <esc>:make clean<cr><cr><cr>
    IMAP <F7> <ESC>:make<CR><CR><CR>:copen<cr><cr>
    IMAP <F8> < esc>:cp<cr>
    IMAP <F9> <ESC>:cn<CR>

Common commands


: Make {arguments}



If you are traveling by <Enter> back to the Vim interface, type the following command to open the Quickfix window



: Cw[indow]



When you double-click a travel message, you automatically skip to the location where you are traveling



: Cn[ext] Next error position



: cp[revious] Previous error position



: Cfirst First Error



: Clast Last Mistake



: CC Details



: cl[ist] Error message overview



Helping: Help Quickfix






Cscope



Cscope is a tool similar to Ctags, but more powerful



Installation: $sudo apt-get install Cscope



To add a configuration to the configuration file ~/.VIMRC:





"-Cscope setting-
    if has ("cscope")
        set csprg = / usr / bin / cscope "specify the command to execute cscope
        set csto = 0 "Set the cstag command search order: 0 first find the cscope database and then the tag file; 1 first find the tag file and then the cscope database
        set cst "search both cscope database and tag files
        set cscopequickfix = s-, c-, d-, i-, t-, e- "Use QuickFix window to display cscope search results
        set nocsverb
        if filereadable ("cscope.out") "If the cscope database exists in the current directory, add the database to vim
            cs add cscope.out
        elseif $ CSCOPE_DB! = "" "Otherwise, as long as the environment variable CSCOPE_DB is not empty, add its specified database to vim
            cs add $ CSCOPE_DB
        endif
        set csverb
    endif
    map <F4>: cs add ./cscope.out. <CR> <CR> <CR>: cs reset <CR>
    imap <F4> <ESC>: cs add ./cscope.out. <CR> <CR> <CR>: cs reset <CR>
    "Map the Cscope search commands such as: cs find c to <C -_> c and other shortcut keys (press Ctrl + Shift +-first, and then press c shortly)
    nmap <C -_> s: cs find s <C-R> = expand ("<cword>") <CR> <CR>: copen <CR> <CR>
    nmap <C -_> g: cs find g <C-R> = expand ("<cword>") <CR> <CR>
    nmap <C -_> d: cs find d <C-R> = expand ("<cword>") <CR> <CR>: copen <CR> <CR>
    nmap <C -_> c: cs find c <C-R> = expand ("<cword>") <CR> <CR>: copen <CR> <CR>
    nmap <C -_> t: cs find t <C-R> = expand ("<cword>") <CR> <CR>: copen <CR> <CR>
    nmap <C -_> e: cs find e <C-R> = expand ("<cword>") <CR> <CR>: copen <CR> <CR>
    nmap <C -_> f: cs find f <C-R> = expand ("<cfile>") <CR> <CR>
    nmap <C -_> i: cs find i <C-R> = expand ("<cfile>") <CR> <CR>: copen <CR> <CR> 


To create a cscope library:



$cscope-RBQ



Add Cscope Library to vim: Open a file, type the command: CS add cscope.out,






The main function of the cscope is achieved by the FIND subcommand, using the following command



: CS Find c|d|e|f|g|i|s|t Name



0/s find this symbol



1/g find this definition



2/d find the function called by this function



3/C find functions that have called this function



4/t Find this string



6/e Find this egrep mode



7/f Find this file



8/i find files containing this file






Helping: Help If_cscop






14. Programming related common shortcut keys



% jump to paired parentheses



[[Jump to the beginning of the current or previous code block (function definition, class definition)



[Jumps to the end of the current block of code]



]] Jump to the beginning of the next-generation code block



[/Jump to the beginning of the comment (for/*/valid)



]/jump to end of comment (valid for/*/*)



GD jumps to the location of the first occurrence of the identifier in the current file, which can be used to jump to the definition of the variable



GD jumps to the position where the identifier first appears in the current function, and can be used to jump to the definition of a local variable



"Jump to the cursor last position, two"





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.