vi July 10, 2009
Posted by pisethkem in Computer.add a comment
vi short introduction
Introduction:
The vi editor is a screen-based editor used by many Unix users. The vi editor has powerful features to aid programmers, but many beginning users avoid using “vi” because the different features overwhelm them. You will learn by experiencing things yourself.
Starting VI:
vi let you create new files or edit exiting files.
To create a new file, at the terminal type : vi
[you will have to tell we what filename to save later]
To edit an existing file type : vi <filename>
you will see a screen filled with tildes “~”.
Quitting VI:
The vi editor has two modes. In order to get out of vi you have to be in command mode. Normally when you start vi, you are in command mode. When you are not in command mode, press Esc (escape) key to get to command mode. [if you are all ready in command mode, when you hit escape, "don't worry" you are still in command mode. The command to quit out of VI is :q. Once in command mode press colon, and 'q', followed by return. If your file has been modified in anyway, the editor will warn you of this and not let you quit. To ignore this message, the command to quit out of vi without saving is :q!. This let you exit VI without saving any of the changes.
Of course, normally in an editor, you would want to save the changes
you have made. The command to save the contents of the editor is :w. You
can combine the above command with the quit command, or :wq. You can specify a different file name to save to by specifying the name after the :w. For
example, if you wanted to save the file you were working as another filename
called filename2, you would type :w filename2 and return.
The 2 modes of VI:
2 modes: command & insert.
The "command" mode allows the entry of commands to manipulate text.
The "insert" mode puts anything typed on the keyboard into the current file.
There are several commands that put VI editor into insert mode. The most
commonly used commands to get into insert mode are a and i.
Some Simple VI commands:
a enter insert mode, the characters typed in will be inserted after the current cursor position.
i enter insert mode, the characters typed in will be inserted before the current cursor position.
h move the cursor to the left one character position
j move the cursor down one line
k move the cursor up one line
l move the cursor to the right one character position
r replace one character under the cursor.
u undo last change to the file
x delete character under the cursor
Command Format:
(optional arguments are given in the brackets)
[count] command [where]
e.g. if you type 12x while in command mode, it will delete 12 characters.
Cutting and Yanking:
The command commonly used command for cutting is d. This command
deletes text from the file. The command is preceded by an optional count
and followed by a movement specification. If you double the command by
typing dd, it deletes the current line. Here are some combinations of these:
d^ deletes from current cursor position to the beginning of the line.
d$ deletes from current cursor position to the end of the line.
dw deletes from current cursor position to the end of the word.
3dd deletes three lines from current cursor position downwards.
There is also the y command which operates similarly to the d command
which take text from the file without deleting the text.
Pasting:
The commands to paste are p and P. The only differ in the position relative to the cursor where they paste. p pastes the specified or general buffer after the cursor position, while P pastes the specified or general buffer before the cursor position. Specifying count before the paste command pastes text the specified number of times.
…
Pointers and Cursors March 10, 2009
Posted by pisethkem in Main.add a comment
- From “Data Structures and Algorithms”
Pointers and Cursors
A pointer is a cell whose value indicates another cell.
A cursor is an integer-valued cell, used as a pointer to an array. As a method of connection, the cursor is essentially the same as a pointer, but a cursor can be used in languages like Fortran that do not have explicit pointer types.
File association February 22, 2009
Posted by pisethkem in Computer.add a comment
Windows XP:
Two commands using “Take Command”.
- assoc
Modify or display relationships between file extensions and file types stored in the Windows registry. - ftype
Modify or display the command used to open a file of a type specified in the Windows registry.
Updating files : Windows XP February 22, 2009
Posted by pisethkem in Computer.add a comment
There are 2 folders to consider when trying to update any Windows XP protected files:
- C:\WINDOWS\system32\dllcache
- C:\WINDOWS\ServicePackFiles\i386
Scheme Codes December 24, 2008
Posted by pisethkem in Scheme.add a comment
;fib: fibonacci number
(define (fib n)
(if (< n 0)
(display “Please input a non negative number.\n”)
(if (= n 0)
0
(if (= n 1)
1
(+ (fib (- n 1)) (fib (- n 2)))))))
;tail-recursion of fibonacci number function
(define (fib-iter n previous current)
(if (< n 0)
(display “Please input a non negative number.\n”)
(if (= n 0)
current
(fib-iter (- n 1) current (+ previous current)))))
(define (fib n) (fib-iter n 1 0))
;fact: factorial
(define (fact n)
(define (fact-iter n acc)
(if (< n 2)
acc
(fact-iter (- n 1) (* n acc))))
(fact-iter n 1))
;third : pick up third item fro m a list
(define (third y) (car (cdr (cdr y))))
;or (define (third y) (caddr y))
;mreverse : reverse a given list
(define (mreverse l)
(define (mreverse-iter l i)
(if (= i (+ (length l) 1))
()
(cons (list-ref l (- (length l) i)) (mreverse-iter l (+ i 1)))))
(mreverse-iter l 1))
;nreverse : using set-cdr! to reverse a list
(define (reverse-append! x y)
(define (loop a b c)
(set-cdr! a c)
(if (pair? b)
(loop b (cdr b) a)
a))
(if (pair? x)
(loop x (cdr x) y)
y))
(define (nreverse x) (reverse-append! x ‘()))
;new environment
(define (make-env) ‘(()))
;add variable to environment
(define (define-value! var val env)
(if (not (null? env))
(set-car! env (cons (cons var val) (car env)))))
;creat a new environment as an extension of a environment given
(define (extend-env env alist)
(define (define-value-rec! alist env)
(if (null? alist)
env
(let ((pair (car alist)))
(define-value! (car pair) (cdr pair) env)
(define-value-rec! (cdr alist) env))))
(define-value-rec! alist (cons ‘() env)))
;find value of a variable in a list of pairs (same as assoc)
;return #f if not found
(define (find-value var alist)
(if (null? alist)
#f
(let ((pair (car alist))
(x (caar alist)))
(if (equal? var x)
pair
(find-value var (cdr alist))))))
;get value of a varibale inside an environment (extended or not)
;return #f if not found
(define (get-value var env)
(if (null? env)
#f
(let ((pair (find-value var (car env)))) ;or use ‘assoc’ instead of ‘find-value’
(if pair
pair
(get-value var (cdr env))))))
;add all elements in a list
(define (add alist)
(if (null? alist)
0
(+ (car alist) (add (cdr alist)))))
;subtract from the first element
(define (subtract alist)
(if (null? alist)
(display “Expect at least one argument\n”)
(let ((rest (cdr alist)))
(if (null? rest)
(- 0 (car alist))
(- (car alist) (add rest)))))) ;use the above add function
;multiply all elements in a list
(define (multiply alist)
(if (null? alist)
1
(* (car alist) (multiply (cdr alist)))))
;divide the 1st element by the rest of the elements in a list
(define (divide alist)
(if (null? alist)
(display “Expect at least one argument\n”)
(let ((rest (cdr alist)))
(if (null? rest)
(/ 1 (car alist))
(/ (car alist) (multiply rest)))))) ;use the above multiply function
;return the last element in a list
(define (last l)
(if (null? (cdr l))
(car l)
(last (cdr l))))
;return #t if all elements in a list are equal
(define (isequal alist)
(if (< (length alist) 2)
(display “Expect at least 2 arguments\n”)
(if (= (length alist) 2)
(= (car alist) (cadr alist))
(and (= (car alist) (cadr alist)) (isequal (cdr alist))))))
;return #t if y is found inside a nestable list x : xs
(define (find? y x : xs)
(define (f y x : xs result)
(cond
((or result (null? x : xs)) result)
((pair? (car x : xs)) (f y (cdr x : xs) (f y (car x : xs) result)))
(else (f y (cdr x : xs) (equal? (car x : xs) y)))))
(f y x : xs #f))