Linux C Programming (1) VIM and GCC commands

Source: Internet
Author: User
Tags first string

1. Enter the following command to start VI:

      (1) VI: Do not specify a file name, you will need to specify a filename when saving it.       (2) VI file name: The file can be either existing or new.       (3) vi +n file name: Enter VI, the cursor stops at the beginning of the nth line.       (4) vi + file name: Enter VI, the cursor stops at the beginning of the last line of the file.       (4) vi +/string file name: Enter VI, the cursor stops at the first string where the row. 2. Save the file in VI and exit:      (1) W file name: Saves the contents of the current file in a new file specified by "file name" and generates an error if the file already exists.       (2) w! File name: Saves the contents of the current file in a new file specified by file name, overwriting the original file if it already exists. 3. Cursor Movement:      (1) NW: Right shift n words, n is a number, the cursor is at the top of the nth word.       (2) W: move 1 words to the right, and the cursor is at the beginning of the next word.       (3) NB: Shift left n characters, n is number, and the cursor is at the top of the nth word.       (4) B: Move left 1 words, the cursor is at the beginning of the next word.       (5) (: Move to the beginning of the sentence, if you are already at the beginning of the sentence, move to the beginning of the previous sentence.)       (6)): Move the first sentence of the next sentence.       (7) {: Move to the beginning of paragraph of this paragraph, if it is already in the beginning of the paragraph, move to the beginning of the previous paragraph.       (8) 1G: Move to the beginning of the first voyage of the file; G: Move to the beginning of the last line of the file; NG: Moves to the beginning of the nth row of the file.       (9) <ctrl>+g: reports where the cursor is located. 4. Deletion of the text:      (1) DW: Delete A word in the clerical position of the cursor; NDW: Deletes the n characters from the beginning of the cursor.       (2) DB: Deletes a word before the cursor; NDB: Deletes the first n characters from the cursor.   &NBSP;   (3) D0: Removes all characters from the previous character to the beginning of the cursor.       (4) d$: Removes all characters from the cursor to the end of the line.       (5) d (: Removes all characters from the beginning of the current character to the first sentence.       (6) d): Removes all characters from the beginning of the current period character to the end of a sentence.       (7) d{: Removes all characters from the beginning of the current character to the top of the paragraph.       (8) d}: Removes all characters from the beginning of the current character to the short tail. 5. Text find and replace:      (1)? String<enter>: Find string       (2): s/old/new: Replace old with new in the current line and replace it only once.       (3): s/old/new/g: Replace old  with new in current line     (4): 1,10s/old/new/g: Replace old  with new on 1~10 line     (5): 1, $s/old/new/g: replace Old6 with new in the entire file. Copy and paste text       (1) YW: Copy the character from the cursor position to the end of the word into the buffer       (2) NYW: Copies the n characters starting at the cursor position into the buffer     & nbsp; (3) YB: Copy a WORD from the cursor to the left       (4) NYB: Copy n characters from the cursor to the left       (5) y0: Copy all characters from the previous character of the cursor to the beginning of the start   & nbsp   (6) y$: Copy all characters from the beginning of the cursor to the end of the line       (7) NP: Inserts the copied text after the cursor position, replicates n times       (8) NP: Inserts the copied text in front of the cursor position, replicating n times. 7. Naming rules for variables under Linux:      (1) Variable names must be meaningful and accurate;      (2) not recommended for case mixing;      (3) in case of loss of meaning, try to use a shorter variable name.       (4) The type of the variable is not represented by the Hungarian nomenclature.       (5) The function name should begin with a verb because the function is a set of statement blocks with a specific function;      (6) Avoid using global variable  8 as much as possible. The GCC compiler can be divided into 4 stages:      (1) preprocessing (pre-processing)       pre-processing stage, input C language source files, usually *.c, mainly processing #ifdef, # Include and # define preprocessing commands. This phase typically generates an intermediate file *.i. The command is:    &NBSP;GCC-E test.c-o test.i      (2) compilation (compling)       During the compile phase, the intermediate file is entered *.I , build assembly language file *.s after compiling. The command is:     gcc-s test.i-o test.s      (3) assembly (assembling)       in the assembly phase, the input assembly file * . s converted to binary machine code *.O, whose commands are:     gcc-c test.s-o test.o      (4) Link (linking)       in link Stage the input binary machine code file *.S with other machine code files and library files into an executable binary code file with commands:    &NBSP;GCC test.o-o test      Finally, the executable file test is generated.       can be simplified to: gcc test.c-o test9. GCC compiles multiple source files with the command:     gcc-o test testmain.c other1.c other2.c      The command compiles 3 source files at the same time, and finallyGenerates an executable program test.       NOTE: When generating an executable program, a program must have only one main function in all compiled and connected source files, whether it is a single source file or multiple source files. Options for GCC:      (1)-C: Compile only, do not link to executable file, compiler only generated by input. C as suffix source code file. O is the suffix of the target file, usually used to compile a subroutine file that does not contain the main program.       (2)-G: Generate the symbolic information necessary for the debugger gdb, to debug the source code, you must include this option when compiling the program.       (3)-O: Optimize the program to compile, link, the resulting executable file execution efficiency is high, but in the compilation, link speed is correspondingly slower.       (4)-o2: Better than-O to optimize compilation, linking.       (5)-wall: Output all warning messages       (6)-W: Turn off all warnings, we recommend not using       (7)- Idirname: Add a directory named DirName to the program header file directory list       (8)-ldirname: Adds a directory named DirName to the library file search directory list of the program, which is the parameter used in the link process.       (9)-lname: Instructs the compiler to mount a function library named Libname.a at link time, which is located in a predefined directory of the system or a directory specified by the-l option. One. GCC error types and Countermeasures       (1) C syntax errors       (2) header file or library file errors       (3) undefined symbol 12. strcpy is insecure and has a security vulnerability, so you should generally use STRNCPY,STRCAT and strncat as well. Strstr is looking for the first occurrence of S2 from the string s1, returns a pointer to the first occurrence of the S2 position, and returns null if not found. STRCHR finds the position of the first occurrence of the character C in the string s, returns the first occurrence of the character C pointer, and returns NULL if there is no C in S.

Linux C Programming (1) VIM and GCC commands

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.