VIM This is the text editor you will use on the workstation. You can also edit the text files...

10

Transcript of VIM This is the text editor you will use on the workstation. You can also edit the text files...

Page 1: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.
Page 2: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.

VIM This is the text editor you will use on

the workstation.

You can also edit the text files under windows environment and upload it to the workstation using FTP.

It will be a very efficient tool is you are familiar with it.

Page 3: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.

VIM

Basic usage :vim <filename>

It will create a new file for you if no such file exists.

You can just type vim a.c to start editing a c source file.

Page 4: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.

VIM The first thing you have to know about Vim is h

ow 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.

Page 5: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.

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.

Page 6: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.

VIM Basic operations in Normal mode :

0 / $ – go to the beginning/end of the line. G / gg – go to the beginning/end of the file. x / dd – delete a world / a line. yy /p – copy / paste u / <ctrl>+r – undo / redo / / n – search / search next <ctrl>+v – block choose

Page 7: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.

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

Page 8: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.

Shell Script Shell script is just like a .bat file in windows, ca

n be used to execute batch works.

Furthermore, you can use if-then, for-loop etc., in your shell script so you can set up some automatic works.

Use sh <filename> to execute it. Or You can just use chmod command to make the file executable.

Page 9: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.

Shell Script All shell script starts with#!/bin bash to specify the shell name.

Other #s beside this line are considered as comment lines.

Spaces and new lines are ignored.

<Enter> is considered as “execute”

Page 10: VIM  This is the text editor you will use on the workstation.  You can also edit the text files under windows environment and upload it to the workstation.

Shell Script I won’t talk too much about Shell Script here because it will becom

e Unix course.

Let’s try a small example.#!/bin/bash

#This is the demo bash script

echo "We are going to use Vim to open a file."read -p "Please insert the file name: " filename

echo "the file name is" $filename", are you sure?(y/n)"read yn

if [ $yn == "y" ]; thenvim temp/$filenameelseecho "command failed"fi