Quản trị hệ thống, Giải pháp Công nghệ, Tư vấn giải pháp

Lệnh cơ bản trên Linux – Phần 3

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.

Lệnh cơ bản trên Linux - Phần 3

Để 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 happy bạn dùng thử mà xem big grin

Để tạo 1 file mới bạn đánh : vi

[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 thêm tại 2 trang web nước ngoài này nhé:

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

Cursor Movement (command mode):

Scroll Backward 1 screen
b

Scroll Up 1/2 screen
u
Go to beginning of line
0
Go to line n
nG
Go to end of line
$

Scroll Down 1/2 screen
d
Go to line number ##
:##

Scroll Forward 1 screen
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

 

ITtoday

VP Miền Bắc: Số 47 – Ngõ 207 Xuân Đỉnh – Q.Bắc Từ Liêm – TP.Hà Nội – ĐT: 097 383 6600
VP Miền Nam: 53/21 Đường 18, Khu phố 5, Phường Ninh Chung,  Quận Thủ Đức, TP Hồ Chí Minh. – ĐT: 0976.413.635
Email: itotdayvn@gmail.com
Website: www.ittoday.vn

Yahoo: kettv88@yahoo.com

Skype: ket.tv

Rate this post