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