In linux, vim automatically inserts a file header in the c file.

Source: Internet
Author: User

In linux, vim automatically inserts a file header in the c file.

"New. c ,. h ,. sh ,. java file, automatically Insert the file header autocmd BufNewFile *. cpp ,*. [ch], *. sh ,*. java exec ": call SetTitle ()" defines the function SetTitle, which automatically inserts the file header func SetTitle () "If the file type is. sh file if & filetype = 'sh' call setline (1, "\###################################### ###################################") call append (line (". ")," \ # File Name :". expand ("%") call append (line (". ") + 1," \ # Author: pengzhen ") call append (line (". ") + 2," # mail: Pz9042@163.com ") call append (line (". ") + 3," # Created Time :". strftime ("% c") call append (line (". ") + 4, "\###################################### ###################################") call append (line (". ") + 5 ,"\#! /Bin/bash ") call append (line (". ") + 6," ") else call setline (1, "/************************************** ***********************************") call append (line (". "),"> File Name :". expand ("%") call append (line (". ") + 1,"> Author: pengzhen ") call append (line (".) + 2, "> Mail: pz9042@163.com") call append (line (". ") + 3,"> Created Time :". strftime ("% c") call append (line (". ") + 4, "*************************************** *********************************/") call append (line (". ") + 5," ") endifif & filetype = 'cpp 'call append (line (". ") + 6," # include <iostream> ") call append (line (". ") + 7," using namespace std; ") call append (line (". ") + 8," ") endifif & filetype = 'C' call append (line (". ") + 6," # include <stdio. h> ") call append (line (". ") + 7," ") endif" after creating a file, the autocmd BufNewFile * normal Gendfunc is automatically located at the end of the file.

  


How to Use vim to compile a C program in linux?

Enter
Vim test. c

Press enter to enter the vim Editor, press a to enter the editing status, and then enter the following C language statement:

# Include <stdio. h>
Int main (){
Printf ("hello world! \ N ");
}

At this point, Press esc to exit the editing state, and then enter a colon (shift + colon that key), followed by the input wq, that is, the input

: Wq

Press enter to release the vim editor and return to the terminal command window (similar to xp command prompt ),

Enter

Gcc test. c. This step is to compile

./A. out. This is the execution and will output hello world!

Now, the premise is that you have installed gcc

In linux, how does the vim editor copy data from an entire file to another file?

There is a way that should be feasible. Try it (back up data !)

For example, copy a.txt to B .txt.

Use vimto open B .txt. Position the cursor to the position where you want to copy and insert the cursor, and enter
: R! Cat a.txt
The next step is to save it.
: Wq

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.