1 / 17

CO004 Projects on Operating Systems

CO004 Projects on Operating Systems. UNIX - Basics 0 3. Outline. Text Editors Compile and run a simple c program. Text Editors. pico/nano - Simple, easy-to-use text editor Vi/vim - Text editor based on an underlying line editor ex emacs - Powerful and extensible

aran
Télécharger la présentation

CO004 Projects on Operating Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CO004 Projects on Operating Systems UNIX - Basics 03

  2. Outline • Text Editors • Compile and run a simple c program

  3. Text Editors • pico/nano - Simple, easy-to-use text editor • Vi/vim - Text editor based on an underlying line editor ex • emacs - Powerful and extensible - Hard to learn

  4. nano

  5. Basic Usage of vi and vim • vim <filename> • It will create a new file for you if no such file exists. • You can just type vim hello.c to start editing a c source file.

  6. Vim • The first thing you have to know about Vim is how to exit it. • <press ESC if you are in the editing mode> • :q –leave vim • :q! –leave without saving • :wq –save and leave • You can use :w to save without leave • and:w <filename> to save in a new name.

  7. VIM • Now you can understand that Vim is a monster filled with hotkeys and commands. • Don’t be frightened by that, you only needs “i”, “:q!”, “:wq”and “ESC”in order to use Vim. • You can press any of the following keys to enter the editing mode: a, i, o, r, A, I, O, R, each has a different function.

  8. VIM • Basic operations in Normal mode: • 0 / $–go to the beginning/end of the line. • gg / G –go to the beginning/end of the file. • x / dd–delete a world / a line. • yy /p–copy / paste a line • u / <ctrl>+r–undo / redo  • / / n–search / search next • <ctrl>+v–block choose

  9. VIM • You can also use number + command to execute multiple commands. • For example, 2dd deletes 2 lines, 2yy copies 2 lines. • Learn Vim by experience, do not try to recite all of the commands. • You can also download a windows version of Vim

  10. Vim: Basic Editing Saving your work assume that you are in command mode :w save :q quit :wq save and quit Insert mode is actually very similar to a regular editor. You can use cursor/navigation keys, backspace, delete … Page 10

  11. Operators and Repetition Examples: d3w: delete THREE words d2t,: delete up to but not including the second comma dd: delete a line d100d: delete 100 lines 11

  12. Yank & Paste Examples: yy: yank (copy) a line into the buffer y7y: yank SEVEN lines 12

  13. Vim Drill Using Vim Type: “vim hello.c”; Type: “i”, and you’ll see “-- INSERT --” appeared; Type: Type: “Esc” key, and you’ll see “-- INSERT --” disappeared; type “:wq”, and you’ll save the file and quit vim. #include <stdio.h> int main(void) { printf("hello world\n"); return 0; } 13

  14. How to compile c programs in UNIX? • Use gcc! • gcc by default hides all the intermediate steps. • “gcc hello.c” generates the executable “a.out” by default. • “gcc -o hello hello.c” generates the executable “hello” directly.

  15. Examples hello.c GCC – GNU C Compiler Output Flag: -o [output file name] gcc -o hello hello.c #include <stdio.h> int main(void) { printf("hello world\n"); return 0; } 1 2 3 4 5 6 The command: ./hello “hello” is the exe file generated by GCC. So, the command means: run the program “hello” in the current directory, where . means the current directory. $ gcc -o hello hello.c [ no error; no warning ] $ ls hello* hello hello.c $ ./hello hello world $

  16. How to run your executable program? • ./ your_program • “.” means the current working directory • “./” means executing your program in the current working directory • ./a.out • ./hello • Note: an executable code is not identified by .exe but by its property.

  17. More about Vim • http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html • http://www.tuxfiles.org/linuxhelp/vimcheat.html • http://www.fprintf.net/vimCheatSheet.html • http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html

More Related