[Accumulate by bit] Use Vim (1) (fromqq)

Source: Internet
Author: User
Source: success,

1) the view of all windows is saved in the session information, and global settings are added.
2) The viminfo information contains the command line history, search string history, input line history, and non-empty register content), file location mark, recent search/replacement mode, buffer list, global variables, and other information. Suppose Vim opens three windows: vsplit, split, and split. Then n F1, N F2, N F3
After opening these files, you do not need to re-load them one by one to keep the current state when you start Vim the next time. This is a stupid method, for example, the following steps: 1. Save the session and status
: Cd src "switch to the/home/easwy/src/vim70/src directory
: Set sessionoptions-= curdir "Remove curdir from session Option
: Set sessionoptions + = sesdir "add sesdir to session Option
: Mksession vim70.vim "Create a session file
: Wviminfo vim70.viminfo "Create a viminfo File
: QA "Exit Vim 2. Resume session and status
At the next startup, any VI F1, and then
: Source ~ /Src/vim70/src/vim70.vim 'load the session file
: Rviminfo vim70.viminfo 'reads the viminfo file ########### 20090310 ########### small skills: 1. file positioning: move the cursor to src/main. "fcntl. H ", and then press" GF". Enabled, VIM opened the/usr/include/fcntl. h file! Now we press" CTRL-^"Back to the position just now, the cursor is still positioned in line 22nd" fcntl. H ", and then press" CTRL-W F". Aha, this time Vim opened a horizontal separation window in which/usr/include/fcntl. H is opened. 2. Update. vimrc: After vimrc is changed, run: ": Source ~ /. Vimrc "will be updated to the. vimrc display without restarting. 3. session files of yesterday (20090309), if ": Source
After vim70.vim ", the system will automatically find and execute the file name as the session file name to remove the suffix (not necessarily. Vim) and add the content in the 'X. Vim 'file. For example
Execute vim70x. Vim (if any) content (such as "set nu ). 3. Use the tag to locate a function. 1) enter the project directory and enter $ ctags-R./to generate the Tag file of the current directory file. (Then go to the corresponding directory. In vim, ": Set tags = tags" "sets the tags option to the tags file in the current directory.) 2) use tags to open a file in the current directory, for example, hello. h has a printhello () function, so: the cursor locates at printhello, enter: Ctrl-] "to jump to the label under the current cursor, this will jump to hello. file C and go to the printhello function definition.
The CTRL-T "jumps to the earlier tag in the tag stack, which is equivalent to the" back "function and returns to hello. in addition to the hfile: Tag {ident} "jumps to the specified tag. For example,": Tag main "jumps to the definition of the main function.
: Tags "display tag stack ########### 20090311 ###### 1. Vim files are viewed before vim 7.0, the file browsing function is provided by explorer. provided by the vim plug-in. In Vim 7.0, this plug-in is netrw. replace the vim plug-in.

Netrw. Vim is the standard plug-in of VIM. It has been released along with vim and does not need to be installed.

Now let's try the vim file function. When you use Vim to open a directory, VIM will automatically call netrw. the Vim plug-in opens the directory (from the operating system perspective, the directory is actually a special file ). For example, run the command in Vim": E ~ /Src

This window is similar to the file manager. You can create, delete, and rename a file or directory. When you press enter on a directory, it will enter the directory. When you press enter on the file, use Vim to open the file. You can change the sorting method and style, hide the directory or file (which is not displayed in the preceding window), and so on.

<F1> Show Help
<CR> If the cursor is a directory, enter the directory. If the cursor is a file, use Vim to open the file.
-Return to the parent directory
C. Switch the current working directory of VIM to the directory being browsed.
D. Create a directory.
D. delete a file or directory.
I switch Display Mode
R: Rename the file or directory
S select sorting method
X custom browsing method. Use the program you specified to open the file.
2. Enter ": sexplore !" A vertical window is opened to display the directory of the current file (horizontal without an exclamation point:
: Vnew (create a file in the new window),: vsplit XXX (file name to be opened),: Split XXX (file name to be opened) All files can be directories.
3. Enter ": ls" to display the files in the Current Buffer. Press n CTRL ^ or ": Buffer N" to switch to the nth buffer.
##########20090312############
1. The main idea of quickfixquickfix mode is to save a location list and provide a series of commands to redirect to this location list.
For most projects that use makefile, Vim's default setting "make" can already meet the requirements. If your project needs to be compiled with a special program, you need to modify the value of the 'makeprg' option.
For example, for hello. C, set the command for executing make. Note that space escaping is required,
": Set makeprg = gcc/-wall/-ohello/Hello. c", and then execute ": Make" to compile. Vim will
Call the command defined by the 'makeprg' option to compile and redirect the compilation output to a temporary file. When an error occurs during compilation,
Vim will read the error information from the temporary files above, form a quickfix list based on the information, and jump to the place where the first error occurs.
You can enter the ": CC" command. Vim will display this information more times, or simply use the ": CW" command to open a quickfix window,
Display All error information.

Frequently Used commands in quickfix mode include:
: CC: detailed error message (: Help: CC)
: CP jump to the previous error (: Help: CP)
: CN jump to the next error (: Help: CN) or press enter on the corresponding row of quickfix list.
: CL: list all errors (: Help: CL)
: CW if an error list exists, open the quickfix window (: Help: CW)
: Col to the previous old Error List (: Help: COL)
: Cnew to a newer Error List (: Help: cnew)
For more commands and more detailed explanations of these commands, see the manual.
If you want to open an error file in a separate window, see the value of the 'switchbuf' option.
2. Auto-completion:
In addition to intelligent completion, the most common completion method should be CTRL-N and CTRL-P completion. They will be in the current buffer zone, other buffer zones, and
Search for words starting with the keyword before the cursor in the header file of the current file. Intelligent completion cannot complete local variables, while CTRL-N and
CTRL-P completion can be very good competent. For example, output the character "Pa" and then press CTRL-P, VIM will list all
Configuration function to choose, then click the CTRL-P, select the first project, that is, I want to enter "parmp ". Our first input
CTRL-P is to complete, the second input of the CTRL-P is in the drop-down menu to select up, the meaning of the two is different. We know that,
CTRL-P general meaning is up, so CTRL-P is up to search to complete, and CTRL-N is down to search to complete, in
Different shortcut keys can be used in the same scenario to accelerate the completion speed. Complete time with CTRL-N and CTRL-P, control Vim with the 'complete' Option
Where to find the complete content. For example, for larger software projects, file inclusion relationships are complex if CTRL-N and CTRL-P are supplemented
It takes a long time to search for the contained header file. At this point, you can remove the 'I' tag in the 'complete' option, so that the CTRL-N and
CTRL-P completion will not be found in the header file, the speed will be much faster; of course, the disadvantage is that you can not find some content in the file to supplement
All. Other completion methods in VIM include:
 
Full CTRL-X CTRL-L
CTRL-X CTRL-N Based on the keywords in the current file
CTRL-X CTRL-K Based on dictionary
CTRL-X CTRL-T Based on synonym dictionary
CTRL-X CTRL-I Based on keywords in header files
Complete CTRL-X by TAG Ctrl-]
Complete file name CTRL-X CTRL-F
Complete macro definition CTRL-X CTRL-D
Complete Vim command CTRL-X CTRL-V
User-Defined completion mode CTRL-X CTRL-U
Spelling suggestion CTRL-X CTRL-S
For example, when we press the CTRL-X CTRL-F, VIM will bring up a drop-down menu that shows the optional directories and files under the current directory.
############20090314###############
Mobile:
1, the upper and lower left and right move the window position command, is CTRL-W H/J/k/L (: Help CTRL-W_H,...). Note that H, J, K, and l are in uppercase.
2. In vim, Pageup and Pagedown can also be used. We usually useCTRL-BAndCTRL-FTo flip pages,CTRL-BAnd
CTRL-FYou can also add a number to indicate the number of pages that are up or down.
3. Jump: the command"Gg"Move to the first line of the file, and the command"G"Move to the last row of the file. Jump to the first line of the file, just enter
"1234g "or": 1234"
You can also jump by percentage. For example, if you want to jump to the center of the file, enter"50%"If you want to jump to section 75%, enter"75%".
Lost your position, then use"CTRL-G"Command to view your location and files.
4. fast intra-row movement. You can use the F, T, f, and t commands. For example ,"FX"To move the cursor to the first 'X' character on the right. "F"Life
To move the cursor to the specified character on the left ,"TX"It will move to the front of the first 'X' character on the right of the cursor. "T"Life
It is"T"The reverse version of the command. After it moves to the specified character on the right of the cursor, you can use a number before the command ,"3fx"Indicates moving to light
Mark the 3rd 'X' characters on the right .";"The command repeats the previous F, T, F, t commands, and","The command repeats the previous input in the opposite direction.
F, T, F, t command. Before these two commands, you can use numbers to represent multiples.

In vim, the command to move to the beginning of a line is very simple, that is"0", This is the number 0, not the uppercase letter O. The command to move to the end of the line is"$"

 

There is also a command"^", Which can be used to move to the first non-blank character at the beginning of the line.

 

The h/m/L key enables the cursor to jump to the top, middle, and bottom of the current window and stay on the first non-null character. Add one

 

Number of rows from the top and bottom of the window

 

Move the top, middle, or bottom of the window relative to the cursor's page :"ZT","ZZ"And"ZB".

 

5. Search: Enter"/"Enter the string you want to query, and press enter to jump to the First Matching place.

 

"? "Perform reverse lookup. Command"N"Repeat the last search command, while the command"N"Repeat the last SEARCH Command, except that

 

Search in the opposite direction. Use"Q /"And"Q? "Command to open a new window at the bottom of the vim window, which will list your query calendar

 

History Records

#################### 20090316 #################

About replacement

1. Input: S/thee/the <press enter>. Note that this command only changes the first match of the row where the cursor is located.
String.

2. Input: S/thee/The/g to replace the matching string of the entire row.

3. Enter #, # S/old/new/g to replace each matching string (#, # indicates the row number of the two rows ).

4. Enter % S/old/new/g to replace each matching string in the entire file.

5. When performing full-text replacement, ask the user to confirm that C option is required for each replacement. Please enter % S/old/new/GC and the rest will not be repeated.

6. When searching, set the IC option (IC is the abbreviation of the first letter that ignores case ignore case in English), that is, input: Set IC

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.