Vim configuration (c + +) __c++

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

Integration Excerpt Reference: http://blog.csdn.net/wooin/article/details/1858917

http://blog.csdn.net/fbfsber008/article/details/7044723

http://blog.csdn.net/deutschester/article/details/5750989

Http://blog.chinaunix.net/uid-23089249-id-2855999.html


Some of the commands that VIM uses are put here for my memo:

% Jump to paired parentheses to
[[ Jumps to the beginning of the code block (but requires that ' {' must have a separate line in the code block)
Gd Jump to the definition of a local variable
'' Jumps to the point where the cursor was last docked, two ', not one ' (keyboard 1 and the key beside the carriage return)
Mx Set bookmark, x can only be a A-Z 26 letters
' X Jump to Bookmark ("'" is the key to the left of 1)
> Increase indentation, "x>" means to increase the indentation of the following X lines
< Reduce indentation, "x<" means to reduce the indentation of the following X lines

Include header file: Press the GF key to enter the corresponding header file, back can Ctrl+o

Set by yourself are:

f3 paste does not shrink close

f4 generate Cscope database and add to Vim

Press F5 to regenerate the tag file, cscope the database, and update the TagList

f6 make clean

F7 Make

F8 on Quickfix the previous error CP jump

F9 the next error in Quickfix CN jump

F12. H and. C. cpp file switching

ctr+w + "S.G.C.T.E.I.F.D" Cscope shortcut keys

ctr+b function prototype prompts the previous

The ctr+d function prototype prompts the next

TG taglist window display or not

WM Winmanager window display or not

QF Quickfix window display or not

Collapse Shortcut za Open or close a collapsed Zi turn on or off all collapsed

Ctr+o jump, ctr+t back jump

--------------------------------------------------------------------------------------------------------------- -------------------

Press CTRL + V to enter visual mode, and you can change the selection by the top and bottom of the keyboard

ctrl+w+w in Code area and TagList window area

Switch between files (one window, but multiple files open) Ctrl+6: Next file

split screen, window file adjustment : http://www.2cto.com/os/201412/358384.html, http://www.2cto.com/os/201307/229329.html


The visualization mode can be divided into the following three types: the character visualization mode entered with the V command (characterwise visual modes). The text selection is in characters. Row visualization mode entered with the V command (linewise visual modes). Text selection is in the behavior unit. Block Visualization (blockwise visual mode) entered with Ctrl + V. You can select the text within a rectangle.

Multi-line Comment:

1. Enter the command line mode, press CTRL + V to enter Visual block mode, and then press J, or K to select multiple rows, marking the lines that need to be commented

2. Capitalize the letter I, then insert the annotation, for example//

3. The ESC key will be fully commented


To cancel multiple-line comments:

1. Enter command line mode, press CTRL + V to enter Visual block mode, and select the number of columns horizontally by letter L, for example///You need to select 2 columns

2. Press the letter J, or K to select the annotation symbol 3. Press D to cancel all comments

Edit in Visual mode

In visual mode, we can perform various editing operations. If the D command deletes the highlighted text, the D command deletes a row, even if only some of the text in the line is highlighted. Similarly, the Y command copies the highlighted text, and the y command copies the entire row. The C command removes the highlighted text and enters edit mode, while the C command deletes one line of text and enters the edit state.

For the highlighted text block, we can use the command ~ for case conversion.

use command > Add indent, or reduce indent with command <.
I. . VIMRC BASIC Configuration

Vim ~/.VIMRC

Add the following content

Set nocompatible set Nu
FileType on
Set history=1000
Set Background=dark
Syntax on
Set Autoindent
Set Smartindent
Set tabstop=4
Set shiftwidth=4
Set Showmatch
Set guioptions-=t
Set VB t_vb=
Set ruler
Set Nohls

Set Incsearch


The following configuration is transferred from: http://blog.chinaunix.net/uid-23089249-id-2855999.html

"This line should is removed as it ensures that various options are" properly set to work with the vim-related Packa
 Ges AvailableIn 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 set color scheme, VIM with  The 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 The editing area and syntax highlighting ' turn on ' this option as down set Background=dark ' uncomment the following to H Ave 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 accordingto" 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. 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 Set the width of the tab (tab) Set softtabstop=4 sets the width of the Soft tab set shiftwidth=4 the 4-space set cindent used by the (automatic) indent The automatic indent mode for C + + languages set Cinoptions={0,1s,t0,n-2,p2s, (03s,=.5s,>1s,=1s,:1s "Set backspace=2" setting backspace key for the specific indentation mode of A/C + + language Available set SHowmatch "Set match mode, display matching parentheses set linebreak" whole word newline set whichwrap=b,s,<,>,[,] "the cursor can jump to another line from the beginning and end of the line" set Hidd En "Hide buffers when they are abandoned set mouse=a ' Enable mouse usage (all modes)" uses the mouse to navigate, select (when certain characters are selected, Vim in the copy Press "Y", paste the "P", if you want to copy to other places, first hold down SHIFT and then use the mouse to select, loosen shift This is the right health menu in the Copy option, or copy the option when the gray, can not use the set number "Enable line Number "Show line Numbers" set Previewwindow "Identity Preview window set history=50" SET command history to 50 "History 50"--state line Settings-SE T laststatus=2 "always shows the state line of the last window; set to 1 when 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 Incsearch "       The input string shows the matching point set Hlsearch


--------------------------------------------------------------------------------------------------------------- -----

two. Ctags installation, configuration and use

Ctags is used to generate symbols to implement jumps

Yum Install Ctags

Add "--ctags setting--" in ~/.VIMRC
"Press F5 to regenerate the tag file and update taglist
Map <F5>:!ctags-R--c++-kinds=+p--fields=+iaS--extra=+q.<CR><CR>:TlistUpdate<CR>
IMAP &LT;F5&GT;&LT;ESC&GT;:!CTAGS-R--C++-KINDS=+P--FIELDS=+IAS--EXTRA=+Q.&LT;CR&GT;&LT;CR&GT;:TLISTUPDATE&LT;CR >
Set Tags=tags
Set Tags+=./tags "Add current directory ' s generated tags file
Tag Command usage:
CTRL +] jumps to the label of the word under the current cursor
Ctrl+o returns the previous label
Ctrl+t returns the previous label
: Tag TagName jumps to TagName label
The above command displays the label in the current window, the file in the current window replaces the package label file, and the current window cursor jumps to the label position. If you do not want the label to appear in the current window, you can use the following command:
: Stag TagName New window displays TagName label, cursor jumps to label
Ctrl+w +] New window displays the label of the word under the current cursor, and the cursor jumps to the label
When a label has more than one match (the function (or method in the class) is defined multiple times), the ": Tags" command jumps to the first place. If there is a match in the current file, it will be used first.
You can use these commands to move between matching labels:
: TFirst to first match
: [Count]tprevious forward [count] match
: [Count]tnext back [count] Match
: Tlast to last match
or use the following command to choose which one to jump to
: Tselect TagName
When you enter the above command, VIM will show you a list of choices. You can then enter the matching code to jump to (in the first column). Other column information lets you know where the label is defined.
The following command displays the label in the preview window
:p tag TagName Preview window displays TagName label, cursor jumps to label
Ctrl+w +} Preview window displays the label of the word under the current cursor, and the cursor jumps to the label
:p Close closes the preview window
:p edit file.h Editing the file file.h in the preview window (useful when editing a header file)
:p Search Atoi Find the current file and any words in the containing file and display the match in the preview window, which is useful when you are using a library function without a label file.
three. TagList

TagList is listed in the symbol in the window, convenient for global preview, jump

Download TagList installation package after decompression in the inside of the Taglist.vim and Taglist.txt respectively in the ~/.vim/plugin and ~/.vim/doc directory

In Vim

: Helptags ~/.vim/doc

: Help Taglist.txt

Add in ~/.VIMRC

Let Tlist_ctags_cmd = '/usr/bin/ctags '   "set Linux system Ctags program position let
tlist_show_one_file=1    " does not display multiple files at the same time tag, Show only the current file let
tlist_exit_onlywindow=1  "If the TagList window is the last window, then quit vim let
Tlist_use_right_window = 1         " Display the TagList window in the right window
"let tlist_use_singleclick= 1    " By default, when you double-click a tag, it jumps to the location of the tag definition let
tlist_auto_open=1    "After starting vim, automatically open the TagList window let
tlist_process_file_always=1  " TagList always parse the tag in the file, whether the TagList window has not been opened
let tlist_file_fold_auto_close=1 "at the same time display multiple files in the tag, you can make taglist only display the current file tag, the other file tag is folded up

nmap TL: tlisttoggle<cr>         "Press T L turn on or off taglist


In the TagList window, you can use the following shortcut keys :


<CR> jump to the position defined by tag under the cursor, double-click this tag function with the mouse also
O in a newly opened window display the cursor under the tag
<Space> (spaces) display the cursor under the prototype definition of tag, in vim
U update tag in taglist window
s to change the sort, and to sort by name and by order of occurrence
x taglist window zoom in and out, easy to see longer tag
+ Open a folded, with Zo
-Fold the tag together with the ZC
* Open all folds, with ZR
= Fold all the tags together with the ZM
[[Skip to previous file
]] jumps to the last file
Q Close TagList window
<F1> Show HelpFour. Resource Directory Winmanager

Download and unzip the winmanager.zip in the ~/.vim directory

Now add the next two sentences to your ~/.VIMRC.

"Let G:winmanagerwindowlayout= ' fileexplorer| TagList ' "Will taglist and wm up and down split screen
Nmap wm:wmtoggle<cr> "directly press W m to show WM
V: Installation of Cscope

Cscope is more powerful than ctags, can be a symbol jump, you can find references in the project

First, add a sentence to the ~/VIMRC:

: Set cscopequickfix=s-,c-,d-,i-,t-,e-
This is whether you want to use the Quickfix window to display cscope results

Install Cscope:
If you have a cscope command (Ctrl+d exit) in your system, you can skip this little segment if you don't
On Cscope's homepage: http://cscope.sourceforge.net Download a source pack, unzip and compile the installation:
#./configure
# make
# make Install//requires root permission

Edit VIMRC Add:

Map <F4>:!find. -type F > cscope.files<cr><cr>:!cscope-rbq<cr><cr>: cs Add cscope.out<cr><cr>
IMAP <F4> <ESC>:!find. -type F > Cscope.files<cr><cr>:!cscope-rbq<cr><cr>

The main function of Cscope is realized by the same subcommand "find".
The use of "Cscope find":
CS Find C|d|e|f|g|i|s|t Name

0 or S Find this C symbol (you can skip annotations)
1 or G Find this definition
2 or D Find the function called by this function
3 or C Find functions that call this function
4 or T Find this string
6 or E Find this egrep mode
7 or F Find this file
8 or I Find files that contain this file

It's annoying to have to enter a long list of commands every time you look up, Cscope's help manual recommends the use of shortcuts, and here's one, which I use, add the following to ~/.VIMRC, and restart Vim:
Nmap <c-w>s:cs Find S <c-r>=expand ("<cword>") <CR><CR>
nmap <c-w>g:cs Find G & Lt C-r>=expand ("<cword>") <CR><CR>
nmap <c-w>c:cs find C <c-r>=expand ("<cword > ") <CR><CR>
nmap <c-w>t:cs find T <c-r>=expand (" <cword> ") <CR><CR>
nmap <c-w>e:cs Find e <c-r>=expand ("<cword>") <CR><CR>
nmap <c-w>f:cs Find F <c-r>=expand ("<cword>") <CR><CR>
nmap <c-w>i:cs Find I <c-r>=expand (" <cfile> ") <CR><CR>
nmap <c-w>d:cs find D <c-r>=expand (" <cword> ") <CR> <CR>

When used, hold the cursor over the object you want to find, press <c-w>g, press "Ctrl+w", and then press "G" soon, and you will find the definition of the object.


It is strange that this sentence:
Nmap <c-w>i:cs Find I ^<c-r>=expand ("<cfile>") <CR>$<CR>
I can't work in my vim, but I change it to:
Nmap <c-w>i:cs Find I <c-r>=expand ("<cfile>") <CR><CR>

Other features of cscope you can learn by yourself through the Help manual

Reset: Reinitialize all connections.
Usage: CS Reset Six. QuickFix window

Cscope called this window, this window lists the query results of the command, the user can select from the window of each result to view, this window is called "QuickFix" window, formerly a Vim plug-in to, but now the standard plug-in vim, You do not have to install, the main function of the Quickfix window is to see the function: Output some alternative results, can be many command calls, more detailed introduction and use of the following command to open the Quickfix manual to learn it:
: Help Quickfix

If you enter in VIM: Make compile error, you can pass: CW or in Copen This window to display positioning error

"--QuickFix setting--
"Press F6 to perform make clean
Map &l

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.