Trình soạn thảo văn bản.
Trên windows có rất nhiều trình soạn thảo khác nhau như office, wordpad, notepad... Trên *nix cũng vậy, nhưng trình soạn thảo ưa thích có lẽ là vi.
Trình soạn thảo này có lẽ là phổ biến nhất và thông dụng nhất trên các hệ thống Unix cũng tương tự như notepad của windows.
Để truy nhập vi trong của sổ terminal bạn đánh : vi
[root@duchai /]# vi
Trình soạn thảo sẽ hiện ra. Như bản Fedora tôi đang dùng thì nó đã thay thế vi bởi VIM :
VIM soạn thảo "thuận tay hơn" vi
bạn dùng thử mà xem 
Để tạo 1 file mới bạn đánh : vi <tên file>
[root@duchai /]# vi hello
Bạn nhấn phím "i" để kích hoạt chế độ Insert, sau đó bạn đánh "Hello world!"
Để ghi lại file bạn bấm phím "ESC" để thoát khỏi chế độ Insert. Sau đó đánh ":qw" để lưu lại và thoát ra khỏi vi.
"hello" [New] 1L, 14C written
[root@duchai /]# more hello
hello world !
[root@duchai /]#
Chi tiết các lệnh của vi có lẽ phải thực hành nhiều một chút mới nhớ được.
Tham khảo :
http://www.ss64.com/bash/vi.html
http://www.eng.hawaii.edu/Tutor/vi.html
VI Editor Commands
Switch to Text or Insert mode:
| |
|
Open line above cursor |
O |
|
|
|
|
Insert text at beginning of line |
I |
Insert text at cursor |
i |
Insert text after cursor |
a |
Append text at line end |
A |
| |
|
Open line below cursor |
o |
|
|
|
|
Switch to Command mode:
Switch to command mode |
<ESC> |
Cursor Movement (command mode):
| |
|
Scroll Backward 1 screen |
<ctrl>b |
|
|
| |
|
Scroll Up 1/2 screen |
<ctrl>u |
|
|
Go to beginning of line |
0 |
Go to line n |
nG |
Go to end of line |
$ |
| |
|
Scroll Down 1/2 screen |
<ctrl>d |
Go to line number ## |
:## |
| |
|
Scroll Forward 1 screen |
<ctrl>f |
|
|
| |
|
Go to last line |
G |
|
|
| Scroll by sentence f/b |
( ) |
|
|
|
|
| Scroll by word f/b |
w b |
Move left, down, up, right |
h j k l |
Left 6 chars |
6h |
| |
|
Directional Movement |
Arrow Keys |
Go to line #6 |
6G |
Deleting text (command mode):
Change word |
cw |
Replace one character |
r |
|
|
Delete word |
dw |
Delete text at cursor |
x |
Delete entire line (to buffer) |
dd |
| |
|
Delete current to end of line |
D |
Delete 5 lines (to buffer) |
5dd |
| |
|
|
|
Delete lines 5-10 |
:5,10d |
Editing (command mode):
Copy line |
yy |
Copy n lines |
nyy |
Copy lines 1-2/paste after 3 |
:1,2t 3 |
Paste above current line |
P |
|
|
|
|
Paste below current line |
p |
|
|
Move lines 4-5/paste after 6 |
:4,5m 6 |
| |
|
|
|
Join previous line |
J |
Search backward for string |
?string |
Search forward for string |
/string |
Find next string occurrence |
n |
% (entire file) s (search and replace) /old text with new/ c (confirm) g (global - all) |
:%s/oldstring/newstring/cg |
|
|
Ignore case during search |
:set ic |
Repeat last command |
. |
Undo previous command |
u |
Undo all changes to line |
U |
Save and Quit (command mode):
Save changes to buffer |
:w |
Save changes and quit vi |
:wq |
Save file to new file |
:w file |
| |
|
Quit without saving |
:q! |
Save lines to new file |
:10,15w file |